## Automatically generated incremental diff
## From:   linux-2.4.13-pre1
## To:     linux-2.4.13-pre2
## Robot:  $Id: make-incremental-diff,v 1.8 2001/12/04 06:05:04 hpa Exp $

diff -urN linux-2.4.13-pre1/Documentation/DMA-mapping.txt linux/Documentation/DMA-mapping.txt
--- linux-2.4.13-pre1/Documentation/DMA-mapping.txt	Wed Aug 15 01:54:44 2001
+++ linux/Documentation/DMA-mapping.txt	Mon Dec  3 23:17:32 2001
@@ -6,14 +6,15 @@
 		  Jakub Jelinek <jakub@redhat.com>
 
 Most of the 64bit platforms have special hardware that translates bus
-addresses (DMA addresses) to physical addresses similarly to how page
-tables and/or TLB translate virtual addresses to physical addresses.
-This is needed so that e.g. PCI devices can access with a Single Address
-Cycle (32bit DMA address) any page in the 64bit physical address space.
-Previously in Linux those 64bit platforms had to set artificial limits on
-the maximum RAM size in the system, so that the virt_to_bus() static scheme
-works (the DMA address translation tables were simply filled on bootup
-to map each bus address to the physical page __pa(bus_to_virt())).
+addresses (DMA addresses) into physical addresses.  This is similar to
+how page tables and/or a TLB translates virtual addresses to physical
+addresses on a cpu.  This is needed so that e.g. PCI devices can
+access with a Single Address Cycle (32bit DMA address) any page in the
+64bit physical address space.  Previously in Linux those 64bit
+platforms had to set artificial limits on the maximum RAM size in the
+system, so that the virt_to_bus() static scheme works (the DMA address
+translation tables were simply filled on bootup to map each bus
+address to the physical page __pa(bus_to_virt())).
 
 So that Linux can use the dynamic DMA mapping, it needs some help from the
 drivers, namely it has to take into account that DMA addresses should be
@@ -28,9 +29,10 @@
 
 #include <linux/pci.h>
 
-is in your driver. This file will obtain for you the definition of
-the dma_addr_t type which should be used everywhere you hold a DMA
-(bus) address returned from the DMA mapping functions.
+is in your driver. This file will obtain for you the definition of the
+dma_addr_t (which can hold any valid DMA address for the platform)
+type which should be used everywhere you hold a DMA (bus) address
+returned from the DMA mapping functions.
 
 			 What memory is DMA'able?
 
@@ -49,7 +51,8 @@
 _underlying_ memory mapped into a vmalloc() area, but this requires
 walking page tables to get the physical addresses, and then
 translating each of those pages back to a kernel address using
-something like __va().
+something like __va().  [ EDIT: Update this when we integrate
+Gerd Knorr's generic code which does this. ]
 
 This rule also means that you may not use kernel image addresses
 (ie. items in the kernel's data/text/bss segment, or your driver's)
@@ -65,60 +68,96 @@
 
 Does your device have any DMA addressing limitations?  For example, is
 your device only capable of driving the low order 24-bits of address
-on the PCI bus for DMA transfers?  If your device can handle any PCI
-dma address fully, then please skip to the next section, the rest of
-this section does not concern your device.
+on the PCI bus for SAC DMA transfers?  If so, you need to inform the
+PCI layer of this fact.
+
+By default, the kernel assumes that your device can address the full
+32-bits in a SAC cycle.  For a 64-bit DAC capable device, this needs
+to be increased.  And for a device with limitations, as discussed in
+the previous paragraph, it needs to be decreased.
 
 For correct operation, you must interrogate the PCI layer in your
 device probe routine to see if the PCI controller on the machine can
-properly support the DMA addressing limitation your device has.  This
-query is performed via a call to pci_dma_supported():
+properly support the DMA addressing limitation your device has.  It is
+good style to do this even if your device holds the default setting,
+because this shows that you did think about these issues wrt. your
+device.
+
+The query is performed via a call to pci_set_dma_mask():
 
-	int pci_dma_supported(struct pci_dev *pdev, dma_addr_t device_mask)
+	int pci_set_dma_mask(struct pci_dev *pdev, u64 device_mask);
 
 Here, pdev is a pointer to the PCI device struct of your device, and
 device_mask is a bit mask describing which bits of a PCI address your
-device supports.  It returns non-zero if your card can perform DMA
-properly on the machine.  If it returns zero, your device can not
-perform DMA properly on this platform, and attempting to do so will
-result in undefined behavior.
+device supports.  It returns zero if your card can perform DMA
+properly on the machine given the address mask you provided.
 
-In the failure case, you have two options:
-
-1) Use some non-DMA mode for data transfer, if possible.
-2) Ignore this device and do not initialize it.
+If it returns non-zero, your device can not perform DMA properly on
+this platform, and attempting to do so will result in undefined
+behavior.  You must either use a different mask, or not use DMA.
+
+This means that in the failure case, you have three options:
+
+1) Use another DMA mask, if possible (see below).
+2) Use some non-DMA mode for data transfer, if possible.
+3) Ignore this device and do not initialize it.
 
 It is recommended that your driver print a kernel KERN_WARNING message
-when you do one of these two things.  In this manner, if a user of
-your driver reports that performance is bad or that the device is not
-even detected, you can ask him for the kernel messages to find out
+when you end up performing either #2 or #2.  In this manner, if a user
+of your driver reports that performance is bad or that the device is not
+even detected, you can ask them for the kernel messages to find out
 exactly why.
 
-So if, for example, you device can only drive the low 24-bits of
-address during PCI bus mastering you might do something like:
+The standard 32-bit addressing PCI device would do something like
+this:
 
-	if (! pci_dma_supported(pdev, 0x00ffffff))
+	if (pci_set_dma_mask(pdev, 0xffffffff)) {
+		printk(KERN_WARNING
+		       "mydev: No suitable DMA available.\n");
 		goto ignore_this_device;
+	}
 
-When DMA is possible for a given mask, the PCI layer must be informed of the
-mask for later allocation operations on the device.  This is achieved by
-setting the dma_mask member of the pci_dev structure, like so:
-
-#define MY_HW_DMA_MASK 0x00ffffff
-
-	if (! pci_dma_supported(pdev, MY_HW_DMA_MASK))
+Another common scenario is a 64-bit capable device.  The approach
+here is to try for 64-bit DAC addressing, but back down to a
+32-bit mask should that fail.  The PCI platform code may fail the
+64-bit mask not because the platform is not capable of 64-bit
+addressing.  Rather, it may fail in this case simply because
+32-bit SAC addressing is done more efficiently than DAC addressing.
+Sparc64 is one platform which behaves in this way.
+
+Here is how you would handle a 64-bit capable device which can drive
+all 64-bits during a DAC cycle:
+
+	int using_dac;
+
+	if (!pci_set_dma_mask(pdev, 0xffffffffffffffff)) {
+		using_dac = 1;
+	} else if (!pci_set_dma_mask(pdev, 0xffffffff)) {
+		using_dac = 0;
+	} else {
+		printk(KERN_WARNING
+		       "mydev: No suitable DMA available.\n");
 		goto ignore_this_device;
+	}
 
-	pdev->dma_mask = MY_HW_DMA_MASK;
+If your 64-bit device is going to be an enormous consumer of DMA
+mappings, this can be problematic since the DMA mappings are a
+finite resource on many platforms.  Please see the "DAC Addressing
+for Address Space Hungry Devices" setion near the end of this
+document for how to handle this case.
 
-A helper function is provided which performs this common code sequence:
+Finally, if your device can only drive the low 24-bits of
+address during PCI bus mastering you might do something like:
 
-	int pci_set_dma_mask(struct pci_dev *pdev, dma_addr_t device_mask)
+	if (pci_set_dma_mask(pdev, 0x00ffffff)) {
+		printk(KERN_WARNING
+		       "mydev: 24-bit DMA addressing not available.\n");
+		goto ignore_this_device;
+	}
 
-Unlike pci_dma_supported(), this returns -EIO when the PCI layer will not be
-able to DMA with addresses restricted by that mask, and returns 0 when DMA
-transfers are possible.  If the call succeeds, the dma_mask will have been
-updated so that your driver need not worry about it.
+When pci_set_dma_mask() is successful, and returns zero, the PCI layer
+saves away this mask you have provided.  The PCI layer will use this
+information later when you make DMA mappings.
 
 There is a case which we are aware of at this time, which is worth
 mentioning in this documentation.  If your device supports multiple
@@ -169,6 +208,10 @@
 
   Think of "consistent" as "synchronous" or "coherent".
 
+  Consistent DMA mappings are always SAC addressable.  That is
+  to say, consistent DMA addresses given to the driver will always
+  be in the low 32-bits of the PCI bus space.
+
   Good examples of what to use consistent mappings for are:
 
 	- Network card DMA ring descriptors.
@@ -230,15 +273,26 @@
 specific (and often is private to the bus which the device is attached
 to).
 
-Size is the length of the region you want to allocate.
+Size is the length of the region you want to allocate, in bytes.
 
 This routine will allocate RAM for that region, so it acts similarly to
 __get_free_pages (but takes size instead of a page order).  If your
 driver needs regions sized smaller than a page, you may prefer using
 the pci_pool interface, described below.
 
-It returns two values: the virtual address which you can use to access
-it from the CPU and dma_handle which you pass to the card.
+The consistent DMA mapping interfaces, for non-NULL dev, will always
+return a DMA address which is SAC (Single Address Cycle) addressible.
+Even if the device indicates (via PCI dma mask) that it may address
+the upper 32-bits and thus perform DAC cycles, consistent allocation
+will still only return 32-bit PCI addresses for DMA.  This is true
+of the pci_pool interface as well.
+
+In fact, as mentioned above, all consistent memory provided by the
+kernel DMA APIs are always SAC addressable.
+
+pci_alloc_consistent returns two values: the virtual address which you
+can use to access it from the CPU and dma_handle which you pass to the
+card.
 
 The cpu return address and the DMA bus master address are both
 guaranteed to be aligned to the smallest PAGE_SIZE order which
@@ -270,14 +324,15 @@
 
 The "name" is for diagnostics (like a kmem_cache name); dev and size
 are as above.  The device's hardware alignment requirement for this
-type of data is "align" (a power of two).  The flags are SLAB_ flags
-as you'd pass to kmem_cache_create.  Not all flags are understood, but
-SLAB_POISON may help you find driver bugs.  If you call this in a non-
-sleeping context (f.e. in_interrupt is true or while holding SMP
-locks), pass SLAB_ATOMIC.  If your device has no boundary crossing
-restrictions, pass 0 for alloc; passing 4096 says memory allocated
-from this pool must not cross 4KByte boundaries (but at that time it
-may be better to go for pci_alloc_consistent directly instead).
+type of data is "align" (which is expressed in bytes, and must be a
+power of two).  The flags are SLAB_ flags as you'd pass to
+kmem_cache_create.  Not all flags are understood, but SLAB_POISON may
+help you find driver bugs.  If you call this in a non- sleeping
+context (f.e. in_interrupt is true or while holding SMP locks), pass
+SLAB_ATOMIC.  If your device has no boundary crossing restrictions,
+pass 0 for alloc; passing 4096 says memory allocated from this pool
+must not cross 4KByte boundaries (but at that time it may be better to
+go for pci_alloc_consistent directly instead).
 
 Allocate memory from a pci pool like this:
 
@@ -318,6 +373,8 @@
 
 PCI_DMA_TODEVICE means "from main memory to the PCI device"
 PCI_DMA_FROMDEVICE means "from the PCI device to main memory"
+It is the direction in which the data moves during the DMA
+transfer.
 
 You are _strongly_ encouraged to specify this as precisely
 as you possibly can.
@@ -333,13 +390,13 @@
 precise direction, and this will help catch cases where your
 direction tracking logic has failed to set things up properly.
 
-Another advantage of specifying this value precisely (outside
-of potential platform-specific optimizations of such) is for
-debugging.  Some platforms actually have a write permission
-boolean which DMA mappings can be marked with, much like page
-protections in a user program can have.  Such platforms can
-and do report errors in the kernel logs when the PCI controller
-hardware detects violation of the permission setting.
+Another advantage of specifying this value precisely (outside of
+potential platform-specific optimizations of such) is for debugging.
+Some platforms actually have a write permission boolean which DMA
+mappings can be marked with, much like page protections in the user
+program address space.  Such platforms can and do report errors in the
+kernel logs when the PCI controller hardware detects violation of the
+permission setting.
 
 Only streaming mappings specify a direction, consistent mappings
 implicitly have a direction attribute setting of
@@ -362,13 +419,17 @@
 
 		  Using Streaming DMA mappings
 
-The streaming DMA mapping routines can be called from interrupt context.
-There are two versions of each map/unmap, one which map/unmap a single
-memory region, one which map/unmap a scatterlist.
+The streaming DMA mapping routines can be called from interrupt
+context.  There are two versions of each map/unmap, one which will
+map/unmap a single memory region, and one which will map/unmap a
+scatterlist.
 
 To map a single region, you do:
 
+	struct pci_dev *pdev = mydev->pdev;
 	dma_addr_t dma_handle;
+	void *addr = buffer->ptr;
+	size_t size = buffer->len;
 
 	dma_handle = pci_map_single(dev, addr, size, direction);
 
@@ -377,9 +438,29 @@
 	pci_unmap_single(dev, dma_handle, size, direction);
 
 You should call pci_unmap_single when the DMA activity is finished, e.g.
-from interrupt which told you the DMA transfer is done.
+from the interrupt which told you that the DMA transfer is done.
 
-Similarly with scatterlists, you map a region gathered from several regions by:
+Using cpu pointers like this for single mappings has a disadvantage,
+you cannot reference HIGHMEM memory in this way.  Thus, there is a
+map/unmap interface pair akin to pci_{map,unmap}_single.  These
+interfaces deal with page/offset pairs instead of cpu pointers.
+Specifically:
+
+	struct pci_dev *pdev = mydev->pdev;
+	dma_addr_t dma_handle;
+	struct page *page = buffer->page;
+	unsigned long offset = buffer->offset;
+	size_t size = buffer->len;
+
+	dma_handle = pci_map_page(dev, page, offset, size, direction);
+
+	...
+
+	pci_unmap_page(dev, dma_handle, size, direction);
+
+Here, "offset" means byte offset within the given page.
+
+With scatterlists, you map a region gathered from several regions by:
 
 	int i, count = pci_map_sg(dev, sglist, nents, direction);
 	struct scatterlist *sg;
@@ -407,7 +488,7 @@
 
 	pci_unmap_sg(dev, sglist, nents, direction);
 
-Again, make sure DMA activity finished.
+Again, make sure DMA activity has already finished.
 
 PLEASE NOTE:  The 'nents' argument to the pci_unmap_sg call must be
               the _same_ one you passed into the pci_map_sg call,
@@ -421,8 +502,8 @@
 all bus addresses.
 
 If you need to use the same streaming DMA region multiple times and touch
-the data in between the DMA transfers, just map it
-with pci_map_{single,sg}, after each DMA transfer call either:
+the data in between the DMA transfers, just map it with
+pci_map_{single,sg}, and after each DMA transfer call either:
 
 	pci_dma_sync_single(dev, dma_handle, size, direction);
 
@@ -430,9 +511,11 @@
 
 	pci_dma_sync_sg(dev, sglist, nents, direction);
 
-and after the last DMA transfer call one of the DMA unmap routines
+as appropriate.
+
+After the last DMA transfer call one of the DMA unmap routines
 pci_unmap_{single,sg}. If you don't touch the data from the first pci_map_*
-call till pci_unmap_*, then you don't have to call the pci_sync_*
+call till pci_unmap_*, then you don't have to call the pci_dma_sync_*
 routines at all.
 
 Here is pseudo code which shows a situation in which you would need
@@ -492,6 +575,119 @@
 supports dynamic DMA mapping in hardware) in your driver structures and/or
 in the card registers.
 
+All PCI drivers should be using these interfaces with no exceptions.
+It is planned to completely remove virt_to_bus() and bus_to_virt() as
+they are entirely deprecated.  Some ports already do not provide these
+as it is impossible to correctly support them.
+
+		64-bit DMA and DAC cycle support
+
+Do you understand all of the text above?  Great, then you already
+know how to use 64-bit DMA addressing under Linux.  Simply make
+the appropriate pci_set_dma_mask() calls based upon your cards
+capabilities, then use the mapping APIs above.
+
+It is that simple.
+
+Well, not for some odd devices.  See the next section for information
+about that.
+
+	DAC Addressing for Address Space Hungry Devices
+
+There exists a class of devices which do not mesh well with the PCI
+DMA mapping API.  By definition these "mappings" are a finite
+resource.  The number of total available mappings per bus is platform
+specific, but there will always be a reasonable amount.
+
+What is "reasonable"?  Reasonable means that networking and block I/O
+devices need not worry about using too many mappings.
+
+As an example of a problematic device, consider compute cluster cards.
+They can potentially need to access gigabytes of memory at once via
+DMA.  Dynamic mappings are unsuitable for this kind of access pattern.
+
+To this end we've provided a small API by which a device driver
+may use DAC cycles to directly address all of physical memory.
+Not all platforms support this, but most do.  It is easy to determine
+whether the platform will work properly at probe time.
+
+First, understand that there may be a SEVERE performance penalty for
+using these interfaces on some platforms.  Therefore, you MUST only
+use these interfaces if it is absolutely required.  %99 of devices can
+use the normal APIs without any problems.
+
+Note that for streaming type mappings you must either use these
+interfaces, or the dynamic mapping interfaces above.  You may not mix
+usage of both for the same device.  Such an act is illegal and is
+guarenteed to put a banana in your tailpipe.
+
+However, consistent mappings may in fact be used in conjunction with
+these interfaces.  Remember that, as defined, consistent mappings are
+always going to be SAC addressable.
+
+The first thing your driver needs to do is query the PCI platform
+layer with your devices DAC addressing capabilities:
+
+	int pci_dac_set_dma_mask(struct pci_dev *pdev, u64 mask);
+
+This routine behaves identically to pci_set_dma_mask.  You may not
+use the following interfaces if this routine fails.
+
+Next, DMA addresses using this API are kept track of using the
+dma64_addr_t type.  It is guarenteed to be big enough to hold any
+DAC address the platform layer will give to you from the following
+routines.  If you have consistent mappings as well, you still
+use plain dma_addr_t to keep track of those.
+
+All mappings obtained here will be direct.  The mappings are not
+translated, and this is the purpose of this dialect of the DMA API.
+
+All routines work with page/offset pairs.  This is the _ONLY_ way to 
+portably refer to any piece of memory.  If you have a cpu pointer
+(which may be validly DMA'd too) you may easily obtain the page
+and offset using something like this:
+
+	struct page *page = virt_to_page(ptr);
+	unsigned long offset = ((unsigned long)ptr & ~PAGE_MASK);
+
+Here are the interfaces:
+
+	dma64_addr_t pci_dac_page_to_dma(struct pci_dev *pdev,
+					 struct page *page,
+					 unsigned long offset,
+					 int direction);
+
+The DAC address for the tuple PAGE/OFFSET are returned.  The direction
+argument is the same as for pci_{map,unmap}_single().  The same rules
+for cpu/device access apply here as for the streaming mapping
+interfaces.  To reiterate:
+
+	The cpu may touch the buffer before pci_dac_page_to_dma.
+	The device may touch the buffer after pci_dac_page_to_dma
+	is made, but the cpu may NOT.
+
+When the DMA transfer is complete, invoke:
+
+	void pci_dac_dma_sync_single(struct pci_dev *pdev,
+				     dma64_addr_t dma_addr,
+				     size_t len, int direction);
+
+This must be done before the CPU looks at the buffer again.
+This interface behaves identically to pci_dma_sync_{single,sg}().
+
+If you need to get back to the PAGE/OFFSET tuple from a dma64_addr_t
+the following interfaces are provided:
+
+	struct page *pci_dac_dma_to_page(struct pci_dev *pdev,
+					 dma64_addr_t dma_addr);
+	unsigned long pci_dac_dma_to_offset(struct pci_dev *pdev,
+					    dma64_addr_t dma_addr);
+
+This is possible with the DAC interfaces purely because they are
+not translated in any way.
+
+			   Closing
+
 This document, and the API itself, would not be in it's current
 form without the feedback and suggestions from numerous individuals.
 We would like to specifically mention, in no particular order, the
@@ -503,3 +699,6 @@
 	Grant Grundler <grundler@cup.hp.com>
 	Jay Estabrook <Jay.Estabrook@compaq.com>
 	Thomas Sailer <sailer@ife.ee.ethz.ch>
+	Andrea Arcangeli <andrea@suse.de>
+	Jens Axboe <axboe@suse.de>
+	David Mosberger-Tang <davidm@hpl.hp.com>
diff -urN linux-2.4.13-pre1/Documentation/filesystems/udf.txt linux/Documentation/filesystems/udf.txt
--- linux-2.4.13-pre1/Documentation/filesystems/udf.txt	Mon Jun 11 19:15:27 2001
+++ linux/Documentation/filesystems/udf.txt	Mon Dec  3 23:17:32 2001
@@ -1,7 +1,7 @@
 *
 * ./Documentation/filesystems/udf.txt
 *
-UDF Filesystem version 0.9.4
+UDF Filesystem version 0.9.5
 
 If you encounter problems with reading UDF discs using this driver,
 please report them to linux_udf@hpesjro.fc.hp.com, which is the
@@ -23,7 +23,7 @@
 	noadinicb	Don't embed data in the inode
 	shortad		Use short ad's
 	longad		Use long ad's (default)
-	strict		Set strict conformance
+	nostrict	Unset strict conformance
 	iocharset=	Set the NLS character set
 
 The remaining are for debugging and disaster recovery:
@@ -42,8 +42,8 @@
 
 	fileset=	Override the fileset block location. (unused)
 	rootdir=	Override the root directory location. (unused)
-				WARNING: overriding the rootdir to a non-directory may
-					yield highly unpredictable results.
+			WARNING: overriding the rootdir to a non-directory may
+				yield highly unpredictable results.
 -------------------------------------------------------------------------------
 
 
diff -urN linux-2.4.13-pre1/Makefile linux/Makefile
--- linux-2.4.13-pre1/Makefile	Mon Dec  3 23:17:24 2001
+++ linux/Makefile	Mon Dec  3 23:17:32 2001
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 4
 SUBLEVEL = 13
-EXTRAVERSION =-pre1
+EXTRAVERSION =-pre2
 
 KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/alpha_ksyms.c linux/arch/alpha/kernel/alpha_ksyms.c
--- linux-2.4.13-pre1/arch/alpha/kernel/alpha_ksyms.c	Thu Sep 13 15:21:32 2001
+++ linux/arch/alpha/kernel/alpha_ksyms.c	Mon Dec  3 23:17:32 2001
@@ -127,10 +127,16 @@
 EXPORT_SYMBOL(pci_alloc_consistent);
 EXPORT_SYMBOL(pci_free_consistent);
 EXPORT_SYMBOL(pci_map_single);
+EXPORT_SYMBOL(pci_map_page);
 EXPORT_SYMBOL(pci_unmap_single);
+EXPORT_SYMBOL(pci_unmap_page);
 EXPORT_SYMBOL(pci_map_sg);
 EXPORT_SYMBOL(pci_unmap_sg);
 EXPORT_SYMBOL(pci_dma_supported);
+EXPORT_SYMBOL(pci_dac_dma_supported);
+EXPORT_SYMBOL(pci_dac_page_to_dma);
+EXPORT_SYMBOL(pci_dac_dma_to_page);
+EXPORT_SYMBOL(pci_dac_dma_to_offset);
 #endif
 
 EXPORT_SYMBOL(dump_thread);
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/core_cia.c linux/arch/alpha/kernel/core_cia.c
--- linux-2.4.13-pre1/arch/alpha/kernel/core_cia.c	Thu Sep 13 15:21:32 2001
+++ linux/arch/alpha/kernel/core_cia.c	Mon Dec  3 23:17:32 2001
@@ -321,7 +321,7 @@
  * be purged to make room for the new entries coming in for the garbage page.
  */
 
-#define CIA_BROKEN_TBIA_BASE	0xE0000000
+#define CIA_BROKEN_TBIA_BASE	0x30000000
 #define CIA_BROKEN_TBIA_SIZE	1024
 
 /* Always called with interrupts disabled */
@@ -382,10 +382,10 @@
 	for (i = 0; i < CIA_BROKEN_TBIA_SIZE / sizeof(unsigned long); ++i)
 		ppte[i] = pte;
 
-	*(vip)CIA_IOC_PCI_W3_BASE = CIA_BROKEN_TBIA_BASE | 3;
-	*(vip)CIA_IOC_PCI_W3_MASK = (CIA_BROKEN_TBIA_SIZE*1024 - 1)
+	*(vip)CIA_IOC_PCI_W1_BASE = CIA_BROKEN_TBIA_BASE | 3;
+	*(vip)CIA_IOC_PCI_W1_MASK = (CIA_BROKEN_TBIA_SIZE*1024 - 1)
 				    & 0xfff00000;
-	*(vip)CIA_IOC_PCI_T3_BASE = virt_to_phys(ppte) >> 2;
+	*(vip)CIA_IOC_PCI_T1_BASE = virt_to_phys(ppte) >> 2;
 }
 
 static void __init
@@ -595,6 +595,8 @@
 failed:
 	printk("pci: disabling sg translation window\n");
 	*(vip)CIA_IOC_PCI_W0_BASE = 0;
+	*(vip)CIA_IOC_PCI_W1_BASE = 0;
+	pci_isa_hose->sg_isa = NULL;
 	alpha_mv.mv_pci_tbi = NULL;
 	goto exit;
 }
@@ -682,13 +684,9 @@
 	 * Set up the PCI to main memory translation windows.
 	 *
 	 * Window 0 is scatter-gather 8MB at 8MB (for isa)
-	 * Window 1 is direct access 1GB at 1GB
-	 * Window 2 is direct access 1GB at 2GB
-	 *
-	 * We must actually use 2 windows to direct-map the 2GB space,
-	 * because of an idiot-syncrasy of the CYPRESS chip used on 
-	 * many PYXIS systems.  It may respond to a PCI bus address in
-	 * the last 1MB of the 4GB address range.
+	 * Window 1 is scatter-gather 1MB at 768MB (for tbia)
+	 * Window 2 is direct access 2GB at 2GB
+	 * Window 3 is DAC access 4GB at 8GB
 	 *
 	 * ??? NetBSD hints that page tables must be aligned to 32K,
 	 * possibly due to a hardware bug.  This is over-aligned
@@ -698,20 +696,35 @@
 
 	hose->sg_pci = NULL;
 	hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 32768);
-	__direct_map_base = 0x40000000;
+	__direct_map_base = 0x80000000;
 	__direct_map_size = 0x80000000;
 
 	*(vip)CIA_IOC_PCI_W0_BASE = hose->sg_isa->dma_base | 3;
 	*(vip)CIA_IOC_PCI_W0_MASK = (hose->sg_isa->size - 1) & 0xfff00000;
 	*(vip)CIA_IOC_PCI_T0_BASE = virt_to_phys(hose->sg_isa->ptes) >> 2;
 
-	*(vip)CIA_IOC_PCI_W1_BASE = 0x40000000 | 1;
-	*(vip)CIA_IOC_PCI_W1_MASK = (0x40000000 - 1) & 0xfff00000;
-	*(vip)CIA_IOC_PCI_T1_BASE = 0 >> 2;
-
-	*(vip)CIA_IOC_PCI_W2_BASE = 0x80000000 | 1;
-	*(vip)CIA_IOC_PCI_W2_MASK = (0x40000000 - 1) & 0xfff00000;
-	*(vip)CIA_IOC_PCI_T2_BASE = 0x40000000 >> 2;
+	*(vip)CIA_IOC_PCI_W2_BASE = __direct_map_base | 1;
+	*(vip)CIA_IOC_PCI_W2_MASK = (__direct_map_size - 1) & 0xfff00000;
+	*(vip)CIA_IOC_PCI_T2_BASE = 0 >> 2;
+
+	/* On PYXIS we have the monster window, selected by bit 40, so
+	   there is no need for window3 to be enabled.
+
+	   On CIA, we don't have true arbitrary addressing -- bits <39:32>
+	   are compared against W_DAC.  We can, however, directly map 4GB,
+	   which is better than before.  However, due to assumptions made
+	   elsewhere, we should not claim that we support DAC unless that
+	   4GB covers all of physical memory.  */
+	if (is_pyxis || max_low_pfn > (0x100000000 >> PAGE_SHIFT)) {
+		*(vip)CIA_IOC_PCI_W3_BASE = 0;
+	} else {
+		*(vip)CIA_IOC_PCI_W3_BASE = 0x00000000 | 1 | 8;
+		*(vip)CIA_IOC_PCI_W3_MASK = 0xfff00000;
+		*(vip)CIA_IOC_PCI_T3_BASE = 0 >> 2;
+
+		alpha_mv.pci_dac_offset = 0x200000000;
+		*(vip)CIA_IOC_PCI_W_DAC = alpha_mv.pci_dac_offset >> 32;
+	}
 
 	/* Prepare workaround for apparently broken tbia. */
 	cia_prepare_tbia_workaround();
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/core_mcpcia.c linux/arch/alpha/kernel/core_mcpcia.c
--- linux-2.4.13-pre1/arch/alpha/kernel/core_mcpcia.c	Fri Mar  2 11:12:07 2001
+++ linux/arch/alpha/kernel/core_mcpcia.c	Mon Dec  3 23:17:32 2001
@@ -406,12 +406,12 @@
 	 * Set up the PCI->physical memory translation windows.
 	 *
 	 * Window 0 is scatter-gather 8MB at 8MB (for isa)
-	 * Window 1 is scatter-gather 128MB at 1GB
+	 * Window 1 is scatter-gather (up to) 1GB at 1GB (for pci)
 	 * Window 2 is direct access 2GB at 2GB
-	 * ??? We ought to scale window 1 with memory.
 	 */
 	hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
-	hose->sg_pci = iommu_arena_new(hose, 0x40000000, 0x08000000, 0);
+	hose->sg_pci = iommu_arena_new(hose, 0x40000000,
+				       size_for_memory(0x40000000), 0);
 
 	__direct_map_base = 0x80000000;
 	__direct_map_size = 0x80000000;
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/core_titan.c linux/arch/alpha/kernel/core_titan.c
--- linux-2.4.13-pre1/arch/alpha/kernel/core_titan.c	Fri Mar  2 11:12:07 2001
+++ linux/arch/alpha/kernel/core_titan.c	Mon Dec  3 23:17:32 2001
@@ -20,6 +20,8 @@
 #include <asm/core_titan.h>
 #undef __EXTERN_INLINE
 
+#include <linux/bootmem.h>
+
 #include "proto.h"
 #include "pci_impl.h"
 
@@ -277,6 +279,7 @@
 titan_init_one_pachip_port(titan_pachip_port *port, int index)
 {
 	struct pci_controller *hose;
+	unsigned long sg_size;
 
 	hose = alloc_pci_controller();
 	if (index == 0)
@@ -342,40 +345,35 @@
 	 * Note: Window 3 on Titan is Scatter-Gather ONLY
 	 *
 	 * Window 0 is scatter-gather 8MB at 8MB (for isa)
-	 * Window 1 is direct access 1GB at 1GB
-	 * Window 2 is direct access 1GB at 2GB
-	 * Window 3 is scatter-gather 128MB at 3GB
-	 * ??? We ought to scale window 3 memory.
-	 *
-	 * We must actually use 2 windows to direct-map the 2GB space,
-	 * because of an idiot-syncrasy of the CYPRESS chip.  It may
-	 * respond to a PCI bus address in the last 1MB of the 4GB
-	 * address range.
+	 * Window 1 is scatter-gather (up to) 1GB at 1GB
+	 * Window 2 is direct access 2GB at 2GB
 	 */
 	hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
 	hose->sg_isa->align_entry = 8; /* 64KB for ISA */
 
-	hose->sg_pci = iommu_arena_new(hose, 0xc0000000, 0x08000000, 0);
+	hose->sg_pci = iommu_arena_new(hose, 0x40000000,
+				       size_for_memory(0x40000000), 0);
 	hose->sg_pci->align_entry = 4; /* Titan caches 4 PTEs at a time */
 
-	__direct_map_base = 0x40000000;
+	__direct_map_base = 0x80000000;
 	__direct_map_size = 0x80000000;
 
 	port->wsba[0].csr = hose->sg_isa->dma_base | 3;
 	port->wsm[0].csr  = (hose->sg_isa->size - 1) & 0xfff00000;
 	port->tba[0].csr  = virt_to_phys(hose->sg_isa->ptes);
 
-	port->wsba[1].csr = 0x40000000 | 1;
-	port->wsm[1].csr  = (0x40000000 - 1) & 0xfff00000;
-	port->tba[1].csr  = 0;
+	port->wsba[1].csr = hose->sg_pci->dma_base | 3;
+	port->wsm[1].csr  = (hose->sg_pci->size - 1) & 0xfff00000;
+	port->tba[1].csr  = virt_to_phys(hose->sg_pci->ptes);
 
 	port->wsba[2].csr = 0x80000000 | 1;
-	port->wsm[2].csr  = (0x40000000 - 1) & 0xfff00000;
-	port->tba[2].csr  = 0x40000000;
+	port->wsm[2].csr  = (0x80000000 - 1) & 0xfff00000;
+	port->tba[2].csr  = 0x80000000;
+
+	port->wsba[3].csr = 0;
 
-	port->wsba[3].csr = hose->sg_pci->dma_base | 3;
-	port->wsm[3].csr  = (hose->sg_pci->size - 1) & 0xfff00000;
-	port->tba[3].csr  = virt_to_phys(hose->sg_pci->ptes);
+	/* Enable the Monster Window to make DAC pci64 possible. */
+	port->pctl.csr |= pctl_m_mwin;
 
 	titan_pci_tbi(hose, 0, -1);
 }
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/core_tsunami.c linux/arch/alpha/kernel/core_tsunami.c
--- linux-2.4.13-pre1/arch/alpha/kernel/core_tsunami.c	Mon Jun 11 19:15:27 2001
+++ linux/arch/alpha/kernel/core_tsunami.c	Mon Dec  3 23:17:32 2001
@@ -279,16 +279,6 @@
 #define FN __FUNCTION__
 
 static void __init
-tsunami_monster_window_enable(tsunami_pchip * pchip)
-{
-	volatile unsigned long * csr = &pchip->pctl.csr;
-
-	*csr |= pctl_m_mwin;
-	mb();
-	*csr;
-}
-
-static void __init
 tsunami_init_one_pchip(tsunami_pchip *pchip, int index)
 {
 	struct pci_controller *hose;
@@ -358,47 +348,34 @@
 	 * Note: Window 3 is scatter-gather only
 	 * 
 	 * Window 0 is scatter-gather 8MB at 8MB (for isa)
-	 * Window 1 is direct access 1GB at 1GB
-	 * Window 2 is direct access 1GB at 2GB
-	 * Window 3 is scatter-gather 128MB at 3GB
-	 * ??? We ought to scale window 3 memory.
-	 *
-	 * We must actually use 2 windows to direct-map the 2GB space,
-	 * because of an idiot-syncrasy of the CYPRESS chip.  It may
-	 * respond to a PCI bus address in the last 1MB of the 4GB
-	 * address range.
+	 * Window 1 is scatter-gather (up to) 1GB at 1GB
+	 * Window 2 is direct access 2GB at 2GB
 	 */
 	hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
-	{
-		unsigned long size = 0x08000000;
-		if (max_low_pfn > (0x80000000 >> PAGE_SHIFT))
-			size = 0x40000000;
-		hose->sg_pci = iommu_arena_new(hose, 0xc0000000, size, 0);
-	}
-	
-	__direct_map_base = 0x40000000;
+	hose->sg_pci = iommu_arena_new(hose, 0x40000000,
+				       size_for_memory(0x40000000), 0);
+
+	__direct_map_base = 0x80000000;
 	__direct_map_size = 0x80000000;
 
 	pchip->wsba[0].csr = hose->sg_isa->dma_base | 3;
 	pchip->wsm[0].csr  = (hose->sg_isa->size - 1) & 0xfff00000;
 	pchip->tba[0].csr  = virt_to_phys(hose->sg_isa->ptes);
 
-	pchip->wsba[1].csr = 0x40000000 | 1;
-	pchip->wsm[1].csr  = (0x40000000 - 1) & 0xfff00000;
-	pchip->tba[1].csr  = 0;
+	pchip->wsba[1].csr = hose->sg_pci->dma_base | 3;
+	pchip->wsm[1].csr  = (hose->sg_pci->size - 1) & 0xfff00000;
+	pchip->tba[1].csr  = virt_to_phys(hose->sg_pci->ptes);
 
 	pchip->wsba[2].csr = 0x80000000 | 1;
-	pchip->wsm[2].csr  = (0x40000000 - 1) & 0xfff00000;
-	pchip->tba[2].csr  = 0x40000000;
+	pchip->wsm[2].csr  = (0x80000000 - 1) & 0xfff00000;
+	pchip->tba[2].csr  = 0x80000000;
 
-	pchip->wsba[3].csr = hose->sg_pci->dma_base | 3;
-	pchip->wsm[3].csr  = (hose->sg_pci->size - 1) & 0xfff00000;
-	pchip->tba[3].csr  = virt_to_phys(hose->sg_pci->ptes);
-
-	tsunami_pci_tbi(hose, 0, -1);
+	pchip->wsba[3].csr = 0;
 
 	/* Enable the Monster Window to make DAC pci64 possible. */
-	tsunami_monster_window_enable(pchip);
+	pchip->pctl.csr |= pctl_m_mwin;
+
+	tsunami_pci_tbi(hose, 0, -1);
 }
 
 void __init
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/pci_impl.h linux/arch/alpha/kernel/pci_impl.h
--- linux-2.4.13-pre1/arch/alpha/kernel/pci_impl.h	Thu Sep 13 15:21:32 2001
+++ linux/arch/alpha/kernel/pci_impl.h	Mon Dec  3 23:17:32 2001
@@ -163,6 +163,8 @@
 extern const char *const pci_mem_names[];
 extern const char pci_hae0_name[];
 
+extern unsigned long size_for_memory(unsigned long max);
+
 extern int iommu_reserve(struct pci_iommu_arena *, long, long);
 extern int iommu_release(struct pci_iommu_arena *, long, long);
 extern int iommu_bind(struct pci_iommu_arena *, long, long, unsigned long *);
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/pci_iommu.c linux/arch/alpha/kernel/pci_iommu.c
--- linux-2.4.13-pre1/arch/alpha/kernel/pci_iommu.c	Thu Sep 13 15:21:32 2001
+++ linux/arch/alpha/kernel/pci_iommu.c	Mon Dec  3 23:17:32 2001
@@ -17,17 +17,18 @@
 
 #define DEBUG_ALLOC 0
 #if DEBUG_ALLOC > 0
-# define DBGA(args...)		printk(KERN_DEBUG ##args)
+# define DBGA(args...)		printk(KERN_DEBUG args)
 #else
 # define DBGA(args...)
 #endif
 #if DEBUG_ALLOC > 1
-# define DBGA2(args...)		printk(KERN_DEBUG ##args)
+# define DBGA2(args...)		printk(KERN_DEBUG args)
 #else
 # define DBGA2(args...)
 #endif
 
 #define DEBUG_NODIRECT 0
+#define DEBUG_FORCEDAC 0
 
 
 static inline unsigned long
@@ -43,6 +44,18 @@
 }
 
 
+/* Return the minimum of MAX or the first power of two larger
+   than main memory.  */
+
+unsigned long
+size_for_memory(unsigned long max)
+{
+	unsigned long mem = max_low_pfn << PAGE_SHIFT;
+	if (mem < max)
+		max = 1UL << ceil_log2(mem);
+	return max;
+}
+
 struct pci_iommu_arena *
 iommu_arena_new(struct pci_controller *hose, dma_addr_t base,
 		unsigned long window_size, unsigned long align)
@@ -163,8 +176,9 @@
    Once the device is given the dma address, the device owns this memory
    until either pci_unmap_single or pci_dma_sync_single is performed.  */
 
-dma_addr_t
-pci_map_single(struct pci_dev *pdev, void *cpu_addr, long size, int direction)
+static dma_addr_t
+pci_map_single_1(struct pci_dev *pdev, void *cpu_addr, size_t size,
+		 int dac_allowed)
 {
 	struct pci_controller *hose = pdev ? pdev->sysdata : pci_isa_hose;
 	dma_addr_t max_dma = pdev ? pdev->dma_mask : 0x00ffffff;
@@ -173,10 +187,7 @@
 	unsigned long paddr;
 	dma_addr_t ret;
 
-	if (direction == PCI_DMA_NONE)
-		BUG();
-
-	paddr = virt_to_phys(cpu_addr);
+	paddr = __pa(cpu_addr);
 
 #if !DEBUG_NODIRECT
 	/* First check to see if we can use the direct map window.  */
@@ -184,13 +195,23 @@
 	    && paddr + size <= __direct_map_size) {
 		ret = paddr + __direct_map_base;
 
-		DBGA2("pci_map_single: [%p,%lx] -> direct %x from %p\n",
+		DBGA2("pci_map_single: [%p,%lx] -> direct %lx from %p\n",
 		      cpu_addr, size, ret, __builtin_return_address(0));
 
 		return ret;
 	}
 #endif
 
+	/* Next, use DAC if selected earlier.  */
+	if (dac_allowed) {
+		ret = paddr + alpha_mv.pci_dac_offset;
+
+		DBGA2("pci_map_single: [%p,%lx] -> DAC %lx from %p\n",
+		      cpu_addr, size, ret, __builtin_return_address(0));
+
+		return ret;
+	}
+
 	/* If the machine doesn't define a pci_tbi routine, we have to
 	   assume it doesn't support sg mapping.  */
 	if (! alpha_mv.mv_pci_tbi) {
@@ -217,12 +238,30 @@
 	ret = arena->dma_base + dma_ofs * PAGE_SIZE;
 	ret += (unsigned long)cpu_addr & ~PAGE_MASK;
 
-	DBGA("pci_map_single: [%p,%lx] np %ld -> sg %x from %p\n",
-	     cpu_addr, size, npages, ret, __builtin_return_address(0));
+	DBGA2("pci_map_single: [%p,%lx] np %ld -> sg %lx from %p\n",
+	      cpu_addr, size, npages, ret, __builtin_return_address(0));
 
 	return ret;
 }
 
+dma_addr_t
+pci_map_single(struct pci_dev *pdev, void *cpu_addr, size_t size, int dir)
+{
+	if (dir == PCI_DMA_NONE)
+		BUG();
+	return pci_map_single_1(pdev, cpu_addr, size,
+			        (pdev->dma_mask >> 32) != 0);
+}
+
+dma_addr_t
+pci_map_page(struct pci_dev *pdev, struct page *page, unsigned long offset,
+	     size_t size, int dir)
+{
+	if (dir == PCI_DMA_NONE)
+		BUG();
+	return pci_map_single_1(pdev, (char *)page_address(page) + offset,
+			        size, (pdev->dma_mask >> 32) != 0);
+}
 
 /* Unmap a single streaming mode DMA translation.  The DMA_ADDR and
    SIZE must match what was provided for in a previous pci_map_single
@@ -231,7 +270,7 @@
    wrote there.  */
 
 void
-pci_unmap_single(struct pci_dev *pdev, dma_addr_t dma_addr, long size,
+pci_unmap_single(struct pci_dev *pdev, dma_addr_t dma_addr, size_t size,
 		 int direction)
 {
 	unsigned long flags;
@@ -242,17 +281,21 @@
 	if (direction == PCI_DMA_NONE)
 		BUG();
 
-#if !DEBUG_NODIRECT
 	if (dma_addr >= __direct_map_base
 	    && dma_addr < __direct_map_base + __direct_map_size) {
 		/* Nothing to do.  */
 
-		DBGA2("pci_unmap_single: direct [%x,%lx] from %p\n",
+		DBGA2("pci_unmap_single: direct [%lx,%lx] from %p\n",
 		      dma_addr, size, __builtin_return_address(0));
 
 		return;
 	}
-#endif
+
+	if (dma_addr > 0xffffffff) {
+		DBGA2("pci64_unmap_single: DAC [%lx,%lx] from %p\n",
+		      dma_addr, size, __builtin_return_address(0));
+		return;
+	}
 
 	arena = hose->sg_pci;
 	if (!arena || dma_addr < arena->dma_base)
@@ -260,7 +303,7 @@
 
 	dma_ofs = (dma_addr - arena->dma_base) >> PAGE_SHIFT;
 	if (dma_ofs * PAGE_SIZE >= arena->size) {
-		printk(KERN_ERR "Bogus pci_unmap_single: dma_addr %x "
+		printk(KERN_ERR "Bogus pci_unmap_single: dma_addr %lx "
 		       " base %x size %x\n", dma_addr, arena->dma_base,
 		       arena->size);
 		return;
@@ -273,21 +316,24 @@
 
 	iommu_arena_free(arena, dma_ofs, npages);
 
-
-        /*
-	   If we're freeing ptes above the `next_entry' pointer (they
+        /* If we're freeing ptes above the `next_entry' pointer (they
            may have snuck back into the TLB since the last wrap flush),
-           we need to flush the TLB before reallocating the latter.
-	*/
+           we need to flush the TLB before reallocating the latter.  */
 	if (dma_ofs >= arena->next_entry)
 		alpha_mv.mv_pci_tbi(hose, dma_addr, dma_addr + size - 1);
 
 	spin_unlock_irqrestore(&arena->lock, flags);
 
-	DBGA("pci_unmap_single: sg [%x,%lx] np %ld from %p\n",
-	     dma_addr, size, npages, __builtin_return_address(0));
+	DBGA2("pci_unmap_single: sg [%lx,%lx] np %ld from %p\n",
+	      dma_addr, size, npages, __builtin_return_address(0));
 }
 
+void
+pci_unmap_page(struct pci_dev *pdev, dma_addr_t dma_addr,
+	       size_t size, int direction)
+{
+	pci_unmap_single(pdev, dma_addr, size, direction);
+}
 
 /* Allocate and map kernel buffer using consistent mode DMA for PCI
    device.  Returns non-NULL cpu-view pointer to the buffer if
@@ -295,7 +341,7 @@
    else DMA_ADDRP is undefined.  */
 
 void *
-pci_alloc_consistent(struct pci_dev *pdev, long size, dma_addr_t *dma_addrp)
+pci_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_addrp)
 {
 	void *cpu_addr;
 	long order = get_order(size);
@@ -311,8 +357,7 @@
 	}
 	memset(cpu_addr, 0, size);
 
-	*dma_addrp = pci_map_single(pdev, cpu_addr, size,
-				    PCI_DMA_BIDIRECTIONAL);
+	*dma_addrp = pci_map_single_1(pdev, cpu_addr, size, 0);
 	if (*dma_addrp == 0) {
 		free_pages((unsigned long)cpu_addr, order);
 		return NULL;
@@ -324,7 +369,6 @@
 	return cpu_addr;
 }
 
-
 /* Free and unmap a consistent DMA buffer.  CPU_ADDR and DMA_ADDR must
    be values that were returned from pci_alloc_consistent.  SIZE must
    be the same as what as passed into pci_alloc_consistent.
@@ -332,7 +376,7 @@
    DMA_ADDR past this call are illegal.  */
 
 void
-pci_free_consistent(struct pci_dev *pdev, long size, void *cpu_addr,
+pci_free_consistent(struct pci_dev *pdev, size_t size, void *cpu_addr,
 		    dma_addr_t dma_addr)
 {
 	pci_unmap_single(pdev, dma_addr, size, PCI_DMA_BIDIRECTIONAL);
@@ -352,27 +396,35 @@
    Write dma_length of each leader with the combined lengths of
    the mergable followers.  */
 
+#define SG_ENT_VIRT_ADDRESS(SG)				\
+	((SG)->address					\
+	 ? (SG)->address				\
+	 : page_address((SG)->page) + (SG)->offset)
+
+#define SG_ENT_PHYS_ADDRESS(SG)	\
+        __pa(SG_ENT_VIRT_ADDRESS(SG))
+
 static void
 sg_classify(struct scatterlist *sg, struct scatterlist *end, int virt_ok)
 {
-	unsigned long next_vaddr;
+	unsigned long next_paddr;
 	struct scatterlist *leader;
 	long leader_flag, leader_length;
 
 	leader = sg;
 	leader_flag = 0;
 	leader_length = leader->length;
-	next_vaddr = (unsigned long)leader->address + leader_length;
+	next_paddr = SG_ENT_PHYS_ADDRESS(leader) + leader_length;
 
 	for (++sg; sg < end; ++sg) {
 		unsigned long addr, len;
-		addr = (unsigned long) sg->address;
+		addr = SG_ENT_PHYS_ADDRESS(sg);
 		len = sg->length;
 
-		if (next_vaddr == addr) {
+		if (next_paddr == addr) {
 			sg->dma_address = -1;
 			leader_length += len;
-		} else if (((next_vaddr | addr) & ~PAGE_MASK) == 0 && virt_ok) {
+		} else if (((next_paddr | addr) & ~PAGE_MASK) == 0 && virt_ok) {
 			sg->dma_address = -2;
 			leader_flag = 1;
 			leader_length += len;
@@ -384,7 +436,7 @@
 			leader_length = len;
 		}
 
-		next_vaddr = addr + len;
+		next_paddr = addr + len;
 	}
 
 	leader->dma_address = leader_flag;
@@ -397,9 +449,9 @@
 static inline int
 sg_fill(struct scatterlist *leader, struct scatterlist *end,
 	struct scatterlist *out, struct pci_iommu_arena *arena,
-	dma_addr_t max_dma)
+	dma_addr_t max_dma, int dac_allowed)
 {
-	unsigned long paddr = virt_to_phys(leader->address);
+	unsigned long paddr = SG_ENT_PHYS_ADDRESS(leader);
 	long size = leader->dma_length;
 	struct scatterlist *sg;
 	unsigned long *ptes;
@@ -414,13 +466,24 @@
 		out->dma_address = paddr + __direct_map_base;
 		out->dma_length = size;
 
-		DBGA("    sg_fill: [%p,%lx] -> direct %x\n",
-		     leader->address, size, out->dma_address);
+		DBGA("    sg_fill: [%p,%lx] -> direct %lx\n",
+		     __va(paddr), size, out->dma_address);
 
 		return 0;
 	}
 #endif
 
+	/* If physically contiguous and DAC is available, use it.  */
+	if (leader->dma_address == 0 && dac_allowed) {
+		out->dma_address = paddr + alpha_mv.pci_dac_offset;
+		out->dma_length = size;
+
+		DBGA("    sg_fill: [%p,%lx] -> DAC %lx\n",
+		     __va(paddr), size, out->dma_address);
+
+		return 0;
+	}
+
 	/* Otherwise, we'll use the iommu to make the pages virtually
 	   contiguous.  */
 
@@ -433,17 +496,16 @@
 			return -1;
 
 		/* Otherwise, break up the remaining virtually contiguous
-		   hunks into individual direct maps.  */
+		   hunks into individual direct maps and retry.  */
 		sg_classify(leader, end, 0);
-		/* Retry.  */
-		return sg_fill(leader, end, out, arena, max_dma);
+		return sg_fill(leader, end, out, arena, max_dma, dac_allowed);
 	}
 
 	out->dma_address = arena->dma_base + dma_ofs*PAGE_SIZE + paddr;
 	out->dma_length = size;
 
-	DBGA("    sg_fill: [%p,%lx] -> sg %x np %ld\n",
-	     leader->address, size, out->dma_address, npages);
+	DBGA("    sg_fill: [%p,%lx] -> sg %lx np %ld\n",
+	     __va(paddr), size, out->dma_address, npages);
 
 	/* All virtually contiguous.  We need to find the length of each
 	   physically contiguous subsegment to fill in the ptes.  */
@@ -455,7 +517,7 @@
 #endif
 
 		size = sg->length;
-		paddr = virt_to_phys(sg->address);
+		paddr = SG_ENT_PHYS_ADDRESS(sg);
 
 		while (sg+1 < end && (int) sg[1].dma_address == -1) {
 			size += sg[1].length;
@@ -470,11 +532,11 @@
 
 #if DEBUG_ALLOC > 0
 		DBGA("    (%ld) [%p,%x] np %ld\n",
-		     last_sg - leader, last_sg->address,
+		     last_sg - leader, SG_ENT_VIRT_ADDRESS(last_sg),
 		     last_sg->length, npages);
 		while (++last_sg <= sg) {
 			DBGA("        (%ld) [%p,%x] cont\n",
-			     last_sg - leader, last_sg->address,
+			     last_sg - leader, SG_ENT_VIRT_ADDRESS(last_sg),
 			     last_sg->length);
 		}
 #endif
@@ -491,15 +553,19 @@
 	struct pci_controller *hose;
 	struct pci_iommu_arena *arena;
 	dma_addr_t max_dma;
+	int dac_allowed;
 
 	if (direction == PCI_DMA_NONE)
 		BUG();
 
+	dac_allowed = ((pdev->dma_mask >> 32) != 0);
+
 	/* Fast path single entry scatterlists.  */
 	if (nents == 1) {
 		sg->dma_length = sg->length;
 		sg->dma_address
-		  = pci_map_single(pdev, sg->address, sg->length, direction);
+		  = pci_map_single_1(pdev, SG_ENT_VIRT_ADDRESS(sg),
+				     sg->length, dac_allowed);
 		return sg->dma_address != 0;
 	}
 
@@ -527,7 +593,7 @@
 	for (out = sg; sg < end; ++sg) {
 		if ((int) sg->dma_address < 0)
 			continue;
-		if (sg_fill(sg, end, out, arena, max_dma) < 0)
+		if (sg_fill(sg, end, out, arena, max_dma, dac_allowed) < 0)
 			goto error;
 		out++;
 	}
@@ -542,7 +608,7 @@
 
 	return out - start;
 
-error:
+ error:
 	printk(KERN_WARNING "pci_map_sg failed: "
 	       "could not allocate dma page tables\n");
 
@@ -553,7 +619,6 @@
 	return 0;
 }
 
-
 /* Unmap a set of streaming mode DMA translations.  Again, cpu read
    rules concerning calls here are the same as for pci_unmap_single()
    above.  */
@@ -586,7 +651,8 @@
 	spin_lock_irqsave(&arena->lock, flags);
 
 	for (end = sg + nents; sg < end; ++sg) {
-		unsigned long addr, size;
+		dma64_addr_t addr;
+		size_t size;
 		long npages, ofs;
 		dma_addr_t tend;
 
@@ -595,7 +661,13 @@
 		if (!size)
 			break;
 
-#if !DEBUG_NODIRECT
+		if (addr > 0xffffffff) {
+			/* It's a DAC address -- nothing to do.  */
+			DBGA("    (%ld) DAC [%lx,%lx]\n",
+			      sg - end + nents, addr, size);
+			continue;
+		}
+
 		if (addr >= __direct_map_base
 		    && addr < __direct_map_base + __direct_map_size) {
 			/* Nothing to do.  */
@@ -603,7 +675,6 @@
 			      sg - end + nents, addr, size);
 			continue;
 		}
-#endif
 
 		DBGA("    (%ld) sg [%lx,%lx]\n",
 		     sg - end + nents, addr, size);
@@ -617,29 +688,27 @@
 		if (fend < tend) fend = tend;
 	}
 
-        /*
-	   If we're freeing ptes above the `next_entry' pointer (they
+        /* If we're freeing ptes above the `next_entry' pointer (they
            may have snuck back into the TLB since the last wrap flush),
-           we need to flush the TLB before reallocating the latter.
-	*/
+           we need to flush the TLB before reallocating the latter.  */
 	if ((fend - arena->dma_base) >> PAGE_SHIFT >= arena->next_entry)
 		alpha_mv.mv_pci_tbi(hose, fbeg, fend);
 
 	spin_unlock_irqrestore(&arena->lock, flags);
 
-	DBGA("pci_unmap_sg: %d entries\n", nents - (end - sg));
+	DBGA("pci_unmap_sg: %ld entries\n", nents - (end - sg));
 }
 
+
 /* Return whether the given PCI device DMA address mask can be
    supported properly.  */
 
 int
-pci_dma_supported(struct pci_dev *pdev, dma_addr_t mask)
+pci_dma_supported(struct pci_dev *pdev, u64 mask)
 {
 	struct pci_controller *hose;
 	struct pci_iommu_arena *arena;
 
-#if !DEBUG_NODIRECT
 	/* If there exists a direct map, and the mask fits either
 	   MAX_DMA_ADDRESS defined such that GFP_DMA does something
 	   useful, or the total system memory as shifted by the
@@ -648,7 +717,6 @@
 	    && (__direct_map_base + MAX_DMA_ADDRESS-IDENT_ADDR-1 <= mask
 		|| __direct_map_base + (max_low_pfn<<PAGE_SHIFT)-1 <= mask))
 		return 1;
-#endif
 
 	/* Check that we have a scatter-gather arena that fits.  */
 	hose = pdev ? pdev->sysdata : pci_isa_hose;
@@ -758,4 +826,50 @@
 		p[i] = IOMMU_RESERVED_PTE;
 
 	return 0;
+}
+
+/* True if the machine supports DAC addressing, and DEV can
+   make use of it given MASK.  */
+
+int
+pci_dac_dma_supported(struct pci_dev *dev, u64 mask)
+{
+	dma64_addr_t dac_offset = alpha_mv.pci_dac_offset;
+	int ok = 1;
+
+	/* If this is not set, the machine doesn't support DAC at all.  */
+	if (dac_offset == 0)
+		ok = 0;
+
+	/* The device has to be able to address our DAC bit.  */
+	if ((dac_offset & dev->dma_mask) != dac_offset)
+		ok = 0;
+
+	/* If both conditions above are met, we are fine. */
+	DBGA("pci_dac_dma_supported %s from %p\n",
+	     ok ? "yes" : "no", __builtin_return_address(0));
+
+	return ok;
+}
+
+dma64_addr_t
+pci_dac_page_to_dma(struct pci_dev *pdev, struct page *page,
+		    unsigned long offset, int direction)
+{
+	return (alpha_mv.pci_dac_offset
+		+ __pa(page_address(page)) 
+		+ (dma64_addr_t) offset);
+}
+
+struct page *
+pci_dac_dma_to_page(struct pci_dev *pdev, dma64_addr_t dma_addr)
+{
+	unsigned long paddr = (dma_addr & PAGE_MASK) - alpha_mv.pci_dac_offset;
+	return virt_to_page(__va(paddr));
+}
+
+unsigned long
+pci_dac_dma_to_offset(struct pci_dev *pdev, dma64_addr_t dma_addr)
+{
+	return (dma_addr & ~PAGE_MASK);
 }
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/sys_cabriolet.c linux/arch/alpha/kernel/sys_cabriolet.c
--- linux-2.4.13-pre1/arch/alpha/kernel/sys_cabriolet.c	Thu Oct  4 18:47:08 2001
+++ linux/arch/alpha/kernel/sys_cabriolet.c	Mon Dec  3 23:17:32 2001
@@ -407,6 +407,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		PYXIS_DAC_OFFSET,
 
 	nr_irqs:		35,
 	device_interrupt:	cabriolet_device_interrupt,
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/sys_dp264.c linux/arch/alpha/kernel/sys_dp264.c
--- linux-2.4.13-pre1/arch/alpha/kernel/sys_dp264.c	Sun Aug 12 10:38:47 2001
+++ linux/arch/alpha/kernel/sys_dp264.c	Mon Dec  3 23:17:32 2001
@@ -574,6 +574,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		TSUNAMI_DAC_OFFSET,
 
 	nr_irqs:		64,
 	device_interrupt:	dp264_device_interrupt,
@@ -598,6 +599,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		TSUNAMI_DAC_OFFSET,
 
 	nr_irqs:		64,
 	device_interrupt:	dp264_device_interrupt,
@@ -621,6 +623,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		TSUNAMI_DAC_OFFSET,
 
 	nr_irqs:		64,
 	device_interrupt:	dp264_device_interrupt,
@@ -644,6 +647,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		TSUNAMI_DAC_OFFSET,
 
 	nr_irqs:		64,
 	device_interrupt:	dp264_device_interrupt,
@@ -672,6 +676,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		TSUNAMI_DAC_OFFSET,
 
 	nr_irqs:		64,
 	device_interrupt:	dp264_device_interrupt,
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/sys_eiger.c linux/arch/alpha/kernel/sys_eiger.c
--- linux-2.4.13-pre1/arch/alpha/kernel/sys_eiger.c	Fri Mar  2 11:12:07 2001
+++ linux/arch/alpha/kernel/sys_eiger.c	Mon Dec  3 23:17:32 2001
@@ -233,6 +233,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		TSUNAMI_DAC_OFFSET,
 
 	nr_irqs:		128,
 	device_interrupt:	eiger_device_interrupt,
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/sys_miata.c linux/arch/alpha/kernel/sys_miata.c
--- linux-2.4.13-pre1/arch/alpha/kernel/sys_miata.c	Sat May 19 17:43:05 2001
+++ linux/arch/alpha/kernel/sys_miata.c	Mon Dec  3 23:17:32 2001
@@ -256,6 +256,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		PYXIS_DAC_OFFSET,
 
 	nr_irqs:		48,
 	device_interrupt:	pyxis_device_interrupt,
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/sys_rawhide.c linux/arch/alpha/kernel/sys_rawhide.c
--- linux-2.4.13-pre1/arch/alpha/kernel/sys_rawhide.c	Mon Jun 11 19:15:27 2001
+++ linux/arch/alpha/kernel/sys_rawhide.c	Mon Dec  3 23:17:32 2001
@@ -254,6 +254,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	MCPCIA_DEFAULT_MEM_BASE,
+	pci_dac_offset:		MCPCIA_DAC_OFFSET,
 
 	nr_irqs:		128,
 	device_interrupt:	rawhide_srm_device_interrupt,
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/sys_ruffian.c linux/arch/alpha/kernel/sys_ruffian.c
--- linux-2.4.13-pre1/arch/alpha/kernel/sys_ruffian.c	Thu Feb  8 12:56:29 2001
+++ linux/arch/alpha/kernel/sys_ruffian.c	Mon Dec  3 23:17:32 2001
@@ -220,6 +220,7 @@
 	max_dma_address:	ALPHA_RUFFIAN_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		PYXIS_DAC_OFFSET,
 
 	nr_irqs:		48,
 	device_interrupt:	pyxis_device_interrupt,
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/sys_sx164.c linux/arch/alpha/kernel/sys_sx164.c
--- linux-2.4.13-pre1/arch/alpha/kernel/sys_sx164.c	Fri Oct 27 10:55:01 2000
+++ linux/arch/alpha/kernel/sys_sx164.c	Mon Dec  3 23:17:32 2001
@@ -129,7 +129,9 @@
 	struct percpu_struct *cpu = (struct percpu_struct*)
 		((char*)hwrpb + hwrpb->processor_offset);
 
-	if (alpha_using_srm && (cpu->pal_revision & 0xffff) == 0x117) {
+	if (amask(AMASK_MAX) != 0
+	    && alpha_using_srm
+	    && (cpu->pal_revision & 0xffff) == 0x117) {
 		__asm__ __volatile__(
 		"lda	$16,8($31)\n"
 		"call_pal 9\n"		/* Allow PALRES insns in kernel mode */
@@ -160,6 +162,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		PYXIS_DAC_OFFSET,
 
 	nr_irqs:		48,
 	device_interrupt:	pyxis_device_interrupt,
diff -urN linux-2.4.13-pre1/arch/alpha/kernel/sys_titan.c linux/arch/alpha/kernel/sys_titan.c
--- linux-2.4.13-pre1/arch/alpha/kernel/sys_titan.c	Fri Mar  2 11:12:07 2001
+++ linux/arch/alpha/kernel/sys_titan.c	Mon Dec  3 23:17:32 2001
@@ -378,6 +378,7 @@
 	max_dma_address:	ALPHA_MAX_DMA_ADDRESS,
 	min_io_address:		DEFAULT_IO_BASE,
 	min_mem_address:	DEFAULT_MEM_BASE,
+	pci_dac_offset:		TITAN_DAC_OFFSET,
 
 	nr_irqs:		80,	/* 64 + 16 */
 	device_interrupt:	privateer_device_interrupt,
diff -urN linux-2.4.13-pre1/arch/ia64/sn/io/pci_dma.c linux/arch/ia64/sn/io/pci_dma.c
--- linux-2.4.13-pre1/arch/ia64/sn/io/pci_dma.c	Thu Apr 12 12:16:35 2001
+++ linux/arch/ia64/sn/io/pci_dma.c	Mon Dec  3 23:17:32 2001
@@ -182,7 +182,7 @@
 }
 
 /*
- * On sn1 we use the alt_address entry of the scatterlist to store
+ * On sn1 we use the orig_address entry of the scatterlist to store
  * the physical address corresponding to the given virtual address
  */
 int
diff -urN linux-2.4.13-pre1/arch/parisc/kernel/ccio-dma.c linux/arch/parisc/kernel/ccio-dma.c
--- linux-2.4.13-pre1/arch/parisc/kernel/ccio-dma.c	Fri Feb  9 11:29:44 2001
+++ linux/arch/parisc/kernel/ccio-dma.c	Mon Dec  3 23:17:32 2001
@@ -638,7 +638,7 @@
 }
 
 
-static int ccio_dma_supported( struct pci_dev *dev, dma_addr_t mask)
+static int ccio_dma_supported( struct pci_dev *dev, u64 mask)
 {
 	if (dev == NULL) {
 		printk(MODULE_NAME ": EISA/ISA/et al not supported\n");
diff -urN linux-2.4.13-pre1/arch/parisc/kernel/ccio-rm-dma.c linux/arch/parisc/kernel/ccio-rm-dma.c
--- linux-2.4.13-pre1/arch/parisc/kernel/ccio-rm-dma.c	Tue Dec  5 12:29:39 2000
+++ linux/arch/parisc/kernel/ccio-rm-dma.c	Mon Dec  3 23:17:32 2001
@@ -93,7 +93,7 @@
 }
 
 
-static int ccio_dma_supported( struct pci_dev *dev, dma_addr_t mask)  
+static int ccio_dma_supported( struct pci_dev *dev, u64 mask)
 {
 	if (dev == NULL) {
 		printk(MODULE_NAME ": EISA/ISA/et al not supported\n");
diff -urN linux-2.4.13-pre1/arch/parisc/kernel/pci-dma.c linux/arch/parisc/kernel/pci-dma.c
--- linux-2.4.13-pre1/arch/parisc/kernel/pci-dma.c	Fri Feb  9 11:29:44 2001
+++ linux/arch/parisc/kernel/pci-dma.c	Mon Dec  3 23:17:32 2001
@@ -77,7 +77,7 @@
 static inline void dump_resmap(void) {;}
 #endif
 
-static int pa11_dma_supported( struct pci_dev *dev, dma_addr_t mask)
+static int pa11_dma_supported( struct pci_dev *dev, u64 mask)
 {
 	return 1;
 }
diff -urN linux-2.4.13-pre1/arch/parisc/kernel/sba_iommu.c linux/arch/parisc/kernel/sba_iommu.c
--- linux-2.4.13-pre1/arch/parisc/kernel/sba_iommu.c	Fri Feb  9 11:29:44 2001
+++ linux/arch/parisc/kernel/sba_iommu.c	Mon Dec  3 23:17:32 2001
@@ -779,7 +779,7 @@
 }
 
 static int
-sba_dma_supported( struct pci_dev *dev, dma_addr_t mask)
+sba_dma_supported( struct pci_dev *dev, u64 mask)
 {
 	if (dev == NULL) {
 		printk(MODULE_NAME ": EISA/ISA/et al not supported\n");
diff -urN linux-2.4.13-pre1/arch/sparc64/kernel/iommu_common.c linux/arch/sparc64/kernel/iommu_common.c
--- linux-2.4.13-pre1/arch/sparc64/kernel/iommu_common.c	Tue Aug 28 07:09:44 2001
+++ linux/arch/sparc64/kernel/iommu_common.c	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: iommu_common.c,v 1.5 2001/08/24 17:57:51 kanoj Exp $
+/* $Id: iommu_common.c,v 1.6 2001/10/09 02:24:33 davem Exp $
  * iommu_common.c: UltraSparc SBUS/PCI common iommu code.
  *
  * Copyright (C) 1999 David S. Miller (davem@redhat.com)
@@ -12,7 +12,7 @@
  */
 
 #ifdef VERIFY_SG
-int verify_lengths(struct scatterlist *sg, int nents, int npages)
+static int verify_lengths(struct scatterlist *sg, int nents, int npages)
 {
 	int sg_len, dma_len;
 	int i, pgcount;
@@ -22,8 +22,8 @@
 		sg_len += sg[i].length;
 
 	dma_len = 0;
-	for (i = 0; i < nents && sg[i].dvma_length; i++)
-		dma_len += sg[i].dvma_length;
+	for (i = 0; i < nents && sg[i].dma_length; i++)
+		dma_len += sg[i].dma_length;
 
 	if (sg_len != dma_len) {
 		printk("verify_lengths: Error, different, sg[%d] dma[%d]\n",
@@ -32,13 +32,13 @@
 	}
 
 	pgcount = 0;
-	for (i = 0; i < nents && sg[i].dvma_length; i++) {
+	for (i = 0; i < nents && sg[i].dma_length; i++) {
 		unsigned long start, end;
 
-		start = sg[i].dvma_address;
+		start = sg[i].dma_address;
 		start = start & IO_PAGE_MASK;
 
-		end = sg[i].dvma_address + sg[i].dvma_length;
+		end = sg[i].dma_address + sg[i].dma_length;
 		end = (end + (IO_PAGE_SIZE - 1)) & IO_PAGE_MASK;
 
 		pgcount += ((end - start) >> IO_PAGE_SHIFT);
@@ -55,15 +55,16 @@
 	return 0;
 }
 
-int verify_one_map(struct scatterlist *dma_sg, struct scatterlist **__sg, int nents, iopte_t **__iopte)
+static int verify_one_map(struct scatterlist *dma_sg, struct scatterlist **__sg, int nents, iopte_t **__iopte)
 {
 	struct scatterlist *sg = *__sg;
 	iopte_t *iopte = *__iopte;
-	u32 dlen = dma_sg->dvma_length;
-	u32 daddr = dma_sg->dvma_address;
+	u32 dlen = dma_sg->dma_length;
+	u32 daddr;
 	unsigned int sglen;
 	unsigned long sgaddr;
 
+	daddr = dma_sg->dma_address;
 	sglen = sg->length;
 	sgaddr = (unsigned long) sg->address;
 	while (dlen > 0) {
@@ -136,7 +137,7 @@
 	return nents;
 }
 
-int verify_maps(struct scatterlist *sg, int nents, iopte_t *iopte)
+static int verify_maps(struct scatterlist *sg, int nents, iopte_t *iopte)
 {
 	struct scatterlist *dma_sg = sg;
 	struct scatterlist *orig_dma_sg = dma_sg;
@@ -147,7 +148,7 @@
 		if (nents <= 0)
 			break;
 		dma_sg++;
-		if (dma_sg->dvma_length == 0)
+		if (dma_sg->dma_length == 0)
 			break;
 	}
 
@@ -174,14 +175,15 @@
 	    verify_maps(sg, nents, iopte) < 0) {
 		int i;
 
-		printk("verify_sglist: Crap, messed up mappings, dumping, iodma at %08x.\n",
-		       (u32) (sg->dvma_address & IO_PAGE_MASK));
+		printk("verify_sglist: Crap, messed up mappings, dumping, iodma at ");
+		printk("%016lx.\n", sg->dma_address & IO_PAGE_MASK);
+
 		for (i = 0; i < nents; i++) {
 			printk("sg(%d): address(%p) length(%x) "
-			       "dma_address[%08x] dma_length[%08x]\n",
+			       "dma_address[%016lx] dma_length[%016lx]\n",
 			       i,
 			       sg[i].address, sg[i].length,
-			       sg[i].dvma_address, sg[i].dvma_length);
+			       sg[i].dma_address, sg[i].dma_length);
 		}
 	}
 
@@ -204,8 +206,8 @@
 		sg++;
 		addr = (unsigned long) sg->address;
 		if (! VCONTIG(prev, addr)) {
-			dma_sg->dvma_address = dent_addr;
-			dma_sg->dvma_length = dent_len;
+			dma_sg->dma_address = dent_addr;
+			dma_sg->dma_length = dent_len;
 			dma_sg++;
 
 			dent_addr = ((dent_addr +
@@ -218,8 +220,8 @@
 		dent_len += sg->length;
 		prev = addr + sg->length;
 	}
-	dma_sg->dvma_address = dent_addr;
-	dma_sg->dvma_length = dent_len;
+	dma_sg->dma_address = dent_addr;
+	dma_sg->dma_length = dent_len;
 
 	return ((unsigned long) dent_addr +
 		(unsigned long) dent_len +
diff -urN linux-2.4.13-pre1/arch/sparc64/kernel/iommu_common.h linux/arch/sparc64/kernel/iommu_common.h
--- linux-2.4.13-pre1/arch/sparc64/kernel/iommu_common.h	Tue Aug 28 07:09:44 2001
+++ linux/arch/sparc64/kernel/iommu_common.h	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: iommu_common.h,v 1.3 2001/08/24 19:36:58 kanoj Exp $
+/* $Id: iommu_common.h,v 1.4 2001/10/09 02:24:33 davem Exp $
  * iommu_common.h: UltraSparc SBUS/PCI common iommu declarations.
  *
  * Copyright (C) 1999 David S. Miller (davem@redhat.com)
@@ -34,10 +34,7 @@
 #undef VERIFY_SG
 
 #ifdef VERIFY_SG
-int verify_lengths(struct scatterlist *sg, int nents, int npages);
-int verify_one_map(struct scatterlist *dma_sg, struct scatterlist **__sg, int nents, iopte_t **__iopte);
-int verify_maps(struct scatterlist *sg, int nents, iopte_t *iopte);
-void verify_sglist(struct scatterlist *sg, int nents, iopte_t *iopte, int npages);
+extern void verify_sglist(struct scatterlist *sg, int nents, iopte_t *iopte, int npages);
 #endif
 
 /* Two addresses are "virtually contiguous" if and only if:
@@ -47,4 +44,4 @@
 #define VCONTIG(__X, __Y)	(((__X) == (__Y)) || \
 				 (((__X) | (__Y)) << (64UL - PAGE_SHIFT)) == 0UL)
 
-unsigned long prepare_sg(struct scatterlist *sg, int nents);
+extern unsigned long prepare_sg(struct scatterlist *sg, int nents);
diff -urN linux-2.4.13-pre1/arch/sparc64/kernel/pci_iommu.c linux/arch/sparc64/kernel/pci_iommu.c
--- linux-2.4.13-pre1/arch/sparc64/kernel/pci_iommu.c	Tue Aug 28 07:09:44 2001
+++ linux/arch/sparc64/kernel/pci_iommu.c	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: pci_iommu.c,v 1.15 2001/08/24 19:36:58 kanoj Exp $
+/* $Id: pci_iommu.c,v 1.16 2001/10/09 02:24:33 davem Exp $
  * pci_iommu.c: UltraSparc PCI controller IOM/STC support.
  *
  * Copyright (C) 1999 David S. Miller (davem@redhat.com)
@@ -378,7 +378,8 @@
 		((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
 #ifdef DEBUG_PCI_IOMMU
 	if (iopte_val(*base) == IOPTE_INVALID)
-		printk("pci_unmap_single called on non-mapped region %08x,%08x from %016lx\n", bus_addr, sz, __builtin_return_address(0));
+		printk("pci_unmap_single called on non-mapped region %08x,%08x from %016lx\n",
+		       bus_addr, sz, __builtin_return_address(0));
 #endif
 	bus_addr &= IO_PAGE_MASK;
 
@@ -423,18 +424,25 @@
 	spin_unlock_irqrestore(&iommu->lock, flags);
 }
 
-static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg, int nused, unsigned long iopte_protection)
+#define SG_ENT_PHYS_ADDRESS(SG)	\
+	((SG)->address ? \
+	 __pa((SG)->address) : \
+	 (__pa(page_address((SG)->page)) + (SG)->offset))
+
+static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
+			   int nused, int nelems, unsigned long iopte_protection)
 {
 	struct scatterlist *dma_sg = sg;
+	struct scatterlist *sg_end = sg + nelems;
 	int i;
 
 	for (i = 0; i < nused; i++) {
 		unsigned long pteval = ~0UL;
 		u32 dma_npages;
 
-		dma_npages = ((dma_sg->dvma_address & (IO_PAGE_SIZE - 1UL)) +
-			      dma_sg->dvma_length +
-			      ((u32)(IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT;
+		dma_npages = ((dma_sg->dma_address & (IO_PAGE_SIZE - 1UL)) +
+			      dma_sg->dma_length +
+			      ((IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT;
 		do {
 			unsigned long offset;
 			signed int len;
@@ -447,7 +455,7 @@
 			for (;;) {
 				unsigned long tmp;
 
-				tmp = (unsigned long) __pa(sg->address);
+				tmp = SG_ENT_PHYS_ADDRESS(sg);
 				len = sg->length;
 				if (((tmp ^ pteval) >> IO_PAGE_SHIFT) != 0UL) {
 					pteval = tmp & IO_PAGE_MASK;
@@ -479,10 +487,11 @@
 			 * adjusting pteval along the way.  Stop when we
 			 * detect a page crossing event.
 			 */
-			while ((pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
-			       pteval == __pa(sg->address) &&
+			while (sg < sg_end &&
+			       (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
+			       (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
 			       ((pteval ^
-				 (__pa(sg->address) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
+				 (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
 				pteval += sg->length;
 				sg++;
 			}
@@ -511,8 +520,13 @@
 
 	/* Fast path single entry scatterlists. */
 	if (nelems == 1) {
-		sglist->dvma_address = pci_map_single(pdev, sglist->address, sglist->length, direction);
-		sglist->dvma_length = sglist->length;
+		sglist->dma_address =
+			pci_map_single(pdev,
+				       (sglist->address ?
+					sglist->address :
+					(page_address(sglist->page) + sglist->offset)),
+				       sglist->length, direction);
+		sglist->dma_length = sglist->length;
 		return 1;
 	}
 
@@ -540,8 +554,8 @@
 	used = nelems;
 
 	sgtmp = sglist;
-	while (used && sgtmp->dvma_length) {
-		sgtmp->dvma_address += dma_base;
+	while (used && sgtmp->dma_length) {
+		sgtmp->dma_address += dma_base;
 		sgtmp++;
 		used--;
 	}
@@ -559,7 +573,7 @@
 		iopte_protection = IOPTE_CONSISTENT(ctx);
 	if (direction != PCI_DMA_TODEVICE)
 		iopte_protection |= IOPTE_WRITE;
-	fill_sg (base, sglist, used, iopte_protection);
+	fill_sg (base, sglist, used, nelems, iopte_protection);
 #ifdef VERIFY_SG
 	verify_sglist(sglist, nelems, base, npages);
 #endif
@@ -591,20 +605,20 @@
 	iommu = pcp->pbm->iommu;
 	strbuf = &pcp->pbm->stc;
 	
-	bus_addr = sglist->dvma_address & IO_PAGE_MASK;
+	bus_addr = sglist->dma_address & IO_PAGE_MASK;
 
 	for (i = 1; i < nelems; i++)
-		if (sglist[i].dvma_length == 0)
+		if (sglist[i].dma_length == 0)
 			break;
 	i--;
-	npages = (IO_PAGE_ALIGN(sglist[i].dvma_address + sglist[i].dvma_length) - bus_addr) >> IO_PAGE_SHIFT;
+	npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length) - bus_addr) >> IO_PAGE_SHIFT;
 
 	base = iommu->page_table +
 		((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
 
 #ifdef DEBUG_PCI_IOMMU
 	if (iopte_val(*base) == IOPTE_INVALID)
-		printk("pci_unmap_sg called on non-mapped region %08x,%d from %016lx\n", sglist->dvma_address, nelems, __builtin_return_address(0));
+		printk("pci_unmap_sg called on non-mapped region %016lx,%d from %016lx\n", sglist->dma_address, nelems, __builtin_return_address(0));
 #endif
 
 	spin_lock_irqsave(&iommu->lock, flags);
@@ -616,7 +630,7 @@
 
 	/* Step 1: Kick data out of streaming buffers if necessary. */
 	if (strbuf->strbuf_enabled) {
-		u32 vaddr = bus_addr;
+		u32 vaddr = (u32) bus_addr;
 
 		PCI_STC_FLUSHFLAG_INIT(strbuf);
 		if (strbuf->strbuf_ctxflush &&
@@ -735,7 +749,7 @@
 		iopte_t *iopte;
 
 		iopte = iommu->page_table +
-			((sglist[0].dvma_address - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
+			((sglist[0].dma_address - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
 		ctx = (iopte_val(*iopte) & IOPTE_CONTEXT) >> 47UL;
 	}
 
@@ -754,13 +768,13 @@
 		unsigned long i, npages;
 		u32 bus_addr;
 
-		bus_addr = sglist[0].dvma_address & IO_PAGE_MASK;
+		bus_addr = sglist[0].dma_address & IO_PAGE_MASK;
 
 		for(i = 1; i < nelems; i++)
-			if (!sglist[i].dvma_length)
+			if (!sglist[i].dma_length)
 				break;
 		i--;
-		npages = (IO_PAGE_ALIGN(sglist[i].dvma_address + sglist[i].dvma_length) - bus_addr) >> IO_PAGE_SHIFT;
+		npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length) - bus_addr) >> IO_PAGE_SHIFT;
 		for (i = 0; i < npages; i++, bus_addr += IO_PAGE_SIZE)
 			pci_iommu_write(strbuf->strbuf_pflush, bus_addr);
 	}
@@ -774,10 +788,10 @@
 	spin_unlock_irqrestore(&iommu->lock, flags);
 }
 
-int pci_dma_supported(struct pci_dev *pdev, dma_addr_t device_mask)
+int pci_dma_supported(struct pci_dev *pdev, u64 device_mask)
 {
 	struct pcidev_cookie *pcp = pdev->sysdata;
-	u32 dma_addr_mask;
+	u64 dma_addr_mask;
 
 	if (pdev == NULL) {
 		dma_addr_mask = 0xffffffff;
diff -urN linux-2.4.13-pre1/arch/sparc64/kernel/pci_psycho.c linux/arch/sparc64/kernel/pci_psycho.c
--- linux-2.4.13-pre1/arch/sparc64/kernel/pci_psycho.c	Tue Aug 28 07:09:44 2001
+++ linux/arch/sparc64/kernel/pci_psycho.c	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: pci_psycho.c,v 1.28 2001/08/24 19:36:58 kanoj Exp $
+/* $Id: pci_psycho.c,v 1.29 2001/10/11 00:44:38 davem Exp $
  * pci_psycho.c: PSYCHO/U2P specific PCI controller support.
  *
  * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@caipfs.rutgers.edu)
@@ -36,7 +36,8 @@
 	__asm__ __volatile__("stxa %0, [%1] %2" \
 			     : /* no outputs */ \
 			     : "r" (__val), "r" (__reg), \
-			       "i" (ASI_PHYS_BYPASS_EC_E))
+			       "i" (ASI_PHYS_BYPASS_EC_E) \
+			     : "memory")
 
 /* Misc. PSYCHO PCI controller register offsets and definitions. */
 #define PSYCHO_CONTROL		0x0010UL
diff -urN linux-2.4.13-pre1/arch/sparc64/kernel/pci_sabre.c linux/arch/sparc64/kernel/pci_sabre.c
--- linux-2.4.13-pre1/arch/sparc64/kernel/pci_sabre.c	Tue Aug 28 07:09:44 2001
+++ linux/arch/sparc64/kernel/pci_sabre.c	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: pci_sabre.c,v 1.39 2001/08/24 19:36:58 kanoj Exp $
+/* $Id: pci_sabre.c,v 1.40 2001/10/11 00:44:38 davem Exp $
  * pci_sabre.c: Sabre specific PCI controller support.
  *
  * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@caipfs.rutgers.edu)
@@ -37,7 +37,8 @@
 	__asm__ __volatile__("stxa %0, [%1] %2" \
 			     : /* no outputs */ \
 			     : "r" (__val), "r" (__reg), \
-			       "i" (ASI_PHYS_BYPASS_EC_E))
+			       "i" (ASI_PHYS_BYPASS_EC_E) \
+			     : "memory")
 
 /* SABRE PCI controller register offsets and definitions. */
 #define SABRE_UE_AFSR		0x0030UL
diff -urN linux-2.4.13-pre1/arch/sparc64/kernel/pci_schizo.c linux/arch/sparc64/kernel/pci_schizo.c
--- linux-2.4.13-pre1/arch/sparc64/kernel/pci_schizo.c	Tue Aug 28 07:09:44 2001
+++ linux/arch/sparc64/kernel/pci_schizo.c	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: pci_schizo.c,v 1.21 2001/08/24 19:36:58 kanoj Exp $
+/* $Id: pci_schizo.c,v 1.22 2001/10/11 00:44:38 davem Exp $
  * pci_schizo.c: SCHIZO specific PCI controller support.
  *
  * Copyright (C) 2001 David S. Miller (davem@redhat.com)
@@ -34,7 +34,8 @@
 	__asm__ __volatile__("stxa %0, [%1] %2" \
 			     : /* no outputs */ \
 			     : "r" (__val), "r" (__reg), \
-			       "i" (ASI_PHYS_BYPASS_EC_E))
+			       "i" (ASI_PHYS_BYPASS_EC_E) \
+			     : "memory")
 
 /* This is a convention that at least Excalibur and Merlin
  * follow.  I suppose the SCHIZO used in Starcat and friends
diff -urN linux-2.4.13-pre1/arch/sparc64/kernel/sbus.c linux/arch/sparc64/kernel/sbus.c
--- linux-2.4.13-pre1/arch/sparc64/kernel/sbus.c	Tue Aug 28 07:09:44 2001
+++ linux/arch/sparc64/kernel/sbus.c	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: sbus.c,v 1.16 2001/08/24 19:36:58 kanoj Exp $
+/* $Id: sbus.c,v 1.17 2001/10/09 02:24:33 davem Exp $
  * sbus.c: UltraSparc SBUS controller support.
  *
  * Copyright (C) 1999 David S. Miller (davem@redhat.com)
@@ -376,18 +376,24 @@
 	spin_unlock_irqrestore(&iommu->lock, flags);
 }
 
-static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg, int nused, unsigned long iopte_bits)
+#define SG_ENT_PHYS_ADDRESS(SG)	\
+	((SG)->address ? \
+	 __pa((SG)->address) : \
+	 (__pa(page_address((SG)->page)) + (SG)->offset))
+
+static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg, int nused, int nelems, unsigned long iopte_bits)
 {
 	struct scatterlist *dma_sg = sg;
+	struct scatterlist *sg_end = sg + nelems;
 	int i;
 
 	for (i = 0; i < nused; i++) {
 		unsigned long pteval = ~0UL;
 		u32 dma_npages;
 
-		dma_npages = ((dma_sg->dvma_address & (IO_PAGE_SIZE - 1UL)) +
-			      dma_sg->dvma_length +
-			      ((u32)(IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT;
+		dma_npages = ((dma_sg->dma_address & (IO_PAGE_SIZE - 1UL)) +
+			      dma_sg->dma_length +
+			      ((IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT;
 		do {
 			unsigned long offset;
 			signed int len;
@@ -400,7 +406,7 @@
 			for (;;) {
 				unsigned long tmp;
 
-				tmp = (unsigned long) __pa(sg->address);
+				tmp = (unsigned long) SG_ENT_PHYS_ADDRESS(sg);
 				len = sg->length;
 				if (((tmp ^ pteval) >> IO_PAGE_SHIFT) != 0UL) {
 					pteval = tmp & IO_PAGE_MASK;
@@ -432,10 +438,11 @@
 			 * adjusting pteval along the way.  Stop when we
 			 * detect a page crossing event.
 			 */
-			while ((pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
-			       pteval == __pa(sg->address) &&
+			while (sg < sg_end &&
+			       (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
+			       (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
 			       ((pteval ^
-				 (__pa(sg->address) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
+				 (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
 				pteval += sg->length;
 				sg++;
 			}
@@ -461,8 +468,13 @@
 
 	/* Fast path single entry scatterlists. */
 	if (nents == 1) {
-		sg->dvma_address = sbus_map_single(sdev, sg->address, sg->length, dir);
-		sg->dvma_length = sg->length;
+		sg->dma_address =
+			sbus_map_single(sdev,
+					(sg->address ?
+					 sg->address :
+					 (page_address(sg->page) + sg->offset)),
+					sg->length, dir);
+		sg->dma_length = sg->length;
 		return 1;
 	}
 
@@ -478,8 +490,8 @@
 	sgtmp = sg;
 	used = nents;
 
-	while (used && sgtmp->dvma_length) {
-		sgtmp->dvma_address += dma_base;
+	while (used && sgtmp->dma_length) {
+		sgtmp->dma_address += dma_base;
 		sgtmp++;
 		used--;
 	}
@@ -489,7 +501,7 @@
 	if (dir != SBUS_DMA_TODEVICE)
 		iopte_bits |= IOPTE_WRITE;
 
-	fill_sg(iopte, sg, used, iopte_bits);
+	fill_sg(iopte, sg, used, nents, iopte_bits);
 #ifdef VERIFY_SG
 	verify_sglist(sg, nents, iopte, npages);
 #endif
@@ -512,17 +524,17 @@
 
 	/* Fast path single entry scatterlists. */
 	if (nents == 1) {
-		sbus_unmap_single(sdev, sg->dvma_address, sg->dvma_length, direction);
+		sbus_unmap_single(sdev, sg->dma_address, sg->dma_length, direction);
 		return;
 	}
 
-	dvma_base = sg[0].dvma_address & IO_PAGE_MASK;
+	dvma_base = sg[0].dma_address & IO_PAGE_MASK;
 	for (i = 0; i < nents; i++) {
-		if (sg[i].dvma_length == 0)
+		if (sg[i].dma_length == 0)
 			break;
 	}
 	i--;
-	size = IO_PAGE_ALIGN(sg[i].dvma_address + sg[i].dvma_length) - dvma_base;
+	size = IO_PAGE_ALIGN(sg[i].dma_address + sg[i].dma_length) - dvma_base;
 
 	iommu = sdev->bus->iommu;
 	spin_lock_irqsave(&iommu->lock, flags);
@@ -550,13 +562,13 @@
 	u32 base;
 	int i;
 
-	base = sg[0].dvma_address & IO_PAGE_MASK;
+	base = sg[0].dma_address & IO_PAGE_MASK;
 	for (i = 0; i < nents; i++) {
-		if (sg[i].dvma_length == 0)
+		if (sg[i].dma_length == 0)
 			break;
 	}
 	i--;
-	size = IO_PAGE_ALIGN(sg[i].dvma_address + sg[i].dvma_length) - base;
+	size = IO_PAGE_ALIGN(sg[i].dma_address + sg[i].dma_length) - base;
 
 	spin_lock_irqsave(&iommu->lock, flags);
 	strbuf_flush(iommu, base, size >> IO_PAGE_SHIFT);
diff -urN linux-2.4.13-pre1/drivers/char/drm/drm_proc.h linux/drivers/char/drm/drm_proc.h
--- linux-2.4.13-pre1/drivers/char/drm/drm_proc.h	Wed Oct 10 23:45:21 2001
+++ linux/drivers/char/drm/drm_proc.h	Mon Dec  3 23:17:33 2001
@@ -186,7 +186,7 @@
 	DRM_PROC_PRINT("slot	 offset	      size type flags	 "
 		       "address mtrr\n\n");
 	i = 0;
-	list_for_each(list, &dev->maplist->head) {
+	if (dev->maplist != NULL) list_for_each(list, &dev->maplist->head) {
 		r_list = (drm_map_list_t *)list;
 		map = r_list->map;
 		if(!map) continue;
diff -urN linux-2.4.13-pre1/drivers/char/epca.c linux/drivers/char/epca.c
--- linux-2.4.13-pre1/drivers/char/epca.c	Sun Sep  9 10:43:02 2001
+++ linux/drivers/char/epca.c	Mon Dec  3 23:17:33 2001
@@ -1572,7 +1572,8 @@
 	cli();
 
 	if ((tty_unregister_driver(&pc_driver)) ||  
-	    (tty_unregister_driver(&pc_callout)))
+	    (tty_unregister_driver(&pc_callout)) ||
+	    (tty_unregister_driver(&pc_info)))
 	{
 		printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n");
 		restore_flags(flags);
diff -urN linux-2.4.13-pre1/drivers/char/nwflash.c linux/drivers/char/nwflash.c
--- linux-2.4.13-pre1/drivers/char/nwflash.c	Thu Sep 13 15:21:32 2001
+++ linux/drivers/char/nwflash.c	Mon Dec  3 23:17:33 2001
@@ -59,6 +59,7 @@
 static int gbWriteBase64Enable;
 static volatile unsigned char *FLASH_BASE;
 static int gbFlashSize = KFLASH_SIZE;
+static DECLARE_MUTEX(nwflash_sem);
 
 extern spinlock_t gpio_lock;
 
@@ -132,7 +133,6 @@
 
 static ssize_t flash_read(struct file *file, char *buf, size_t size, loff_t * ppos)
 {
-	struct inode *inode = file->f_dentry->d_inode;
 	unsigned long p = *ppos;
 	unsigned int count = size;
 	int ret = 0;
@@ -151,7 +151,7 @@
 		/*
 		 * We now lock against reads and writes. --rmk
 		 */
-		if (down_interruptible(&inode->i_sem))
+		if (down_interruptible(&nwflash_sem))
 			return -ERESTARTSYS;
 
 		ret = copy_to_user(buf, (void *)(FLASH_BASE + p), count);
@@ -159,14 +159,13 @@
 			ret = count;
 			*ppos += count;
 		}
-		up(&inode->i_sem);
+		up(&nwflash_sem);
 	}
 	return ret;
 }
 
 static ssize_t flash_write(struct file *file, const char *buf, size_t size, loff_t * ppos)
 {
-	struct inode *inode = file->f_dentry->d_inode;
 	unsigned long p = *ppos;
 	unsigned int count = size;
 	int written;
@@ -198,7 +197,7 @@
 	/*
 	 * We now lock against reads and writes. --rmk
 	 */
-	if (down_interruptible(&inode->i_sem))
+	if (down_interruptible(&nwflash_sem))
 		return -ERESTARTSYS;
 
 	written = 0;
@@ -286,7 +285,7 @@
 	 */
 	leds_event(led_release);
 
-	up(&inode->i_sem);
+	up(&nwflash_sem);
 
 	return written;
 }
diff -urN linux-2.4.13-pre1/drivers/net/acenic.c linux/drivers/net/acenic.c
--- linux-2.4.13-pre1/drivers/net/acenic.c	Wed Oct 10 23:23:24 2001
+++ linux/drivers/net/acenic.c	Mon Dec  3 23:17:33 2001
@@ -165,10 +165,6 @@
 #define SMP_CACHE_BYTES	L1_CACHE_BYTES
 #endif
 
-#if (BITS_PER_LONG == 64) || defined(CONFIG_HIGHMEM)
-#define ACE_64BIT_PTR	1
-#endif
-
 #ifndef SET_MODULE_OWNER
 #define SET_MODULE_OWNER(dev)		{do{} while(0);}
 #define ACE_MOD_INC_USE_COUNT		MOD_INC_USE_COUNT
@@ -203,9 +199,15 @@
 	*dma_handle = virt_to_bus(virt_ptr);
 	return virt_ptr;
 }
+
 #define pci_free_consistent(cookie, size, ptr, dma_ptr)	kfree(ptr)
-#define pci_map_single(cookie, address, size, dir)	virt_to_bus(address)
-#define pci_unmap_single(cookie, address, size, dir)
+#define pci_map_page(cookie, page, off, size, dir)	\
+	virt_to_bus(page_address(page)+(off))
+#define pci_unmap_page(cookie, address, size, dir)
+#define pci_set_dma_mask(dev, mask)		\
+	(((u64)(mask) & 0xffffffff00000000) == 0 ? 0 : -EIO)
+#define pci_dma_supported(dev, mask)		\
+	(((u64)(mask) & 0xffffffff00000000) == 0 ? 1 : 0)
 #endif
 
 #if (LINUX_VERSION_CODE < 0x02032b)
@@ -263,10 +265,6 @@
 #define ace_if_down(dev)			{do{} while(0);}
 #endif
 
-#ifndef pci_set_dma_mask
-#define pci_set_dma_mask(dev, mask)		dev->dma_mask = mask;
-#endif
-
 #if (LINUX_VERSION_CODE >= 0x02031b)
 #define NEW_NETINIT
 #define ACE_PROBE_ARG				void
@@ -598,7 +596,7 @@
 		dev->irq = pdev->irq;
 		dev->open = &ace_open;
 		dev->hard_start_xmit = &ace_start_xmit;
-		dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_HIGHDMA;
+		dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
 		if (1) {
 			static void ace_watchdog(struct net_device *dev);
 			dev->tx_timeout = &ace_watchdog;
@@ -740,6 +738,8 @@
 			kfree(dev);
 			continue;
 		}
+		if (ap->pci_using_dac)
+			dev->features |= NETIF_F_HIGHDMA;
 
 		boards_found++;
 	}
@@ -816,9 +816,9 @@
 				dma_addr_t mapping;
 
 				mapping = ap->skb->rx_std_skbuff[i].mapping;
-				pci_unmap_single(ap->pdev, mapping,
-						 ACE_STD_BUFSIZE - (2 + 16),
-						 PCI_DMA_FROMDEVICE);
+				pci_unmap_page(ap->pdev, mapping,
+					       ACE_STD_BUFSIZE - (2 + 16),
+					       PCI_DMA_FROMDEVICE);
 
 				ap->rx_std_ring[i].size = 0;
 				ap->skb->rx_std_skbuff[i].skb = NULL;
@@ -833,9 +833,9 @@
 					dma_addr_t mapping;
 
 					mapping = ap->skb->rx_mini_skbuff[i].mapping;
-					pci_unmap_single(ap->pdev, mapping,
-							 ACE_MINI_BUFSIZE - (2 + 16),
-							 PCI_DMA_FROMDEVICE);
+					pci_unmap_page(ap->pdev, mapping,
+						       ACE_MINI_BUFSIZE - (2 + 16),
+						       PCI_DMA_FROMDEVICE);
 
 					ap->rx_mini_ring[i].size = 0;
 					ap->skb->rx_mini_skbuff[i].skb = NULL;
@@ -849,9 +849,9 @@
 				dma_addr_t mapping;
 
 				mapping = ap->skb->rx_jumbo_skbuff[i].mapping;
-				pci_unmap_single(ap->pdev, mapping,
-						 ACE_JUMBO_BUFSIZE - (2 + 16),
-						 PCI_DMA_FROMDEVICE);
+				pci_unmap_page(ap->pdev, mapping,
+					       ACE_JUMBO_BUFSIZE - (2 + 16),
+					       PCI_DMA_FROMDEVICE);
 
 				ap->rx_jumbo_ring[i].size = 0;
 				ap->skb->rx_jumbo_skbuff[i].skb = NULL;
@@ -1210,12 +1210,6 @@
 		ap->pci_latency);
 
 	/*
-	 * Make sure to enable the 64 bit DMA mask if we're in a 64bit slot
-	 */
-	if (!(pci_state & PCI_32BIT))
-		pci_set_dma_mask(ap->pdev, (dma_addr_t)~0ULL);
-
-	/*
 	 * Set the max DMA transfer size. Seems that for most systems
 	 * the performance is better when no MAX parameter is
 	 * set. However for systems enabling PCI write and invalidate,
@@ -1309,12 +1303,24 @@
 #endif
 		
 	/*
+	 * Configure DMA attributes.
+	 */
+	if (!pci_set_dma_mask(ap->pdev, (u64) 0xffffffffffffffff)) {
+		ap->pci_using_dac = 1;
+	} else if (!pci_set_dma_mask(ap->pdev, (u64) 0xffffffff)) {
+		ap->pci_using_dac = 0;
+	} else {
+		ecode = -ENODEV;
+		goto init_error;
+	}
+
+	/*
 	 * Initialize the generic info block and the command+event rings
 	 * and the control blocks for the transmit and receive rings
 	 * as they need to be setup once and for all.
 	 */
 	if (!(info = pci_alloc_consistent(ap->pdev, sizeof(struct ace_info),
-				    &ap->info_dma))) {
+					  &ap->info_dma))) {
 		ecode = -EAGAIN;
 		goto init_error;
 	}
@@ -1355,12 +1361,8 @@
 	ace_load_firmware(dev);
 	ap->fw_running = 0;
 
-	tmp_ptr = (unsigned long) ap->info_dma;
-#ifdef ACE_64BIT_PTR
+	tmp_ptr = (u64) ap->info_dma;
 	writel(tmp_ptr >> 32, &regs->InfoPtrHi);
-#else
-	writel(0, &regs->InfoPtrHi);
-#endif
 	writel(tmp_ptr & 0xffffffff, &regs->InfoPtrLo);
 
 	memset(ap->evt_ring, 0, EVT_RING_ENTRIES * sizeof(struct event));
@@ -1796,9 +1798,12 @@
 		 * Make sure IP header starts on a fresh cache line.
 		 */
 		skb_reserve(skb, 2 + 16);
-		mapping = pci_map_single(ap->pdev, skb->data,
-					 ACE_STD_BUFSIZE - (2 + 16),
-					 PCI_DMA_FROMDEVICE);
+		mapping = pci_map_page(ap->pdev,
+				       virt_to_page(skb->data),
+				       ((unsigned long) skb->data &
+					~PAGE_MASK),
+				       ACE_STD_BUFSIZE - (2 + 16),
+				       PCI_DMA_FROMDEVICE);
 		ap->skb->rx_std_skbuff[idx].skb = skb;
 		ap->skb->rx_std_skbuff[idx].mapping = mapping;
 
@@ -1860,9 +1865,12 @@
 		 * Make sure the IP header ends up on a fresh cache line
 		 */
 		skb_reserve(skb, 2 + 16);
-		mapping = pci_map_single(ap->pdev, skb->data,
-					 ACE_MINI_BUFSIZE - (2 + 16),
-					 PCI_DMA_FROMDEVICE);
+		mapping = pci_map_page(ap->pdev,
+				       virt_to_page(skb->data),
+				       ((unsigned long) skb->data &
+					~PAGE_MASK),
+				       ACE_MINI_BUFSIZE - (2 + 16),
+				       PCI_DMA_FROMDEVICE);
 		ap->skb->rx_mini_skbuff[idx].skb = skb;
 		ap->skb->rx_mini_skbuff[idx].mapping = mapping;
 
@@ -1919,9 +1927,12 @@
 		 * Make sure the IP header ends up on a fresh cache line
 		 */
 		skb_reserve(skb, 2 + 16);
-		mapping = pci_map_single(ap->pdev, skb->data,
-					 ACE_JUMBO_BUFSIZE - (2 + 16),
-					 PCI_DMA_FROMDEVICE);
+		mapping = pci_map_page(ap->pdev,
+				       virt_to_page(skb->data),
+				       ((unsigned long) skb->data &
+					~PAGE_MASK),
+				       ACE_JUMBO_BUFSIZE - (2 + 16),
+				       PCI_DMA_FROMDEVICE);
 		ap->skb->rx_jumbo_skbuff[idx].skb = skb;
 		ap->skb->rx_jumbo_skbuff[idx].mapping = mapping;
 
@@ -2129,8 +2140,8 @@
 
 		skb = rip->skb;
 		rip->skb = NULL;
-		pci_unmap_single(ap->pdev, rip->mapping, mapsize,
-				 PCI_DMA_FROMDEVICE);
+		pci_unmap_page(ap->pdev, rip->mapping, mapsize,
+			       PCI_DMA_FROMDEVICE);
 		skb_put(skb, retdesc->size);
 
 		/*
@@ -2198,8 +2209,8 @@
 		mapping = info->mapping;
 
 		if (mapping) {
-			pci_unmap_single(ap->pdev, mapping, info->maplen,
-					 PCI_DMA_TODEVICE);
+			pci_unmap_page(ap->pdev, mapping, info->maplen,
+				       PCI_DMA_TODEVICE);
 			info->mapping = 0;
 		}
 
@@ -2488,11 +2499,10 @@
 
 		if (mapping) {
 			memset(ap->tx_ring+i, 0, sizeof(struct tx_desc));
-			pci_unmap_single(ap->pdev, mapping, info->maplen,
-					 PCI_DMA_TODEVICE);
+			pci_unmap_page(ap->pdev, mapping, info->maplen,
+				       PCI_DMA_TODEVICE);
 			info->mapping = 0;
 		}
-
 		if (skb) {
 			dev_kfree_skb(skb);
 			info->skb = NULL;
@@ -2512,75 +2522,35 @@
 	return 0;
 }
 
-
-/*
- * Following below should be (in more clean form!) in arch/ARCH/kernel/pci_*.
- * For now, let it stay here.
- */
-#if defined(CONFIG_HIGHMEM) && MAX_SKB_FRAGS
-
-#if defined(CONFIG_X86)
-#define DMAADDR_OFFSET	0
-typedef unsigned long long dmaaddr_high_t;
-#elif defined(CONFIG_PPC)
-#define DMAADDR_OFFSET PCI_DRAM_OFFSET
-typedef unsigned long dmaaddr_high_t;
-#endif
-
-
-static inline dmaaddr_high_t
-pci_map_single_high(struct pci_dev *hwdev, struct page *page,
-		    int offset, size_t size, int dir)
-{
-	dmaaddr_high_t phys;
-
-	phys = (page-mem_map) *	(dmaaddr_high_t) PAGE_SIZE + offset;
-
-	return (phys + DMAADDR_OFFSET);
-}
-
-#else
-
-typedef unsigned long dmaaddr_high_t;
-
-static inline dmaaddr_high_t
-pci_map_single_high(struct pci_dev *hwdev, struct page *page,
-		    int offset, size_t size, int dir)
-{
-	return pci_map_single(hwdev, page_address(page) + offset, size, dir);
-}
-
-#endif
-
-
-static inline dmaaddr_high_t
+static inline dma_addr_t
 ace_map_tx_skb(struct ace_private *ap, struct sk_buff *skb,
 	       struct sk_buff *tail, u32 idx)
 {
 	unsigned long addr;
 	struct tx_ring_info *info;
 
-	addr = pci_map_single(ap->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
+	addr = pci_map_page(ap->pdev,
+			    virt_to_page(skb->data),
+			    ((unsigned long) skb->data &
+			     ~PAGE_MASK),
+			    skb->len, PCI_DMA_TODEVICE);
 
 	info = ap->skb->tx_skbuff + idx;
 	info->skb = tail;
 	info->mapping = addr;
 	info->maplen = skb->len;
-
 	return addr;
 }
 
 
 static inline void
-ace_load_tx_bd(struct tx_desc *desc, dmaaddr_high_t addr, u32 flagsize)
+ace_load_tx_bd(struct tx_desc *desc, u64 addr, u32 flagsize)
 {
 #if !USE_TX_COAL_NOW
 	flagsize &= ~BD_FLG_COAL_NOW;
 #endif
 
-#ifdef ACE_64BIT_PTR
 	desc->addr.addrhi = addr >> 32;
-#endif
 	desc->addr.addrlo = addr;
 	desc->flagsize = flagsize;
 }
@@ -2642,16 +2612,16 @@
 		for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
 			skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
 			struct tx_ring_info *info;
-			dmaaddr_high_t phys;
+			dma_addr_t phys;
 
 			len += frag->size;
 			info = ap->skb->tx_skbuff + idx;
 			desc = ap->tx_ring + idx;
 
-			phys = pci_map_single_high(ap->pdev, frag->page,
-						   frag->page_offset,
-						   frag->size,
-						   PCI_DMA_TODEVICE);
+			phys = pci_map_page(ap->pdev, frag->page,
+					    frag->page_offset,
+					    frag->size,
+					    PCI_DMA_TODEVICE);
 
 			flagsize = (frag->size << 16);
 			if (skb->ip_summed == CHECKSUM_HW)
@@ -2673,7 +2643,6 @@
 			}
 			info->mapping = phys;
 			info->maplen = frag->size;
-
 			ace_load_tx_bd(desc, phys, flagsize);
 		}
 	}
@@ -2995,7 +2964,7 @@
 
 	while (size > 0) {
 		tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
-				min_t(u32, size, ACE_WINDOW_SIZE));
+			    min_t(u32, size, ACE_WINDOW_SIZE));
 		tdest = (unsigned long)&regs->Window +
 			(dest & (ACE_WINDOW_SIZE - 1));
 		writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
@@ -3026,7 +2995,7 @@
 
 	while (size > 0) {
 		tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
-			    min_t(u32, size, ACE_WINDOW_SIZE));
+				min_t(u32, size, ACE_WINDOW_SIZE));
 		tdest = (unsigned long)&regs->Window +
 			(dest & (ACE_WINDOW_SIZE - 1));
 		writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
diff -urN linux-2.4.13-pre1/drivers/net/acenic.h linux/drivers/net/acenic.h
--- linux-2.4.13-pre1/drivers/net/acenic.h	Wed Oct 10 23:23:24 2001
+++ linux/drivers/net/acenic.h	Mon Dec  3 23:17:33 2001
@@ -582,7 +582,6 @@
 	aceaddr	stats2_ptr;
 };
 
-
 struct ring_info {
 	struct sk_buff		*skb;
 	dma_addr_t		mapping;
@@ -684,6 +683,7 @@
 	u32			last_tx, last_std_rx, last_mini_rx;
 #endif
 	struct net_device_stats stats;
+	int			pci_using_dac;
 };
 
 
@@ -705,31 +705,11 @@
 
 static inline void set_aceaddr(aceaddr *aa, dma_addr_t addr)
 {
-	unsigned long baddr = (unsigned long) addr;
-#ifdef ACE_64BIT_PTR
+	u64 baddr = (u64) addr;
 	aa->addrlo = baddr & 0xffffffff;
 	aa->addrhi = baddr >> 32;
-#else
-	/* Don't bother setting zero every time */
-	aa->addrlo = baddr;
-#endif
 	mb();
 }
-
-
-#if 0
-static inline void *get_aceaddr(aceaddr *aa)
-{
-	unsigned long addr;
-	mb();
-#ifdef ACE_64BIT_PTR
-	addr = (u64)aa->addrhi << 32 | aa->addrlo;
-#else
-	addr = aa->addrlo;
-#endif
-	return (void *)addr;
-}
-#endif
 
 
 static inline void ace_set_txprd(struct ace_regs *regs,
diff -urN linux-2.4.13-pre1/drivers/net/hamradio/scc.c linux/drivers/net/hamradio/scc.c
--- linux-2.4.13-pre1/drivers/net/hamradio/scc.c	Thu Sep 13 16:04:43 2001
+++ linux/drivers/net/hamradio/scc.c	Mon Dec  3 23:17:33 2001
@@ -1,5 +1,3 @@
-#define RCS_ID "$Id: scc.c,v 1.75 1998/11/04 15:15:01 jreuter Exp jreuter $"
-
 #define VERSION "3.0"
 
 /*
@@ -18,7 +16,7 @@
 
    ********************************************************************
 
-	Copyright (c) 1993, 2000 Joerg Reuter DL1BKE
+	Copyright (c) 1993, 2001 Joerg Reuter DL1BKE
 
 	portions (c) 1993 Guido ten Dolle PE1NNZ
 
@@ -106,6 +104,10 @@
    2000-02-13	Fixed for new network driver interface changes, still
    		does TX timeouts itself since it uses its own queue
    		scheme.
+   2001-10-05   Set skb to NULL on Rx_OVR in scc_spint() (tnx everybody
+		who insisted that the skb gets in fact re-used by the
+		following code otherwise. I think we have another Z8530
+		bug here...)
 
    Thanks to all who contributed to this driver with ideas and bug
    reports!
@@ -583,6 +585,7 @@
 		if (skb != NULL) 
 			dev_kfree_skb_irq(skb);
 		scc->rx_buff = skb = NULL;
+		skb = NULL;			/* avoid skb being reused */
 	}
 
 	if(status & END_FR && skb != NULL)	/* end of frame */
diff -urN linux-2.4.13-pre1/drivers/net/pcmcia/netwave_cs.c linux/drivers/net/pcmcia/netwave_cs.c
--- linux-2.4.13-pre1/drivers/net/pcmcia/netwave_cs.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/net/pcmcia/netwave_cs.c	Mon Dec  3 23:17:33 2001
@@ -269,8 +269,15 @@
    because they generally can't be allocated dynamically.
 */
 
-#define SIOCGIPSNAP	SIOCDEVPRIVATE		/* Site Survey Snapshot */
-/*#define SIOCGIPQTHR	SIOCDEVPRIVATE + 1*/
+/* Wireless Extension Backward compatibility - Jean II
+ * If the new wireless device private ioctl range is not defined,
+ * default to standard device private ioctl range */
+#ifndef SIOCIWFIRSTPRIV
+#define SIOCIWFIRSTPRIV	SIOCDEVPRIVATE
+#endif /* SIOCIWFIRSTPRIV */
+
+#define SIOCGIPSNAP	SIOCIWFIRSTPRIV		/* Site Survey Snapshot */
+/*#define SIOCGIPQTHR	SIOCIWFIRSTPRIV + 1*/
 
 #define MAX_ESA 10
 
diff -urN linux-2.4.13-pre1/drivers/net/pcmcia/ray_cs.c linux/drivers/net/pcmcia/ray_cs.c
--- linux-2.4.13-pre1/drivers/net/pcmcia/ray_cs.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/net/pcmcia/ray_cs.c	Mon Dec  3 23:17:33 2001
@@ -1451,9 +1451,12 @@
 #endif	/* WIRELESS_SPY */
 
       /* ------------------ PRIVATE IOCTL ------------------ */
-#define SIOCSIPFRAMING	SIOCDEVPRIVATE		/* Set framing mode */
-#define SIOCGIPFRAMING	SIOCDEVPRIVATE + 1	/* Get framing mode */
-#define SIOCGIPCOUNTRY	SIOCDEVPRIVATE + 3	/* Get country code */
+#ifndef SIOCIWFIRSTPRIV
+#define SIOCIWFIRSTPRIV	SIOCDEVPRIVATE
+#endif /* SIOCIWFIRSTPRIV */
+#define SIOCSIPFRAMING	SIOCIWFIRSTPRIV		/* Set framing mode */
+#define SIOCGIPFRAMING	SIOCIWFIRSTPRIV + 1	/* Get framing mode */
+#define SIOCGIPCOUNTRY	SIOCIWFIRSTPRIV + 3	/* Get country code */
     case SIOCSIPFRAMING:
       if(!capable(CAP_NET_ADMIN))	/* For private IOCTLs, we need to check permissions */
 	{
diff -urN linux-2.4.13-pre1/drivers/net/pcmcia/wavelan_cs.c linux/drivers/net/pcmcia/wavelan_cs.c
--- linux-2.4.13-pre1/drivers/net/pcmcia/wavelan_cs.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/net/pcmcia/wavelan_cs.c	Mon Dec  3 23:17:33 2001
@@ -2269,6 +2269,12 @@
 	  range.max_qual.qual = MMR_SGNL_QUAL;
 	  range.max_qual.level = MMR_SIGNAL_LVL;
 	  range.max_qual.noise = MMR_SILENCE_LVL;
+#if WIRELESS_EXT > 11
+	  range.avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
+	  /* Need to get better values for those two */
+	  range.avg_qual.level = 30;
+	  range.avg_qual.noise = 8;
+#endif /* WIRELESS_EXT > 11 */
 
 #if WIRELESS_EXT > 7
 	  range.num_bitrates = 1;
diff -urN linux-2.4.13-pre1/drivers/net/pcmcia/wavelan_cs.h linux/drivers/net/pcmcia/wavelan_cs.h
--- linux-2.4.13-pre1/drivers/net/pcmcia/wavelan_cs.h	Wed Apr 18 14:40:05 2001
+++ linux/drivers/net/pcmcia/wavelan_cs.h	Mon Dec  3 23:17:33 2001
@@ -465,13 +465,20 @@
 
 /* ------------------------ PRIVATE IOCTL ------------------------ */
 
-#define SIOCSIPQTHR	SIOCDEVPRIVATE		/* Set quality threshold */
-#define SIOCGIPQTHR	SIOCDEVPRIVATE + 1	/* Get quality threshold */
-#define SIOCSIPROAM     SIOCDEVPRIVATE + 2      /* Set roaming state */
-#define SIOCGIPROAM     SIOCDEVPRIVATE + 3      /* Get roaming state */
+/* Wireless Extension Backward compatibility - Jean II
+ * If the new wireless device private ioctl range is not defined,
+ * default to standard device private ioctl range */
+#ifndef SIOCIWFIRSTPRIV
+#define SIOCIWFIRSTPRIV	SIOCDEVPRIVATE
+#endif /* SIOCIWFIRSTPRIV */
 
-#define SIOCSIPHISTO	SIOCDEVPRIVATE + 6	/* Set histogram ranges */
-#define SIOCGIPHISTO	SIOCDEVPRIVATE + 7	/* Get histogram values */
+#define SIOCSIPQTHR	SIOCIWFIRSTPRIV		/* Set quality threshold */
+#define SIOCGIPQTHR	SIOCIWFIRSTPRIV + 1	/* Get quality threshold */
+#define SIOCSIPROAM     SIOCIWFIRSTPRIV + 2	/* Set roaming state */
+#define SIOCGIPROAM     SIOCIWFIRSTPRIV + 3	/* Get roaming state */
+
+#define SIOCSIPHISTO	SIOCIWFIRSTPRIV + 6	/* Set histogram ranges */
+#define SIOCGIPHISTO	SIOCIWFIRSTPRIV + 7	/* Get histogram values */
 
 /*************************** WaveLAN Roaming  **************************/
 #ifdef WAVELAN_ROAMING		/* Conditional compile, see above in options */
diff -urN linux-2.4.13-pre1/drivers/net/sk98lin/skge.c linux/drivers/net/sk98lin/skge.c
--- linux-2.4.13-pre1/drivers/net/sk98lin/skge.c	Wed Oct 10 23:23:24 2001
+++ linux/drivers/net/sk98lin/skge.c	Mon Dec  3 23:17:33 2001
@@ -443,6 +443,11 @@
 		if (pci_enable_device(pdev))
 			continue;
 
+		/* Configure DMA attributes. */
+		if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffff) &&
+		    pci_set_dma_mask(pdev, (u64) 0xffffffff))
+				continue;
+
 		if ((dev = init_etherdev(dev, sizeof(DEV_NET))) == 0) {
 			printk(KERN_ERR "Unable to allocate etherdev "
 			       "structure!\n");
@@ -1770,10 +1775,12 @@
 #endif
 
 	/* set up descriptor and CONTROL dword */
-	PhysAddr = (SK_U64) pci_map_single(&pAC->PciDev,
-					   pMessage->data,
-					   pMessage->len,
-					   PCI_DMA_TODEVICE);
+	PhysAddr = (SK_U64) pci_map_page(&pAC->PciDev,
+					 virt_to_page(pMessage->data),
+					 ((unsigned long) pMessage->data &
+					  ~PAGE_MASK),
+					 pMessage->len,
+					 PCI_DMA_TODEVICE);
 	pTxd->VDataLow = (SK_U32)  (PhysAddr & 0xffffffff);
 	pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
 	pTxd->pMBuf = pMessage;
@@ -1865,9 +1872,9 @@
 		/* release the DMA mapping */
 		PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
 		PhysAddr |= (SK_U64) pTxd->VDataLow;
-		pci_unmap_single(&pAC->PciDev, PhysAddr,
-				 pTxd->pMBuf->len,
-				 PCI_DMA_TODEVICE);
+		pci_unmap_page(&pAC->PciDev, PhysAddr,
+			       pTxd->pMBuf->len,
+			       PCI_DMA_TODEVICE);
 
 		/* free message */
 		DEV_KFREE_SKB_ANY(pTxd->pMBuf);
@@ -1946,10 +1953,12 @@
 	pRxPort->pRxdRingTail = pRxd->pNextRxd;
 	pRxPort->RxdRingFree--;
 	Length = pAC->RxBufSize;
-	PhysAddr = (SK_U64) pci_map_single(&pAC->PciDev,
-					   pMsgBlock->data,
-					   pAC->RxBufSize - 2,
-					   PCI_DMA_FROMDEVICE);
+	PhysAddr = (SK_U64) pci_map_page(&pAC->PciDev,
+					 virt_to_page(pMsgBlock->data),
+					 ((unsigned long) pMsgBlock->data &
+					  ~PAGE_MASK),
+					 pAC->RxBufSize - 2,
+					 PCI_DMA_FROMDEVICE);
 	pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
 	pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
 	pRxd->pMBuf = pMsgBlock;
@@ -2093,9 +2102,9 @@
 			PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
 			PhysAddr |= (SK_U64) pRxd->VDataLow;
 			pci_dma_sync_single(&pAC->PciDev,
-						(dma_addr_t) PhysAddr,
-						FrameLength,
-						PCI_DMA_FROMDEVICE);
+					    (dma_addr_t) PhysAddr,
+					    FrameLength,
+					    PCI_DMA_FROMDEVICE);
 			ReQueueRxBuffer(pAC, pRxPort, pMsg,
 				pRxd->VDataHigh, pRxd->VDataLow);
 
@@ -2117,9 +2126,9 @@
 			skb_reserve(pNewMsg, 2);
 			skb_put(pNewMsg, FrameLength);
 			pci_dma_sync_single(&pAC->PciDev,
-						(dma_addr_t) PhysAddr,
-						FrameLength,
-						PCI_DMA_FROMDEVICE);
+					    (dma_addr_t) PhysAddr,
+					    FrameLength,
+					    PCI_DMA_FROMDEVICE);
 			eth_copy_and_sum(pNewMsg, pMsg->data,
 				FrameLength, 0);
 			ReQueueRxBuffer(pAC, pRxPort, pMsg,
@@ -2137,10 +2146,10 @@
 			PhysAddr |= (SK_U64) pRxd->VDataLow;
 
 			/* release the DMA mapping */
-			pci_unmap_single(&pAC->PciDev,
-					 PhysAddr,
-					 pAC->RxBufSize - 2,
-					 PCI_DMA_FROMDEVICE);
+			pci_unmap_page(&pAC->PciDev,
+				       PhysAddr,
+				       pAC->RxBufSize - 2,
+				       PCI_DMA_FROMDEVICE);
 
 			/* set length in message */
 			skb_put(pMsg, FrameLength);
@@ -2262,10 +2271,10 @@
 	/* release the DMA mapping */
 	PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
 	PhysAddr |= (SK_U64) pRxd->VDataLow;
-	pci_unmap_single(&pAC->PciDev,
-			 PhysAddr,
-			 pAC->RxBufSize - 2,
-			 PCI_DMA_FROMDEVICE);
+	pci_unmap_page(&pAC->PciDev,
+		       PhysAddr,
+		       pAC->RxBufSize - 2,
+		       PCI_DMA_FROMDEVICE);
 	DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
 	pRxd->pMBuf = NULL;
 	pRxPort->RxdRingFree++;
@@ -2342,10 +2351,10 @@
 		if (pRxd->pMBuf != NULL) {
 			PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
 			PhysAddr |= (SK_U64) pRxd->VDataLow;
-			pci_unmap_single(&pAC->PciDev,
-					 PhysAddr,
-					 pAC->RxBufSize - 2,
-					 PCI_DMA_FROMDEVICE);
+			pci_unmap_page(&pAC->PciDev,
+				       PhysAddr,
+				       pAC->RxBufSize - 2,
+				       PCI_DMA_FROMDEVICE);
 			DEV_KFREE_SKB(pRxd->pMBuf);
 			pRxd->pMBuf = NULL;
 		}
diff -urN linux-2.4.13-pre1/drivers/net/sungem.c linux/drivers/net/sungem.c
--- linux-2.4.13-pre1/drivers/net/sungem.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/net/sungem.c	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: sungem.c,v 1.20 2001/09/19 00:04:32 davem Exp $
+/* $Id: sungem.c,v 1.22 2001/10/09 02:24:33 davem Exp $
  * sungem.c: Sun GEM ethernet driver.
  *
  * Copyright (C) 2000, 2001 David S. Miller (davem@redhat.com)
@@ -418,7 +418,8 @@
 	while (entry != limit) {
 		struct sk_buff *skb;
 		struct gem_txd *txd;
-		u32 dma_addr, dma_len;
+		dma_addr_t dma_addr;
+		u32 dma_len;
 		int frag;
 
 		skb = gp->tx_skbs[entry];
@@ -444,10 +445,10 @@
 		for (frag = 0; frag <= skb_shinfo(skb)->nr_frags; frag++) {
 			txd = &gp->init_block->txd[entry];
 
-			dma_addr = (u32) le64_to_cpu(txd->buffer);
+			dma_addr = le64_to_cpu(txd->buffer);
 			dma_len = le64_to_cpu(txd->control_word) & TXDCTRL_BUFSZ;
 
-			pci_unmap_single(gp->pdev, dma_addr, dma_len, PCI_DMA_TODEVICE);
+			pci_unmap_page(gp->pdev, dma_addr, dma_len, PCI_DMA_TODEVICE);
 			entry = NEXT_TX(entry);
 		}
 
@@ -498,7 +499,7 @@
 		struct gem_rxd *rxd = &gp->init_block->rxd[entry];
 		struct sk_buff *skb;
 		u64 status = cpu_to_le64(rxd->status_word);
-		u32 dma_addr;
+		dma_addr_t dma_addr;
 		int len;
 
 		if ((status & RXDCTRL_OWN) != 0)
@@ -520,7 +521,7 @@
 			goto next;
 		}
 
-		dma_addr = (u32) cpu_to_le64(rxd->buffer);
+		dma_addr = cpu_to_le64(rxd->buffer);
 		if (len > RX_COPY_THRESHOLD) {
 			struct sk_buff *new_skb;
 
@@ -529,15 +530,18 @@
 				drops++;
 				goto drop_it;
 			}
-			pci_unmap_single(gp->pdev, dma_addr,
-					 RX_BUF_ALLOC_SIZE(gp), PCI_DMA_FROMDEVICE);
+			pci_unmap_page(gp->pdev, dma_addr,
+				       RX_BUF_ALLOC_SIZE(gp),
+				       PCI_DMA_FROMDEVICE);
 			gp->rx_skbs[entry] = new_skb;
 			new_skb->dev = gp->dev;
 			skb_put(new_skb, (ETH_FRAME_LEN + RX_OFFSET));
-			rxd->buffer = cpu_to_le64(pci_map_single(gp->pdev,
-								 new_skb->data,
-								 RX_BUF_ALLOC_SIZE(gp),
-								 PCI_DMA_FROMDEVICE));
+			rxd->buffer = cpu_to_le64(pci_map_page(gp->pdev,
+							       virt_to_page(new_skb->data),
+							       ((unsigned long) new_skb->data &
+								~PAGE_MASK),
+							       RX_BUF_ALLOC_SIZE(gp),
+							       PCI_DMA_FROMDEVICE));
 			skb_reserve(new_skb, RX_OFFSET);
 
 			/* Trim the original skb for the netif. */
@@ -661,37 +665,45 @@
 
 	if (skb_shinfo(skb)->nr_frags == 0) {
 		struct gem_txd *txd = &gp->init_block->txd[entry];
-		u32 mapping, len;
+		dma_addr_t mapping;
+		u32 len;
 
 		len = skb->len;
-		mapping = pci_map_single(gp->pdev, skb->data, len, PCI_DMA_TODEVICE);
+		mapping = pci_map_page(gp->pdev,
+				       virt_to_page(skb->data),
+				       ((unsigned long) skb->data &
+					~PAGE_MASK),
+				       len, PCI_DMA_TODEVICE);
 		ctrl |= TXDCTRL_SOF | TXDCTRL_EOF | len;
 		txd->buffer = cpu_to_le64(mapping);
 		txd->control_word = cpu_to_le64(ctrl);
 		entry = NEXT_TX(entry);
 	} else {
 		struct gem_txd *txd;
-		u32 first_len, first_mapping;
+		u32 first_len;
+		dma_addr_t first_mapping;
 		int frag, first_entry = entry;
 
 		/* We must give this initial chunk to the device last.
 		 * Otherwise we could race with the device.
 		 */
 		first_len = skb->len - skb->data_len;
-		first_mapping = pci_map_single(gp->pdev, skb->data,
-					       first_len, PCI_DMA_TODEVICE);
+		first_mapping = pci_map_page(gp->pdev, virt_to_page(skb->data),
+					     ((unsigned long) skb->data & ~PAGE_MASK),
+					     first_len, PCI_DMA_TODEVICE);
 		entry = NEXT_TX(entry);
 
 		for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
 			skb_frag_t *this_frag = &skb_shinfo(skb)->frags[frag];
-			u32 len, mapping;
+			u32 len;
+			dma_addr_t mapping;
 			u64 this_ctrl;
 
 			len = this_frag->size;
-			mapping = pci_map_single(gp->pdev,
-						 ((void *) page_address(this_frag->page) +
-						  this_frag->page_offset),
-						 len, PCI_DMA_TODEVICE);
+			mapping = pci_map_page(gp->pdev,
+					       this_frag->page,
+					       this_frag->page_offset,
+					       len, PCI_DMA_TODEVICE);
 			this_ctrl = ctrl;
 			if (frag == skb_shinfo(skb)->nr_frags - 1)
 				this_ctrl |= TXDCTRL_EOF;
@@ -948,19 +960,18 @@
 	struct gem_init_block *gb = gp->init_block;
 	struct sk_buff *skb;
 	int i;
-	u32 dma_addr;
+	dma_addr_t dma_addr;
 
 	for (i = 0; i < RX_RING_SIZE; i++) {
 		struct gem_rxd *rxd;
 
 		rxd = &gb->rxd[i];
 		if (gp->rx_skbs[i] != NULL) {
-
 			skb = gp->rx_skbs[i];
-			dma_addr = (u32) le64_to_cpu(rxd->buffer);
-			pci_unmap_single(gp->pdev, dma_addr,
-					 RX_BUF_ALLOC_SIZE(gp),
-					 PCI_DMA_FROMDEVICE);
+			dma_addr = le64_to_cpu(rxd->buffer);
+			pci_unmap_page(gp->pdev, dma_addr,
+				       RX_BUF_ALLOC_SIZE(gp),
+				       PCI_DMA_FROMDEVICE);
 			dev_kfree_skb_any(skb);
 			gp->rx_skbs[i] = NULL;
 		}
@@ -978,10 +989,10 @@
 
 			for (frag = 0; frag <= skb_shinfo(skb)->nr_frags; frag++) {
 				txd = &gb->txd[i];
-				dma_addr = (u32) le64_to_cpu(txd->buffer);
-				pci_unmap_single(gp->pdev, dma_addr,
-						 le64_to_cpu(txd->control_word) &
-						 TXDCTRL_BUFSZ, PCI_DMA_TODEVICE);
+				dma_addr = le64_to_cpu(txd->buffer);
+				pci_unmap_page(gp->pdev, dma_addr,
+					       le64_to_cpu(txd->control_word) &
+					       TXDCTRL_BUFSZ, PCI_DMA_TODEVICE);
 
 				if (frag != skb_shinfo(skb)->nr_frags)
 					i++;
@@ -996,7 +1007,7 @@
 	struct gem_init_block *gb = gp->init_block;
 	struct net_device *dev = gp->dev;
 	int i, gfp_flags = GFP_KERNEL;
-	u32 dma_addr;
+	dma_addr_t dma_addr;
 
 	if (from_irq)
 		gfp_flags = GFP_ATOMIC;
@@ -1019,9 +1030,12 @@
 		gp->rx_skbs[i] = skb;
 		skb->dev = dev;
 		skb_put(skb, (ETH_FRAME_LEN + RX_OFFSET));
-		dma_addr = pci_map_single(gp->pdev, skb->data,
-					  RX_BUF_ALLOC_SIZE(gp),
-					  PCI_DMA_FROMDEVICE);
+		dma_addr = pci_map_page(gp->pdev,
+					virt_to_page(skb->data),
+					((unsigned long) skb->data &
+					 ~PAGE_MASK),
+					RX_BUF_ALLOC_SIZE(gp),
+					PCI_DMA_FROMDEVICE);
 		rxd->buffer = cpu_to_le64(dma_addr);
 		rxd->status_word = cpu_to_le64(RXDCTRL_FRESH(gp));
 		skb_reserve(skb, RX_OFFSET);
@@ -1137,13 +1151,15 @@
 
 static void gem_init_dma(struct gem *gp)
 {
+	u64 desc_dma = (u64) gp->gblock_dvma;
 	u32 val;
 
 	val = (TXDMA_CFG_BASE | (0x7ff << 10) | TXDMA_CFG_PMODE);
 	writel(val, gp->regs + TXDMA_CFG);
 
-	writel(0, gp->regs + TXDMA_DBHI);
-	writel(gp->gblock_dvma, gp->regs + TXDMA_DBLOW);
+	writel(desc_dma >> 32, gp->regs + TXDMA_DBHI);
+	writel(desc_dma & 0xffffffff, gp->regs + TXDMA_DBLOW);
+	desc_dma += (TX_RING_SIZE * sizeof(struct gem_txd));
 
 	writel(0, gp->regs + TXDMA_KICK);
 
@@ -1151,10 +1167,8 @@
 	       ((14 / 2) << 13) | RXDMA_CFG_FTHRESH_512);
 	writel(val, gp->regs + RXDMA_CFG);
 
-	writel(0, gp->regs + RXDMA_DBHI);
-	writel((gp->gblock_dvma +
-		(TX_RING_SIZE * sizeof(struct gem_txd))),
-	       gp->regs + RXDMA_DBLOW);
+	writel(desc_dma >> 32, gp->regs + RXDMA_DBHI);
+	writel(desc_dma & 0xffffffff, gp->regs + RXDMA_DBLOW);
 
 	writel(RX_RING_SIZE - 4, gp->regs + RXDMA_KICK);
 
@@ -1562,8 +1576,10 @@
 	}
 
 	{
-		u32 cfg = readl(gp->regs + GREG_BIFCFG);
+		u32 cfg;
 
+		/* XXX Why do I do this? -DaveM XXX */
+		cfg = readl(gp->regs + GREG_BIFCFG);
 		cfg |= GREG_BIFCFG_B64DIS;
 		writel(cfg, gp->regs + GREG_BIFCFG);
 
@@ -1621,7 +1637,7 @@
 	unsigned long gemreg_base, gemreg_len;
 	struct net_device *dev;
 	struct gem *gp;
-	int i, err;
+	int i, err, pci_using_dac;
 
 	if (gem_version_printed++ == 0)
 		printk(KERN_INFO "%s", version);
@@ -1634,6 +1650,29 @@
 	}
 	pci_set_master(pdev);
 
+	/* Configure DMA attributes. */
+
+	/* All of the GEM documentation states that 64-bit DMA addressing
+	 * is fully supported and should work just fine.  However the
+	 * front end for RIO based GEMs is different and only supports
+	 * 32-bit addressing.
+	 *
+	 * For now we assume the various PPC GEMs are 32-bit only as well.
+	 */
+	if (pdev->vendor == PCI_VENDOR_ID_SUN &&
+	    pdev->device == PCI_DEVICE_ID_SUN_GEM &&
+	    !pci_set_dma_mask(pdev, (u64) 0xffffffffffffffff)) {
+		pci_using_dac = 1;
+	} else {
+		err = pci_set_dma_mask(pdev, (u64) 0xffffffff);
+		if (err) {
+			printk(KERN_ERR PFX "No usable DMA configuration, "
+			       "aborting.\n");
+			return err;
+		}
+		pci_using_dac = 0;
+	}
+
 	gemreg_base = pci_resource_start(pdev, 0);
 	gemreg_len = pci_resource_len(pdev, 0);
 
@@ -1717,6 +1756,8 @@
 
 	/* GEM can do it all... */
 	dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
+	if (pci_using_dac)
+		dev->features |= NETIF_F_HIGHDMA;
 
 	return 0;
 
diff -urN linux-2.4.13-pre1/drivers/net/sunhme.c linux/drivers/net/sunhme.c
--- linux-2.4.13-pre1/drivers/net/sunhme.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/net/sunhme.c	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: sunhme.c,v 1.122 2001/08/13 14:40:07 davem Exp $
+/* $Id: sunhme.c,v 1.123 2001/10/02 02:22:30 davem Exp $
  * sunhme.c: Sparc HME/BigMac 10/100baseT half/full duplex auto switching,
  *           auto carrier detecting ethernet driver.  Also known as the
  *           "Happy Meal Ethernet" found on SunSwift SBUS cards.
diff -urN linux-2.4.13-pre1/drivers/net/wavelan.c linux/drivers/net/wavelan.c
--- linux-2.4.13-pre1/drivers/net/wavelan.c	Sun Sep 30 12:26:08 2001
+++ linux/drivers/net/wavelan.c	Mon Dec  3 23:17:33 2001
@@ -2059,6 +2059,10 @@
 			range.max_qual.qual = MMR_SGNL_QUAL;
 			range.max_qual.level = MMR_SIGNAL_LVL;
 			range.max_qual.noise = MMR_SILENCE_LVL;
+			range.avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
+			/* Need to get better values for those two */
+			range.avg_qual.level = 30;
+			range.avg_qual.noise = 8;
 
 			range.num_bitrates = 1;
 			range.bitrate[0] = 2000000;	/* 2 Mb/s */
diff -urN linux-2.4.13-pre1/drivers/net/wavelan.p.h linux/drivers/net/wavelan.p.h
--- linux-2.4.13-pre1/drivers/net/wavelan.p.h	Mon Jul  2 14:03:04 2001
+++ linux/drivers/net/wavelan.p.h	Mon Dec  3 23:17:33 2001
@@ -447,13 +447,13 @@
 
 /* ------------------------ PRIVATE IOCTL ------------------------ */
 
-#define SIOCSIPQTHR	SIOCDEVPRIVATE		/* Set quality threshold */
-#define SIOCGIPQTHR	SIOCDEVPRIVATE + 1	/* Get quality threshold */
-#define SIOCSIPLTHR	SIOCDEVPRIVATE + 2	/* Set level threshold */
-#define SIOCGIPLTHR	SIOCDEVPRIVATE + 3	/* Get level threshold */
+#define SIOCSIPQTHR	SIOCIWFIRSTPRIV		/* Set quality threshold */
+#define SIOCGIPQTHR	SIOCIWFIRSTPRIV + 1	/* Get quality threshold */
+#define SIOCSIPLTHR	SIOCIWFIRSTPRIV + 2	/* Set level threshold */
+#define SIOCGIPLTHR	SIOCIWFIRSTPRIV + 3	/* Get level threshold */
 
-#define SIOCSIPHISTO	SIOCDEVPRIVATE + 6	/* Set histogram ranges */
-#define SIOCGIPHISTO	SIOCDEVPRIVATE + 7	/* Get histogram values */
+#define SIOCSIPHISTO	SIOCIWFIRSTPRIV + 6	/* Set histogram ranges */
+#define SIOCGIPHISTO	SIOCIWFIRSTPRIV + 7	/* Get histogram values */
 
 /****************************** TYPES ******************************/
 
diff -urN linux-2.4.13-pre1/drivers/pci/pci.c linux/drivers/pci/pci.c
--- linux-2.4.13-pre1/drivers/pci/pci.c	Mon Sep 17 22:52:35 2001
+++ linux/drivers/pci/pci.c	Mon Dec  3 23:17:33 2001
@@ -834,17 +834,27 @@
 }
 
 int
-pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask)
+pci_set_dma_mask(struct pci_dev *dev, u64 mask)
 {
-    if(! pci_dma_supported(dev, mask))
-        return -EIO;
+	if (!pci_dma_supported(dev, mask))
+		return -EIO;
 
-    dev->dma_mask = mask;
+	dev->dma_mask = mask;
 
-    return 0;
+	return 0;
 }
     
+int
+pci_dac_set_dma_mask(struct pci_dev *dev, u64 mask)
+{
+	if (!pci_dac_dma_supported(dev, mask))
+		return -EIO;
+
+	dev->dma_mask = mask;
 
+	return 0;
+}
+    
 /*
  * Translate the low bits of the PCI base
  * to the resource type
@@ -1678,7 +1688,8 @@
 	if (!page)
 		return 0;
 	page->vaddr = pci_alloc_consistent (pool->dev,
-				pool->allocation, &page->dma);
+					    pool->allocation,
+					    &page->dma);
 	if (page->vaddr) {
 		memset (page->bitmap, 0xff, mapsize);	// bit set == free
 		if (pool->flags & SLAB_POISON)
@@ -1864,14 +1875,14 @@
 	if ((page = pool_find_page (pool, dma)) == 0) {
 		printk (KERN_ERR "pci_pool_free %s/%s, %p/%x (bad dma)\n",
 			pool->dev ? pool->dev->slot_name : NULL,
-			pool->name, vaddr, dma);
+			pool->name, vaddr, (int) (dma & 0xffffffff));
 		return;
 	}
 #ifdef	CONFIG_PCIPOOL_DEBUG
 	if (((dma - page->dma) + (void *)page->vaddr) != vaddr) {
 		printk (KERN_ERR "pci_pool_free %s/%s, %p (bad vaddr)/%x\n",
 			pool->dev ? pool->dev->slot_name : NULL,
-			pool->name, vaddr, dma);
+			pool->name, vaddr, (int) (dma & 0xffffffff));
 		return;
 	}
 #endif
@@ -1956,6 +1967,7 @@
 EXPORT_SYMBOL(pci_find_subsys);
 EXPORT_SYMBOL(pci_set_master);
 EXPORT_SYMBOL(pci_set_dma_mask);
+EXPORT_SYMBOL(pci_dac_set_dma_mask);
 EXPORT_SYMBOL(pci_assign_resource);
 EXPORT_SYMBOL(pci_register_driver);
 EXPORT_SYMBOL(pci_unregister_driver);
diff -urN linux-2.4.13-pre1/drivers/scsi/aha1542.c linux/drivers/scsi/aha1542.c
--- linux-2.4.13-pre1/drivers/scsi/aha1542.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/scsi/aha1542.c	Mon Dec  3 23:17:33 2001
@@ -67,12 +67,10 @@
 		       int nseg,
 		       int badseg)
 {
-	printk(KERN_CRIT "sgpnt[%d:%d] addr %p/0x%lx alt %p/0x%lx length %d\n",
+	printk(KERN_CRIT "sgpnt[%d:%d] addr %p/0x%lx length %d\n",
 	       badseg, nseg,
 	       sgpnt[badseg].address,
 	       SCSI_PA(sgpnt[badseg].address),
-	       sgpnt[badseg].alt_address,
-	       sgpnt[badseg].alt_address ? SCSI_PA(sgpnt[badseg].alt_address) : 0,
 	       sgpnt[badseg].length);
 
 	/*
@@ -716,7 +714,7 @@
 				unsigned char *ptr;
 				printk(KERN_CRIT "Bad segment list supplied to aha1542.c (%d, %d)\n", SCpnt->use_sg, i);
 				for (i = 0; i < SCpnt->use_sg; i++) {
-					printk(KERN_CRIT "%d: %x %x %d\n", i, (unsigned int) sgpnt[i].address, (unsigned int) sgpnt[i].alt_address,
+					printk(KERN_CRIT "%d: %p %d\n", i, sgpnt[i].address,
 					       sgpnt[i].length);
 				};
 				printk(KERN_CRIT "cptr %x: ", (unsigned int) cptr);
diff -urN linux-2.4.13-pre1/drivers/scsi/osst.c linux/drivers/scsi/osst.c
--- linux-2.4.13-pre1/drivers/scsi/osst.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/scsi/osst.c	Mon Dec  3 23:17:33 2001
@@ -4935,7 +4935,6 @@
 			tb->sg[0].address =
 			    (unsigned char *)__get_free_pages(priority, order);
 			if (tb->sg[0].address != NULL) {
-			    tb->sg[0].alt_address = NULL;
 			    tb->sg[0].length = b_size;
 			    break;
 			}
@@ -4971,7 +4970,6 @@
 				tb = NULL;
 				break;
 			    }
-			    tb->sg[segs].alt_address = NULL;
 			    tb->sg[segs].length = b_size;
 			    got += b_size;
 			    segs++;
@@ -5045,7 +5043,6 @@
 			normalize_buffer(STbuffer);
 			return FALSE;
 		}
-		STbuffer->sg[segs].alt_address = NULL;
 		STbuffer->sg[segs].length = b_size;
 		STbuffer->sg_segs += 1;
 		got += b_size;
diff -urN linux-2.4.13-pre1/drivers/scsi/qlogicfc.c linux/drivers/scsi/qlogicfc.c
--- linux-2.4.13-pre1/drivers/scsi/qlogicfc.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/scsi/qlogicfc.c	Mon Dec  3 23:17:33 2001
@@ -21,6 +21,9 @@
  *
  * Big endian support and dynamic DMA mapping added
  * by Jakub Jelinek <jakub@redhat.com>.
+ *
+ * Conversion to final pci64 DMA interfaces
+ * by David S. Miller <davem@redhat.com>.
  */
 
 /*
@@ -63,31 +66,10 @@
 #include "sd.h"
 #include "hosts.h"
 
-#if 1
-/* Once pci64_ DMA mapping interface is in, kill this. */
-typedef dma_addr_t dma64_addr_t;
-#define pci64_alloc_consistent(d,s,p) pci_alloc_consistent((d),(s),(p))
-#define pci64_free_consistent(d,s,c,a) pci_free_consistent((d),(s),(c),(a))
-#define pci64_map_single(d,c,s,dir) pci_map_single((d),(c),(s),(dir))
-#define pci64_map_sg(d,s,n,dir) pci_map_sg((d),(s),(n),(dir))
-#define pci64_unmap_single(d,a,s,dir) pci_unmap_single((d),(a),(s),(dir))
-#define pci64_unmap_sg(d,s,n,dir) pci_unmap_sg((d),(s),(n),(dir))
-#if BITS_PER_LONG > 32
 #define pci64_dma_hi32(a) ((u32) (0xffffffff & (((u64)(a))>>32)))
 #define pci64_dma_lo32(a) ((u32) (0xffffffff & (((u64)(a)))))
-#else
-#define pci64_dma_hi32(a) 0
-#define pci64_dma_lo32(a) (a)
-#endif	/* BITS_PER_LONG */
-#define pci64_dma_build(hi,lo) (lo)
-#define sg_dma64_address(s) sg_dma_address(s)
-#define sg_dma64_len(s) sg_dma_len(s)
-#if BITS_PER_LONG > 32
-#define PCI64_DMA_BITS 64
-#else
-#define PCI64_DMA_BITS	32
-#endif 	/* BITS_PER_LONG */
-#endif
+#define pci64_dma_build(hi,lo) \
+	((dma_addr_t)(((u64)(lo))|(((u64)(hi))<<32)))
 
 #include "qlogicfc.h"
 
@@ -243,13 +225,8 @@
 };
 
 /* entry header type commands */
-#if PCI64_DMA_BITS > 32
 #define ENTRY_COMMAND		0x19
 #define ENTRY_CONTINUATION	0x0a
-#else
-#define ENTRY_COMMAND		0x11
-#define ENTRY_CONTINUATION	0x02
-#endif
 
 #define ENTRY_STATUS		0x03
 #define ENTRY_MARKER		0x04
@@ -260,23 +237,12 @@
 #define EFLAG_BAD_HEADER	4
 #define EFLAG_BAD_PAYLOAD	8
 
-#if PCI64_DMA_BITS > 32
-
 struct dataseg {
 	u_int d_base;
 	u_int d_base_hi;
 	u_int d_count;
 };
 
-#else
-
-struct dataseg {
-	u_int d_base;
-	u_int d_count;
-};
-
-#endif
-
 struct Command_Entry {
 	struct Entry_header hdr;
 	u_int handle;
@@ -301,18 +267,10 @@
 #define CFLAG_READ		0x20
 #define CFLAG_WRITE		0x40
 
-#if PCI64_DMA_BITS > 32
-struct Continuation_Entry {
-	struct Entry_header hdr;
-	struct dataseg dataseg[DATASEGS_PER_CONT];
-};
-#else
 struct Continuation_Entry {
 	struct Entry_header hdr;
-        u32 rsvd;
 	struct dataseg dataseg[DATASEGS_PER_CONT];
 };
-#endif
 
 struct Marker_Entry {
 	struct Entry_header hdr;
@@ -741,7 +699,7 @@
 	struct isp2x00_hostdata *hostdata;
 	struct pci_dev *pdev;
 	unsigned short device_ids[2];
-	dma64_addr_t busaddr;
+	dma_addr_t busaddr;
 	int i;
 
 
@@ -753,7 +711,7 @@
 	tmpt->proc_name = "isp2x00";
 
 	if (pci_present() == 0) {
-		printk("qlogicfc : PCI not present\n");
+		printk(KERN_INFO "qlogicfc : PCI not present\n");
 		return 0;
 	}
 
@@ -763,6 +721,11 @@
 			if (pci_enable_device(pdev))
 				continue;
 
+			/* Try to configure DMA attributes. */
+			if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffff) &&
+			    pci_set_dma_mask(pdev, (u64) 0xffffffff))
+					continue;
+
 		        host = scsi_register(tmpt, sizeof(struct isp2x00_hostdata));
 			if (!host) {
 			        printk("qlogicfc%d : could not register host.\n", hosts);
@@ -776,11 +739,11 @@
 
 			memset(hostdata, 0, sizeof(struct isp2x00_hostdata));
 			hostdata->pci_dev = pdev;
-			hostdata->res = pci64_alloc_consistent(pdev, RES_SIZE + REQ_SIZE, &busaddr);
+			hostdata->res = pci_alloc_consistent(pdev, RES_SIZE + REQ_SIZE, &busaddr);
 
 			if (!hostdata->res){
 			        printk("qlogicfc%d : could not allocate memory for request and response queue.\n", hosts);
-				pci64_free_consistent(pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
+				pci_free_consistent(pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
 			        scsi_unregister(host);
 				continue;
 			}
@@ -813,7 +776,7 @@
 			hostdata->host_id = hosts;
 
 			if (isp2x00_init(host) || isp2x00_reset_hardware(host)) {
-				pci64_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
+				pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
 			        scsi_unregister(host);
 				continue;
 			}
@@ -822,7 +785,7 @@
 			if (request_irq(host->irq, do_isp2x00_intr_handler, SA_INTERRUPT | SA_SHIRQ, "qlogicfc", host)) {
 			        printk("qlogicfc%d : interrupt %d already in use\n",
 				       hostdata->host_id, host->irq);
-				pci64_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
+				pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
 				scsi_unregister(host);
 				continue;
 			}
@@ -831,7 +794,7 @@
 				       "in use\n",
 				       hostdata->host_id, host->io_port, host->io_port + 0xff);
 				free_irq(host->irq, host);
-				pci64_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
+				pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
 				scsi_unregister(host);
 				continue;
 			}
@@ -990,7 +953,7 @@
 	u_int port_id;
 	struct sns_cb *req;
 	u_char *sns_response;
-	dma64_addr_t busaddr;
+	dma_addr_t busaddr;
 	struct isp2x00_hostdata *hostdata;
 
 	hostdata = (struct isp2x00_hostdata *) host->hostdata;
@@ -1007,7 +970,7 @@
 	}
 	printk("qlogicfc%d : Fabric found.\n", hostdata->host_id);
 
-	req = (struct sns_cb *)pci64_alloc_consistent(hostdata->pci_dev, sizeof(*req) + 608, &busaddr);
+	req = (struct sns_cb *)pci_alloc_consistent(hostdata->pci_dev, sizeof(*req) + 608, &busaddr);
 	
 	if (!req){
 		printk("qlogicfc%d : Could not allocate DMA resources for fabric initialization\n", hostdata->host_id);
@@ -1109,12 +1072,12 @@
 				done = 1;
 		} else {
 			printk("qlogicfc%d : Get All Next failed %x.\n", hostdata->host_id, param[0]);
-			pci64_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
+			pci_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
 			return 0;
 		}
 	}
 
-	pci64_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
+	pci_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
 	return 1;
 }
 
@@ -1124,7 +1087,7 @@
 int isp2x00_release(struct Scsi_Host *host)
 {
 	struct isp2x00_hostdata *hostdata;
-	dma64_addr_t busaddr;
+	dma_addr_t busaddr;
 
 	ENTER("isp2x00_release");
 
@@ -1137,7 +1100,7 @@
 
 	busaddr = pci64_dma_build(le32_to_cpu(hostdata->control_block.res_queue_addr_high),
 				  le32_to_cpu(hostdata->control_block.res_queue_addr_lo));
-	pci64_free_consistent(hostdata->pci_dev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
+	pci_free_consistent(hostdata->pci_dev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
 
 	LEAVE("isp2x00_release");
 
@@ -1281,7 +1244,7 @@
 
 	if (Cmnd->use_sg) {
 		sg = (struct scatterlist *) Cmnd->request_buffer;
-		sg_count = pci64_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg, scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+		sg_count = pci_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg, scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
 		cmd->segment_cnt = cpu_to_le16(sg_count);
 		ds = cmd->dataseg;
 		/* fill in first two sg entries: */
@@ -1290,11 +1253,9 @@
 			n = DATASEGS_PER_COMMAND;
 
 		for (i = 0; i < n; i++) {
-			ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma64_address(sg)));
-#if PCI64_DMA_BITS > 32
-			ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma64_address(sg)));
-#endif
-			ds[i].d_count = cpu_to_le32(sg_dma64_len(sg));
+			ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));
+			ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));
+			ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
 			++sg;
 		}
 		sg_count -= DATASEGS_PER_COMMAND;
@@ -1316,31 +1277,30 @@
 			if (n > DATASEGS_PER_CONT)
 				n = DATASEGS_PER_CONT;
 			for (i = 0; i < n; ++i) {
-				ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma64_address(sg)));
-#if PCI64_DMA_BITS > 32
-				ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma64_address(sg)));
-#endif
-				ds[i].d_count = cpu_to_le32(sg_dma64_len(sg));
+				ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));
+				ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));
+				ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
 				++sg;
 			}
 			sg_count -= n;
 		}
 	} else if (Cmnd->request_bufflen && Cmnd->sc_data_direction != PCI_DMA_NONE) {
-		dma64_addr_t busaddr = pci64_map_single(hostdata->pci_dev, Cmnd->request_buffer, Cmnd->request_bufflen,
-							scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+		struct page *page = virt_to_page(Cmnd->request_buffer);
+		unsigned long offset = ((unsigned long)Cmnd->request_buffer &
+					~PAGE_MASK);
+		dma_addr_t busaddr = pci_map_page(hostdata->pci_dev,
+						  page, offset,
+						  Cmnd->request_bufflen,
+						  scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+		Cmnd->SCp.dma_handle = busaddr;
 
-		*(dma64_addr_t *)&Cmnd->SCp = busaddr;
 		cmd->dataseg[0].d_base = cpu_to_le32(pci64_dma_lo32(busaddr));
-#if PCI64_DMA_BITS > 32
 		cmd->dataseg[0].d_base_hi = cpu_to_le32(pci64_dma_hi32(busaddr));
-#endif
 		cmd->dataseg[0].d_count = cpu_to_le32(Cmnd->request_bufflen);
 		cmd->segment_cnt = cpu_to_le16(1);
 	} else {
 		cmd->dataseg[0].d_base = 0;
-#if PCI64_DMA_BITS > 32
 		cmd->dataseg[0].d_base_hi = 0;
-#endif
 		cmd->segment_cnt = cpu_to_le16(1); /* Shouldn't this be 0? */
 	}
 
@@ -1433,16 +1393,17 @@
 					Scsi_Cmnd *Cmnd = hostdata->handle_ptrs[i];
 
 					 if (Cmnd->use_sg)
-						 pci64_unmap_sg(hostdata->pci_dev,
-								(struct scatterlist *)Cmnd->buffer,
-								Cmnd->use_sg,
-								scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+						 pci_unmap_sg(hostdata->pci_dev,
+							      (struct scatterlist *)Cmnd->buffer,
+							      Cmnd->use_sg,
+							      scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
 					 else if (Cmnd->request_bufflen &&
-						  Cmnd->sc_data_direction != PCI_DMA_NONE)
-						 pci64_unmap_single(hostdata->pci_dev,
-								    *(dma64_addr_t *)&Cmnd->SCp,
-								    Cmnd->request_bufflen,
-								    scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+						  Cmnd->sc_data_direction != PCI_DMA_NONE) {
+						 pci_unmap_page(hostdata->pci_dev,
+								Cmnd->SCp.dma_handle,
+								Cmnd->request_bufflen,
+								scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+					 }
 
 					 hostdata->handle_ptrs[i]->result = DID_SOFT_ERROR << 16;
 
@@ -1539,16 +1500,16 @@
 			hostdata->queued--;
 			if (Cmnd != NULL) {
 				if (Cmnd->use_sg)
-					pci64_unmap_sg(hostdata->pci_dev,
-						       (struct scatterlist *)Cmnd->buffer,
-						       Cmnd->use_sg,
-						       scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+					pci_unmap_sg(hostdata->pci_dev,
+						     (struct scatterlist *)Cmnd->buffer,
+						     Cmnd->use_sg,
+						     scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
 				else if (Cmnd->request_bufflen &&
 					 Cmnd->sc_data_direction != PCI_DMA_NONE)
-					pci64_unmap_single(hostdata->pci_dev,
-							   *(dma64_addr_t *)&Cmnd->SCp,
-							   Cmnd->request_bufflen,
-							   scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+					pci_unmap_page(hostdata->pci_dev,
+						       Cmnd->SCp.dma_handle,
+						       Cmnd->request_bufflen,
+						       scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
 				Cmnd->result = 0x0;
 				(*Cmnd->scsi_done) (Cmnd);
 			} else
@@ -1594,13 +1555,14 @@
 				hostdata->queued--;
 
 				if (Cmnd->use_sg)
-					pci64_unmap_sg(hostdata->pci_dev,
-						       (struct scatterlist *)Cmnd->buffer, Cmnd->use_sg,
-						       scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+					pci_unmap_sg(hostdata->pci_dev,
+						     (struct scatterlist *)Cmnd->buffer, Cmnd->use_sg,
+						     scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
 				else if (Cmnd->request_bufflen && Cmnd->sc_data_direction != PCI_DMA_NONE)
-					pci64_unmap_single(hostdata->pci_dev, *(dma64_addr_t *)&Cmnd->SCp,
-							   Cmnd->request_bufflen,
-							   scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
+					pci_unmap_page(hostdata->pci_dev,
+						       Cmnd->SCp.dma_handle,
+						       Cmnd->request_bufflen,
+						       scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
 
 				/* 
 				 * if any of the following are true we do not
@@ -1859,7 +1821,7 @@
 	u_short param[8];
 	struct isp2x00_hostdata *hostdata;
 	int loop_count;
-	dma64_addr_t busaddr;
+	dma_addr_t busaddr;
 
 	ENTER("isp2x00_reset_hardware");
 
@@ -1970,9 +1932,15 @@
 	hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[3]) & 0x00ff) << 8;
 	hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[3]) & 0xff00) >> 8;
 
-	/* FIXME: If the DMA transfer goes one way only, this should use PCI_DMA_TODEVICE and below as well. */
-	busaddr = pci64_map_single(hostdata->pci_dev, &hostdata->control_block, sizeof(hostdata->control_block),
-				   PCI_DMA_BIDIRECTIONAL);
+	/* FIXME: If the DMA transfer goes one way only, this should use
+	 *        PCI_DMA_TODEVICE and below as well.
+	 */
+	busaddr = pci_map_page(hostdata->pci_dev,
+			       virt_to_page(&hostdata->control_block),
+			       ((unsigned long) &hostdata->control_block &
+				~PAGE_MASK),
+			       sizeof(hostdata->control_block),
+			       PCI_DMA_BIDIRECTIONAL);
 
 	param[0] = MBOX_INIT_FIRMWARE;
 	param[2] = (u_short) (pci64_dma_lo32(busaddr) >> 16);
@@ -1984,21 +1952,24 @@
 	isp2x00_mbox_command(host, param);
 	if (param[0] != MBOX_COMMAND_COMPLETE) {
 		printk("qlogicfc%d.c: Ouch 0x%04x\n", hostdata->host_id,  param[0]);
-		pci64_unmap_single(hostdata->pci_dev, busaddr, sizeof(hostdata->control_block),
-				   PCI_DMA_BIDIRECTIONAL);
+		pci_unmap_page(hostdata->pci_dev, busaddr,
+			       sizeof(hostdata->control_block),
+			       PCI_DMA_BIDIRECTIONAL);
 		return 1;
 	}
 	param[0] = MBOX_GET_FIRMWARE_STATE;
 	isp2x00_mbox_command(host, param);
 	if (param[0] != MBOX_COMMAND_COMPLETE) {
 		printk("qlogicfc%d.c: 0x%04x\n", hostdata->host_id,  param[0]);
-		pci64_unmap_single(hostdata->pci_dev, busaddr, sizeof(hostdata->control_block),
-				   PCI_DMA_BIDIRECTIONAL);
+		pci_unmap_page(hostdata->pci_dev, busaddr,
+			       sizeof(hostdata->control_block),
+			       PCI_DMA_BIDIRECTIONAL);
 		return 1;
 	}
 
-	pci64_unmap_single(hostdata->pci_dev, busaddr, sizeof(hostdata->control_block),
-			   PCI_DMA_BIDIRECTIONAL);
+	pci_unmap_page(hostdata->pci_dev, busaddr,
+		       sizeof(hostdata->control_block),
+		       PCI_DMA_BIDIRECTIONAL);
 	LEAVE("isp2x00_reset_hardware");
 
 	return 0;
diff -urN linux-2.4.13-pre1/drivers/scsi/scsi.h linux/drivers/scsi/scsi.h
--- linux-2.4.13-pre1/drivers/scsi/scsi.h	Wed Oct 10 23:47:24 2001
+++ linux/drivers/scsi/scsi.h	Mon Dec  3 23:17:33 2001
@@ -633,6 +633,8 @@
 	struct scatterlist *buffer;	/* which buffer */
 	int buffers_residual;	/* how many buffers left */
 
+        dma_addr_t dma_handle;
+
 	volatile int Status;
 	volatile int Message;
 	volatile int have_data_in;
@@ -745,7 +747,8 @@
 	unsigned request_bufflen;	/* Actual request size */
 
 	struct timer_list eh_timeout;	/* Used to time out the command. */
-	void *request_buffer;	/* Actual requested buffer */
+	void *request_buffer;		/* Actual requested buffer */
+        void **bounce_buffers;		/* Array of bounce buffers when using scatter-gather */
 
 	/* These elements define the operation we ultimately want to perform */
 	unsigned char data_cmnd[MAX_COMMAND_SIZE];
diff -urN linux-2.4.13-pre1/drivers/scsi/scsi_debug.c linux/drivers/scsi/scsi_debug.c
--- linux-2.4.13-pre1/drivers/scsi/scsi_debug.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/scsi/scsi_debug.c	Mon Dec  3 23:17:33 2001
@@ -154,10 +154,7 @@
 	if (SCpnt->use_sg) {
 		sgpnt = (struct scatterlist *) SCpnt->buffer;
 		for (i = 0; i < SCpnt->use_sg; i++) {
-			lpnt = (int *) sgpnt[i].alt_address;
-			printk(":%p %p %d\n", sgpnt[i].alt_address, sgpnt[i].address, sgpnt[i].length);
-			if (lpnt)
-				printk(" (Alt %x) ", lpnt[15]);
+			printk(":%p %d\n", sgpnt[i].address, sgpnt[i].length);
 		};
 	} else {
 		printk("nosg: %p %p %d\n", SCpnt->request.buffer, SCpnt->buffer,
@@ -175,12 +172,6 @@
 	printk("\n");
 	if (flag == 0)
 		return;
-	lpnt = (unsigned int *) sgpnt[0].alt_address;
-	for (i = 0; i < sizeof(Scsi_Cmnd) / 4 + 1; i++) {
-		if ((i & 7) == 0)
-			printk("\n");
-		printk("%x ", *lpnt++);
-	};
 #if 0
 	printk("\n");
 	lpnt = (unsigned int *) sgpnt[0].address;
diff -urN linux-2.4.13-pre1/drivers/scsi/scsi_lib.c linux/drivers/scsi/scsi_lib.c
--- linux-2.4.13-pre1/drivers/scsi/scsi_lib.c	Sun Aug 12 10:51:42 2001
+++ linux/drivers/scsi/scsi_lib.c	Mon Dec  3 23:17:33 2001
@@ -496,13 +496,16 @@
 	 */
 	if (SCpnt->use_sg) {
 		struct scatterlist *sgpnt;
+		void **bbpnt;
 		int i;
 
 		sgpnt = (struct scatterlist *) SCpnt->request_buffer;
+		bbpnt = SCpnt->bounce_buffers;
 
-		for (i = 0; i < SCpnt->use_sg; i++) {
-			if (sgpnt[i].alt_address) {
-				scsi_free(sgpnt[i].address, sgpnt[i].length);
+		if (bbpnt) {
+			for (i = 0; i < SCpnt->use_sg; i++) {
+				if (bbpnt[i])
+					scsi_free(sgpnt[i].address, sgpnt[i].length);
 			}
 		}
 		scsi_free(SCpnt->request_buffer, SCpnt->sglist_len);
@@ -568,18 +571,22 @@
 	 */
 	if (SCpnt->use_sg) {
 		struct scatterlist *sgpnt;
+		void **bbpnt;
 		int i;
 
 		sgpnt = (struct scatterlist *) SCpnt->buffer;
+		bbpnt = SCpnt->bounce_buffers;
 
-		for (i = 0; i < SCpnt->use_sg; i++) {
-			if (sgpnt[i].alt_address) {
-				if (SCpnt->request.cmd == READ) {
-					memcpy(sgpnt[i].alt_address, 
-					       sgpnt[i].address,
-					       sgpnt[i].length);
+		if (bbpnt) {
+			for (i = 0; i < SCpnt->use_sg; i++) {
+				if (bbpnt[i]) {
+					if (SCpnt->request.cmd == READ) {
+						memcpy(bbpnt[i],
+						       sgpnt[i].address,
+						       sgpnt[i].length);
+					}
+					scsi_free(sgpnt[i].address, sgpnt[i].length);
 				}
-				scsi_free(sgpnt[i].address, sgpnt[i].length);
 			}
 		}
 		scsi_free(SCpnt->buffer, SCpnt->sglist_len);
diff -urN linux-2.4.13-pre1/drivers/scsi/scsi_merge.c linux/drivers/scsi/scsi_merge.c
--- linux-2.4.13-pre1/drivers/scsi/scsi_merge.c	Thu Jul  5 11:28:17 2001
+++ linux/drivers/scsi/scsi_merge.c	Mon Dec  3 23:17:33 2001
@@ -120,9 +120,11 @@
 {
 	int jj;
 	struct scatterlist *sgpnt;
+	void **bbpnt;
 	int consumed = 0;
 
 	sgpnt = (struct scatterlist *) SCpnt->request_buffer;
+	bbpnt = SCpnt->bounce_buffers;
 
 	/*
 	 * Now print out a bunch of stats.  First, start with the request
@@ -136,15 +138,13 @@
 	 */
 	for(jj=0; jj < SCpnt->use_sg; jj++)
 	{
-		printk("[%d]\tlen:%d\taddr:%p\talt:%p\n",
+		printk("[%d]\tlen:%d\taddr:%p\tbounce:%p\n",
 		       jj,
 		       sgpnt[jj].length,
 		       sgpnt[jj].address,
-		       sgpnt[jj].alt_address);		       
-		if( sgpnt[jj].alt_address != NULL )
-		{
-			consumed = (sgpnt[jj].length >> 9);
-		}
+		       (bbpnt ? bbpnt[jj] : NULL));
+		if (bbpnt && bbpnt[jj])
+			consumed += sgpnt[jj].length;
 	}
 	printk("Total %d sectors consumed\n", consumed);
 	panic("DMA pool exhausted");
@@ -807,6 +807,7 @@
 	int		     sectors;
 	struct scatterlist * sgpnt;
 	int		     this_count;
+	void		   ** bbpnt;
 
 	/*
 	 * FIXME(eric) - don't inline this - it doesn't depend on the
@@ -861,10 +862,19 @@
 
 	/* 
 	 * Allocate the actual scatter-gather table itself.
-	 * scsi_malloc can only allocate in chunks of 512 bytes 
 	 */
-	SCpnt->sglist_len = (SCpnt->use_sg
-			     * sizeof(struct scatterlist) + 511) & ~511;
+	SCpnt->sglist_len = (SCpnt->use_sg * sizeof(struct scatterlist));
+
+	/* If we could potentially require ISA bounce buffers, allocate
+	 * space for this array here.
+	 */
+	if (dma_host)
+		SCpnt->sglist_len += (SCpnt->use_sg * sizeof(void *));
+
+	/* scsi_malloc can only allocate in chunks of 512 bytes so
+	 * round it up.
+	 */
+	SCpnt->sglist_len = (SCpnt->sglist_len + 511) & ~511;
 
 	sgpnt = (struct scatterlist *) scsi_malloc(SCpnt->sglist_len);
 
@@ -889,6 +899,14 @@
 	SCpnt->request_bufflen = 0;
 	bhprev = NULL;
 
+	if (dma_host)
+		bbpnt = (void **) ((char *)sgpnt +
+			 (SCpnt->use_sg * sizeof(struct scatterlist)));
+	else
+		bbpnt = NULL;
+
+	SCpnt->bounce_buffers = bbpnt;
+
 	for (count = 0, bh = SCpnt->request.bh;
 	     bh; bh = bh->b_reqnext) {
 		if (use_clustering && bhprev != NULL) {
@@ -956,7 +974,7 @@
 			if( scsi_dma_free_sectors - sectors <= 10  ) {
 				/*
 				 * If this would nearly drain the DMA
-				 * pool, mpty, then let's stop here.
+				 * pool empty, then let's stop here.
 				 * Don't make this request any larger.
 				 * This is kind of a safety valve that
 				 * we use - we could get screwed later
@@ -970,7 +988,7 @@
 				break;
 			}
 
-			sgpnt[i].alt_address = sgpnt[i].address;
+			bbpnt[i] = sgpnt[i].address;
 			sgpnt[i].address =
 			    (char *) scsi_malloc(sgpnt[i].length);
 			/*
@@ -987,7 +1005,7 @@
 				break;
 			}
 			if (SCpnt->request.cmd == WRITE) {
-				memcpy(sgpnt[i].address, sgpnt[i].alt_address,
+				memcpy(sgpnt[i].address, bbpnt[i],
 				       sgpnt[i].length);
 			}
 		}
diff -urN linux-2.4.13-pre1/drivers/scsi/sr.c linux/drivers/scsi/sr.c
--- linux-2.4.13-pre1/drivers/scsi/sr.c	Sun Sep 30 12:26:07 2001
+++ linux/drivers/scsi/sr.c	Mon Dec  3 23:17:33 2001
@@ -264,6 +264,7 @@
 	struct scatterlist *sg, *old_sg = NULL;
 	int i, fsize, bsize, sg_ent, sg_count;
 	char *front, *back;
+	void **bbpnt, **old_bbpnt = NULL;
 
 	back = front = NULL;
 	sg_ent = SCpnt->use_sg;
@@ -291,17 +292,25 @@
 	 * extend or allocate new scatter-gather table
 	 */
 	sg_count = SCpnt->use_sg;
-	if (sg_count)
+	if (sg_count) {
 		old_sg = (struct scatterlist *) SCpnt->request_buffer;
-	else {
+		old_bbpnt = SCpnt->bounce_buffers;
+	} else {
 		sg_count = 1;
 		sg_ent++;
 	}
 
-	i = ((sg_ent * sizeof(struct scatterlist)) + 511) & ~511;
+	/* Get space for scatterlist and bounce buffer array. */
+	i  = sg_ent * sizeof(struct scatterlist);
+	i += sg_ent * sizeof(void *);
+	i  = (i + 511) & ~511;
+
 	if ((sg = scsi_malloc(i)) == NULL)
 		goto no_mem;
 
+	bbpnt = (void **)
+		((char *)sg + (sg_ent * sizeof(struct scatterlist)));
+
 	/*
 	 * no more failing memory allocs possible, we can safely assign
 	 * SCpnt values now
@@ -312,13 +321,15 @@
 
 	i = 0;
 	if (fsize) {
-		sg[0].address = sg[0].alt_address = front;
+		sg[0].address = bbpnt[0] = front;
 		sg[0].length = fsize;
 		i++;
 	}
 	if (old_sg) {
 		memcpy(sg + i, old_sg, SCpnt->use_sg * sizeof(struct scatterlist));
-		scsi_free(old_sg, ((SCpnt->use_sg * sizeof(struct scatterlist)) + 511) & ~511);
+		memcpy(bbpnt + i, old_bbpnt, SCpnt->use_sg * sizeof(void *));
+		scsi_free(old_sg, (((SCpnt->use_sg * sizeof(struct scatterlist)) +
+				    (SCpnt->use_sg * sizeof(void *))) + 511) & ~511);
 	} else {
 		sg[i].address = SCpnt->request_buffer;
 		sg[i].length = SCpnt->request_bufflen;
@@ -326,11 +337,12 @@
 
 	SCpnt->request_bufflen += (fsize + bsize);
 	SCpnt->request_buffer = sg;
+	SCpnt->bounce_buffers = bbpnt;
 	SCpnt->use_sg += i;
 
 	if (bsize) {
 		sg[SCpnt->use_sg].address = back;
-		sg[SCpnt->use_sg].alt_address = back;
+		bbpnt[SCpnt->use_sg] = back;
 		sg[SCpnt->use_sg].length = bsize;
 		SCpnt->use_sg++;
 	}
diff -urN linux-2.4.13-pre1/drivers/scsi/st.c linux/drivers/scsi/st.c
--- linux-2.4.13-pre1/drivers/scsi/st.c	Wed Oct  3 14:28:50 2001
+++ linux/drivers/scsi/st.c	Mon Dec  3 23:17:33 2001
@@ -3229,7 +3229,6 @@
 			tb->sg[0].address =
 			    (unsigned char *) __get_free_pages(priority, order);
 			if (tb->sg[0].address != NULL) {
-				tb->sg[0].alt_address = NULL;
 				tb->sg[0].length = b_size;
 				break;
 			}
@@ -3265,7 +3264,6 @@
 					tb = NULL;
 					break;
 				}
-				tb->sg[segs].alt_address = NULL;
 				tb->sg[segs].length = b_size;
 				got += b_size;
 				segs++;
@@ -3339,7 +3337,6 @@
 			normalize_buffer(STbuffer);
 			return FALSE;
 		}
-		STbuffer->sg[segs].alt_address = NULL;
 		STbuffer->sg[segs].length = b_size;
 		STbuffer->sg_segs += 1;
 		got += b_size;
diff -urN linux-2.4.13-pre1/drivers/scsi/sym53c8xx.c linux/drivers/scsi/sym53c8xx.c
--- linux-2.4.13-pre1/drivers/scsi/sym53c8xx.c	Sun Sep 30 12:26:08 2001
+++ linux/drivers/scsi/sym53c8xx.c	Mon Dec  3 23:17:33 2001
@@ -987,8 +987,8 @@
 	if (vbp) {
 		dma_addr_t daddr;
 		vp = (m_addr_t) pci_alloc_consistent(mp->bush,
-						PAGE_SIZE<<MEMO_PAGE_ORDER,
-						&daddr);
+						     PAGE_SIZE<<MEMO_PAGE_ORDER,
+						     &daddr);
 		if (vp) {
 			int hc = VTOB_HASH_CODE(vp);
 			vbp->vaddr = vp;
@@ -1138,26 +1138,26 @@
 /* Linux version with pci bus iommu kernel interface */
 
 /* To keep track of the dma mapping (sg/single) that has been set */
-#define __data_mapped	SCp.phase
-#define __data_mapping	SCp.have_data_in
+#define __data_mapped(cmd)	(cmd)->SCp.phase
+#define __data_mapping(cmd)	(cmd)->SCp.dma_handle
 
 static void __unmap_scsi_data(pcidev_t pdev, Scsi_Cmnd *cmd)
 {
 	int dma_dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
 
-	switch(cmd->__data_mapped) {
+	switch(__data_mapped(cmd)) {
 	case 2:
 		pci_unmap_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
 		break;
 	case 1:
-		pci_unmap_single(pdev, cmd->__data_mapping,
-				 cmd->request_bufflen, dma_dir);
+		pci_unmap_page(pdev, __data_mapping(cmd),
+			       cmd->request_bufflen, dma_dir);
 		break;
 	}
-	cmd->__data_mapped = 0;
+	__data_mapped(cmd) = 0;
 }
 
-static u_long __map_scsi_single_data(pcidev_t pdev, Scsi_Cmnd *cmd)
+static dma_addr_t __map_scsi_single_data(pcidev_t pdev, Scsi_Cmnd *cmd)
 {
 	dma_addr_t mapping;
 	int dma_dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
@@ -1165,10 +1165,13 @@
 	if (cmd->request_bufflen == 0)
 		return 0;
 
-	mapping = pci_map_single(pdev, cmd->request_buffer,
-				 cmd->request_bufflen, dma_dir);
-	cmd->__data_mapped = 1;
-	cmd->__data_mapping = mapping;
+	mapping = pci_map_page(pdev,
+			       virt_to_page(cmd->request_buffer),
+			       ((unsigned long)cmd->request_buffer &
+				~PAGE_MASK),
+			       cmd->request_bufflen, dma_dir);
+	__data_mapped(cmd) = 1;
+	__data_mapping(cmd) = mapping;
 
 	return mapping;
 }
@@ -1182,8 +1185,8 @@
 		return 0;
 
 	use_sg = pci_map_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
-	cmd->__data_mapped = 2;
-	cmd->__data_mapping = use_sg;
+	__data_mapped(cmd) = 2;
+	__data_mapping(cmd) = use_sg;
 
 	return use_sg;
 }
@@ -1192,12 +1195,12 @@
 {
 	int dma_dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
 
-	switch(cmd->__data_mapped) {
+	switch(__data_mapped(cmd)) {
 	case 2:
 		pci_dma_sync_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
 		break;
 	case 1:
-		pci_dma_sync_single(pdev, cmd->__data_mapping,
+		pci_dma_sync_single(pdev, __data_mapping(cmd),
 				    cmd->request_bufflen, dma_dir);
 		break;
 	}
@@ -5029,12 +5032,12 @@
 	/*
 	**	64 bit (53C895A or 53C896) ?
 	*/
-	if (np->features & FE_DAC)
-#ifdef SCSI_NCR_USE_64BIT_DAC
-		np->rv_ccntl1	|= (XTIMOD | EXTIBMV);
-#else
-		np->rv_ccntl1	|= (DDAC);
-#endif
+	if (np->features & FE_DAC) {
+		if (np->features & FE_DAC_IN_USE)
+			np->rv_ccntl1	|= (XTIMOD | EXTIBMV);
+		else
+			np->rv_ccntl1	|= (DDAC);
+	}
 
 	/*
 	**	Phase mismatch handled by SCRIPTS (53C895A, 53C896 or C1010) ?
@@ -12068,15 +12071,9 @@
 **	code will get more complex later).
 */
 
-#ifdef SCSI_NCR_USE_64BIT_DAC
 #define SCATTER_ONE(data, badd, len)					\
 	(data)->addr = cpu_to_scr(badd);				\
 	(data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len);
-#else
-#define SCATTER_ONE(data, badd, len)		\
-	(data)->addr = cpu_to_scr(badd);	\
-	(data)->size = cpu_to_scr(len);
-#endif
 
 #define CROSS_16MB(p, n) (((((u_long) p) + n - 1) ^ ((u_long) p)) & ~0xffffff)
 
@@ -12088,7 +12085,7 @@
 	cp->data_len = cmd->request_bufflen;
 
 	if (cmd->request_bufflen) {
-		u_long baddr = map_scsi_single_data(np, cmd);
+		dma_addr_t baddr = map_scsi_single_data(np, cmd);
 
 		SCATTER_ONE(data, baddr, cmd->request_bufflen);
 		if (CROSS_16MB(baddr, cmd->request_bufflen)) {
@@ -12139,7 +12136,7 @@
 		data = &cp->phys.data[MAX_SCATTER - use_sg];
 
 		for (segn = 0; segn < use_sg; segn++) {
-			u_long baddr = scsi_sg_dma_address(&scatter[segn]);
+			dma_addr_t baddr = scsi_sg_dma_address(&scatter[segn]);
 			unsigned int len = scsi_sg_dma_len(&scatter[segn]);
 
 			SCATTER_ONE(&data[segn],
@@ -12178,7 +12175,7 @@
 		data = &cp->phys.data[MAX_SCATTER - use_sg];
 
 		for (segment = 0; segment < use_sg; segment++) {
-			u_long baddr = scsi_sg_dma_address(&scatter[segment]);
+			dma_addr_t baddr = scsi_sg_dma_address(&scatter[segment]);
 			unsigned int len = scsi_sg_dma_len(&scatter[segment]);
 
 			SCATTER_ONE(&data[segment],
@@ -13098,14 +13095,6 @@
 		(int) (PciDeviceFn(pdev) & 0xf8) >> 3,
 		(int) (PciDeviceFn(pdev) & 7));
 
-#ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
-	if (pci_set_dma_mask(pdev, (dma_addr_t) (0xffffffffUL))) {
-		printk(KERN_WARNING NAME53C8XX
-		       "32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
-		return -1;
-	}
-#endif
-
 	/*
 	**    Read info from the PCI config space.
 	**    pci_read_config_xxx() functions are assumed to be used for 
@@ -13173,6 +13162,28 @@
 		break;
 	}
 
+#ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
+	/* Configure DMA attributes.  For DAC capable boards, we can encode
+	** 32+8 bits for SCSI DMA data addresses with the extra bits used
+	** in the size field.  We use normal 32-bit PCI addresses for
+	** descriptors.
+	*/
+	if (chip->features & FE_DAC) {
+		if (pci_set_dma_mask(pdev, (u64) 0xffffffffff))
+			chip->features &= ~FE_DAC_IN_USE;
+		else
+			chip->features |= FE_DAC_IN_USE;
+	}
+
+	if (!(chip->features & FE_DAC_IN_USE)) {
+		if (pci_set_dma_mask(pdev, (u64) 0xffffffff)) {
+			printk(KERN_WARNING NAME53C8XX
+			       "32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
+			return -1;
+		}
+	}
+#endif
+
 	/*
 	**	Ignore Symbios chips controlled by SISL RAID controller.
 	**	This controller sets value 0x52414944 at RAM end - 16.
@@ -13609,8 +13620,8 @@
      cmd->SCp.ptr       = NULL;
      cmd->SCp.buffer    = NULL;
 #ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
-     cmd->__data_mapped = 0;
-     cmd->__data_mapping = 0;
+     __data_mapped(cmd) = 0;
+     __data_mapping(cmd) = 0;
 #endif
 
      NCR_LOCK_NCB(np, flags);
diff -urN linux-2.4.13-pre1/drivers/scsi/sym53c8xx_comm.h linux/drivers/scsi/sym53c8xx_comm.h
--- linux-2.4.13-pre1/drivers/scsi/sym53c8xx_comm.h	Thu Jul  5 11:28:16 2001
+++ linux/drivers/scsi/sym53c8xx_comm.h	Mon Dec  3 23:17:33 2001
@@ -2186,7 +2186,7 @@
 		(int) (PciDeviceFn(pdev) & 7));
 
 #ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
-	if (!pci_dma_supported(pdev, (dma_addr_t) (0xffffffffUL))) {
+	if (!pci_dma_supported(pdev, 0xffffffff)) {
 		printk(KERN_WARNING NAME53C8XX
 		       "32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
 		return -1;
diff -urN linux-2.4.13-pre1/drivers/scsi/sym53c8xx_defs.h linux/drivers/scsi/sym53c8xx_defs.h
--- linux-2.4.13-pre1/drivers/scsi/sym53c8xx_defs.h	Wed Oct 10 23:47:52 2001
+++ linux/drivers/scsi/sym53c8xx_defs.h	Mon Dec  3 23:17:33 2001
@@ -184,20 +184,6 @@
 #endif
 
 /*
- * Should we enable DAC cycles on Sparc64 platform?
- * Until further investigation we do not enable it
- * at the moment.
- * We may want to enable it for __ia64__ (untested)
- */
-#if defined(__ia64__)
-#    if !defined(SCSI_NCR_USE_64BIT_DAC)
-#        define SCSI_NCR_USE_64BIT_DAC
-#    endif
-#else
-#    undef SCSI_NCR_USE_64BIT_DAC
-#endif
-
-/*
  * Immediate arbitration
  */
 #if defined(CONFIG_SCSI_NCR53C8XX_IARB)
@@ -205,13 +191,6 @@
 #endif
 
 /*
- * Should we enable DAC cycles on sparc64 platforms?
- * Until further investigation we do not enable it
- * anywhere at the moment.
- */
-#undef SCSI_NCR_USE_64BIT_DAC
-
-/*
  * Sync transfer frequency at startup.
  * Allow from 5Mhz to 80Mhz default 20 Mhz.
  */
@@ -746,6 +725,7 @@
 #define FE_66MHZ 	(1<<23)   /* 66MHz PCI Support */
 #define FE_DAC	 	(1<<24)   /* Support DAC cycles (64 bit addressing) */
 #define FE_ISTAT1 	(1<<25)   /* Have ISTAT1, MBOX0, MBOX1 registers */
+#define FE_DAC_IN_USE	(1<<26)	  /* Platform does DAC cycles */
 
 #define FE_CACHE_SET	(FE_ERL|FE_CLSE|FE_WRIE|FE_ERMP)
 #define FE_SCSI_SET	(FE_WIDE|FE_ULTRA|FE_ULTRA2|FE_DBLR|FE_QUAD|F_CLK80)
diff -urN linux-2.4.13-pre1/drivers/video/hgafb.c linux/drivers/video/hgafb.c
--- linux-2.4.13-pre1/drivers/video/hgafb.c	Fri Sep 14 14:48:10 2001
+++ linux/drivers/video/hgafb.c	Mon Dec  3 23:17:33 2001
@@ -203,7 +203,7 @@
 		fillchar = 0x00;
 	spin_unlock_irqrestore(&hga_reg_lock, flags);
 	if (fillchar != 0xbf)
-		memset((char *)hga_vram_base, fillchar, hga_vram_len);
+		isa_memset_io(hga_vram_base, fillchar, hga_vram_len);
 }
 
 
@@ -275,11 +275,12 @@
 static void hga_show_logo(void)
 {
 	int x, y;
-	char *dest = (char *)hga_vram_base;
+	unsigned long dest = hga_vram_base;
 	char *logo = linux_logo_bw;
 	for (y = 134; y < 134 + 80 ; y++) /* this needs some cleanup */
 		for (x = 0; x < 10 ; x++)
-			*(dest + (y%4)*8192 + (y>>2)*90 + x + 40) = ~*(logo++);
+			isa_writeb(~*(logo++),
+				   (dest + (y%4)*8192 + (y>>2)*90 + x + 40));
 }
 #endif /* MODULE */	
 
diff -urN linux-2.4.13-pre1/fs/buffer.c linux/fs/buffer.c
--- linux-2.4.13-pre1/fs/buffer.c	Sun Sep 30 12:05:19 2001
+++ linux/fs/buffer.c	Mon Dec  3 23:17:33 2001
@@ -1123,13 +1123,12 @@
 }
 
 /*
- * bforget() is like brelse(), except it puts the buffer on the
- * free list if it can.. We can NOT free the buffer if:
- *  - there are other users of it
- *  - it is locked and thus can have active IO
+ * bforget() is like brelse(), except it might discard any
+ * potentially dirty data.
  */
 void __bforget(struct buffer_head * buf)
 {
+	/* mark_buffer_clean(bh); */
 	__brelse(buf);
 }
 
diff -urN linux-2.4.13-pre1/fs/fat/cache.c linux/fs/fat/cache.c
--- linux-2.4.13-pre1/fs/fat/cache.c	Tue Aug 14 19:57:28 2001
+++ linux/fs/fat/cache.c	Mon Dec  3 23:17:33 2001
@@ -15,8 +15,6 @@
 #include <linux/stat.h>
 #include <linux/fat_cvf.h>
 
-#include "msbuffer.h"
-
 #if 0
 #  define PRINTK(x) printk x
 #else
diff -urN linux-2.4.13-pre1/fs/fat/dir.c linux/fs/fat/dir.c
--- linux-2.4.13-pre1/fs/fat/dir.c	Tue Aug 14 19:57:28 2001
+++ linux/fs/fat/dir.c	Mon Dec  3 23:17:33 2001
@@ -10,12 +10,9 @@
  *  VFAT extensions by Gordon Chaffee <chaffee@plateau.cs.berkeley.edu>
  *  Merged with msdos fs by Henrik Storner <storner@osiris.ping.dk>
  *  Rewritten for constant inumbers. Plugged buffer overrun in readdir(). AV
- *  Short name translation 1999 by Wolfram Pienkoss <wp@bszh.de>
+ *  Short name translation 1999, 2001 by Wolfram Pienkoss <wp@bszh.de>
  */
 
-#define ASC_LINUX_VERSION(V, P, S)	(((V) * 65536) + ((P) * 256) + (S))
-
-#include <linux/version.h>
 #include <linux/fs.h>
 #include <linux/msdos_fs.h>
 #include <linux/nls.h>
@@ -30,8 +27,6 @@
 
 #include <asm/uaccess.h>
 
-#include "msbuffer.h"
-
 #define PRINTK(X)
 
 struct file_operations fat_dir_operations = {
@@ -163,6 +158,27 @@
 	return 0;
 }
 
+static inline int
+fat_shortname2uni(struct nls_table *nls, char *buf, int buf_size,
+		  wchar_t *uni_buf, unsigned short opt, int lower)
+{
+	int len = 0;
+
+	if (opt & VFAT_SFN_DISPLAY_LOWER)
+		len =  fat_short2lower_uni(nls, buf, buf_size, uni_buf);
+	else if (opt & VFAT_SFN_DISPLAY_WIN95)
+		len = fat_short2uni(nls, buf, buf_size, uni_buf);
+	else if (opt & VFAT_SFN_DISPLAY_WINNT) {
+		if (lower)
+			len = fat_short2lower_uni(nls, buf, buf_size, uni_buf);
+		else 
+			len = fat_short2uni(nls, buf, buf_size, uni_buf);
+	} else
+		len = fat_short2uni(nls, buf, buf_size, uni_buf);
+
+	return len;
+}
+
 /*
  * Return values: negative -> error, 0 -> not found, positive -> found,
  * value is the total amount of slots, including the shortname entry.
@@ -176,11 +192,12 @@
 	struct nls_table *nls_io = MSDOS_SB(sb)->nls_io;
 	struct nls_table *nls_disk = MSDOS_SB(sb)->nls_disk;
 	wchar_t bufuname[14];
-	unsigned char xlate_len, long_slots, *unicode = NULL;
+	unsigned char xlate_len, long_slots;
+	wchar_t *unicode = NULL;
 	char work[8], bufname[260];	/* 256 + 4 */
 	int uni_xlate = MSDOS_SB(sb)->options.unicode_xlate;
 	int utf8 = MSDOS_SB(sb)->options.utf8;
-	int nocase = MSDOS_SB(sb)->options.nocase;
+	unsigned short opt_shortname = MSDOS_SB(sb)->options.shortname;
 	int ino, chl, i, j, last_u, res = 0;
 	loff_t cpos = 0;
 
@@ -197,7 +214,6 @@
 			continue;
 		if (de->attr == ATTR_EXT) {
 			struct msdos_dir_slot *ds;
-			int offset;
 			unsigned char id;
 			unsigned char slot;
 			unsigned char slots;
@@ -205,7 +221,7 @@
 			unsigned char alias_checksum;
 
 			if (!unicode) {
-				unicode = (unsigned char *)
+				unicode = (wchar_t *)
 					__get_free_page(GFP_KERNEL);
 				if (!unicode) {
 					fat_brelse(sb, bh);
@@ -214,7 +230,6 @@
 			}
 parse_long:
 			slots = 0;
-			offset = 0;
 			ds = (struct msdos_dir_slot *) de;
 			id = ds->id;
 			if (!(id & 0x40))
@@ -227,16 +242,16 @@
 
 			slot = slots;
 			while (1) {
+				int offset;
+
 				slot--;
-				offset = slot * 26;
-				memcpy(&unicode[offset], ds->name0_4, 10);
-				memcpy(&unicode[offset+10], ds->name5_10, 12);
-				memcpy(&unicode[offset+22], ds->name11_12, 4);
-				offset += 26;
+				offset = slot * 13;
+				fat16_towchar(unicode + offset, ds->name0_4, 5);
+				fat16_towchar(unicode + offset + 5, ds->name5_10, 6);
+				fat16_towchar(unicode + offset + 11, ds->name11_12, 2);
 
 				if (ds->id & 0x40) {
-					unicode[offset] = 0;
-					unicode[offset+1] = 0;
+					unicode[offset + 13] = 0;
 				}
 				if (fat_get_entry(inode,&cpos,&bh,&de,&ino)<0)
 					goto EODir;
@@ -271,10 +286,9 @@
 		}
 		for (i = 0, j = 0, last_u = 0; i < 8;) {
 			if (!work[i]) break;
-			if (nocase)
-				chl = fat_short2uni(nls_disk, &work[i], 8 - i, &bufuname[j++]);
-			else
-				chl = fat_short2lower_uni(nls_disk, &work[i], 8 - i, &bufuname[j++]);
+			chl = fat_shortname2uni(nls_disk, &work[i], 8 - i,
+						&bufuname[j++], opt_shortname,
+						de->lcase & CASE_LOWER_BASE);
 			if (chl <= 1) {
 				if (work[i] != ' ')
 					last_u = j;
@@ -287,10 +301,9 @@
 		fat_short2uni(nls_disk, ".", 1, &bufuname[j++]);
 		for (i = 0; i < 3;) {
 			if (!de->ext[i]) break;
-			if (nocase)
-				chl = fat_short2uni(nls_disk, &de->ext[i], 3 - i, &bufuname[j++]);
-			else
-				chl = fat_short2lower_uni(nls_disk, &de->ext[i], 3 - i, &bufuname[j++]);
+			chl = fat_shortname2uni(nls_disk, &de->ext[i], 3 - i,
+						&bufuname[j++], opt_shortname,
+						de->lcase & CASE_LOWER_EXT);
 			if (chl <= 1) {
 				if (de->ext[i] != ' ')
 					last_u = j;
@@ -314,8 +327,8 @@
 
 		if (long_slots) {
 			xlate_len = utf8
-				?utf8_wcstombs(bufname, (wchar_t *) unicode, sizeof(bufname))
-				:uni16_to_x8(bufname, (wchar_t *) unicode, uni_xlate, nls_io);
+				?utf8_wcstombs(bufname, unicode, sizeof(bufname))
+				:uni16_to_x8(bufname, unicode, uni_xlate, nls_io);
 			if (xlate_len != name_len)
 				continue;
 			if ((!anycase && !memcmp(name, bufname, xlate_len)) ||
@@ -346,13 +359,15 @@
 	struct nls_table *nls_io = MSDOS_SB(sb)->nls_io;
 	struct nls_table *nls_disk = MSDOS_SB(sb)->nls_disk;
 	wchar_t bufuname[14];
-	unsigned char long_slots, *unicode = NULL;
+	unsigned char long_slots;
+	wchar_t *unicode = NULL;
 	char c, work[8], bufname[56], *ptname = bufname;
 	unsigned long lpos, dummy, *furrfu = &lpos;
 	int uni_xlate = MSDOS_SB(sb)->options.unicode_xlate;
 	int isvfat = MSDOS_SB(sb)->options.isvfat;
 	int utf8 = MSDOS_SB(sb)->options.utf8;
 	int nocase = MSDOS_SB(sb)->options.nocase;
+	unsigned short opt_shortname = MSDOS_SB(sb)->options.shortname;
 	int ino, inum, chi, chl, i, i2, j, last, last_u, dotoffset = 0;
 	loff_t cpos;
 
@@ -394,7 +409,6 @@
 
 	if (isvfat && de->attr == ATTR_EXT) {
 		struct msdos_dir_slot *ds;
-		int offset;
 		unsigned char id;
 		unsigned char slot;
 		unsigned char slots;
@@ -402,7 +416,7 @@
 		unsigned char alias_checksum;
 
 		if (!unicode) {
-			unicode = (unsigned char *)
+			unicode = (wchar_t *)
 				__get_free_page(GFP_KERNEL);
 			if (!unicode) {
 				filp->f_pos = cpos;
@@ -412,7 +426,6 @@
 		}
 ParseLong:
 		slots = 0;
-		offset = 0;
 		ds = (struct msdos_dir_slot *) de;
 		id = ds->id;
 		if (!(id & 0x40))
@@ -425,16 +438,16 @@
 
 		slot = slots;
 		while (1) {
+			int offset;
+
 			slot--;
-			offset = slot * 26;
-			memcpy(&unicode[offset], ds->name0_4, 10);
-			memcpy(&unicode[offset+10], ds->name5_10, 12);
-			memcpy(&unicode[offset+22], ds->name11_12, 4);
-			offset += 26;
+			offset = slot * 13;
+			fat16_towchar(unicode + offset, ds->name0_4, 5);
+			fat16_towchar(unicode + offset + 5, ds->name5_10, 6);
+			fat16_towchar(unicode + offset + 11, ds->name11_12, 2);
 
 			if (ds->id & 0x40) {
-				unicode[offset] = 0;
-				unicode[offset+1] = 0;
+				unicode[offset + 13] = 0;
 			}
 			if (fat_get_entry(inode,&cpos,&bh,&de,&ino) == -1)
 				goto EODir;
@@ -474,10 +487,9 @@
 	}
 	for (i = 0, j = 0, last = 0, last_u = 0; i < 8;) {
 		if (!(c = work[i])) break;
-		if (nocase)
-			chl = fat_short2uni(nls_disk, &work[i], 8 - i, &bufuname[j++]);
-		else
-			chl = fat_short2lower_uni(nls_disk, &work[i], 8 - i, &bufuname[j++]);
+		chl = fat_shortname2uni(nls_disk, &work[i], 8 - i,
+					&bufuname[j++], opt_shortname,
+					de->lcase & CASE_LOWER_BASE);
 		if (chl <= 1) {
 			ptname[i++] = (!nocase && c>='A' && c<='Z') ? c+32 : c;
 			if (c != ' ') {
@@ -498,10 +510,9 @@
 	ptname[i++] = '.';
 	for (i2 = 0; i2 < 3;) {
 		if (!(c = de->ext[i2])) break;
-		if (nocase)
-			chl = fat_short2uni(nls_disk, &de->ext[i2], 3 - i2, &bufuname[j++]);
-		else
-			chl = fat_short2lower_uni(nls_disk, &de->ext[i2], 3 - i2, &bufuname[j++]);
+		chl = fat_shortname2uni(nls_disk, &de->ext[i2], 3 - i2,
+					&bufuname[j++], opt_shortname,
+					de->lcase & CASE_LOWER_EXT);
 		if (chl <= 1) {
 			i2++;
 			ptname[i++] = (!nocase && c>='A' && c<='Z') ? c+32 : c;
@@ -553,8 +564,8 @@
 	} else {
 		char longname[275];
 		int long_len = utf8
-			? utf8_wcstombs(longname, (wchar_t *) unicode, sizeof(longname))
-			: uni16_to_x8(longname, (wchar_t *) unicode, uni_xlate,
+			? utf8_wcstombs(longname, unicode, sizeof(longname))
+			: uni16_to_x8(longname, unicode, uni_xlate,
 				      nls_io);
 		if (both) {
 			memcpy(&longname[long_len+1], bufname, i);
diff -urN linux-2.4.13-pre1/fs/fat/fatfs_syms.c linux/fs/fat/fatfs_syms.c
--- linux-2.4.13-pre1/fs/fat/fatfs_syms.c	Wed Apr 18 11:49:12 2001
+++ linux/fs/fat/fatfs_syms.c	Mon Dec  3 23:17:33 2001
@@ -4,8 +4,7 @@
  * Exported kernel symbols for the low-level FAT-based fs support.
  *
  */
-#define ASC_LINUX_VERSION(V, P, S)	(((V) * 65536) + ((P) * 256) + (S))
-#include <linux/version.h>
+
 #include <linux/module.h>
 #include <linux/init.h>
 
@@ -13,8 +12,6 @@
 #include <linux/msdos_fs.h>
 #include <linux/fat_cvf.h>
 
-#include "msbuffer.h"
-
 EXPORT_SYMBOL(fat_new_dir);
 EXPORT_SYMBOL(fat_get_block);
 EXPORT_SYMBOL(fat_clear_inode);
@@ -23,7 +20,6 @@
 EXPORT_SYMBOL(fat__get_entry);
 EXPORT_SYMBOL(fat_mark_buffer_dirty);
 EXPORT_SYMBOL(fat_notify_change);
-EXPORT_SYMBOL(fat_parent_ino);
 EXPORT_SYMBOL(fat_put_super);
 EXPORT_SYMBOL(fat_attach);
 EXPORT_SYMBOL(fat_detach);
diff -urN linux-2.4.13-pre1/fs/fat/inode.c linux/fs/fat/inode.c
--- linux-2.4.13-pre1/fs/fat/inode.c	Wed Oct  3 22:57:36 2001
+++ linux/fs/fat/inode.c	Mon Dec  3 23:17:33 2001
@@ -10,17 +10,14 @@
  *  	Max Cohan: Fixed invalid FSINFO offset when info_sector is 0
  */
 
-#include <linux/config.h>
-#include <linux/version.h>
-#define __NO_VERSION__
 #include <linux/module.h>
-
 #include <linux/msdos_fs.h>
 #include <linux/nls.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/string.h>
+#include <linux/bitops.h>
 #include <linux/major.h>
 #include <linux/blkdev.h>
 #include <linux/fs.h>
@@ -28,11 +25,8 @@
 #include <linux/locks.h>
 #include <linux/fat_cvf.h>
 #include <linux/slab.h>
-#include <linux/bitops.h>
 #include <linux/smp_lock.h>
 
-#include "msbuffer.h"
-
 #include <asm/uaccess.h>
 #include <asm/unaligned.h>
 
@@ -81,9 +75,10 @@
 static struct list_head fat_inode_hashtable[FAT_HASH_SIZE];
 spinlock_t fat_inode_lock = SPIN_LOCK_UNLOCKED;
 
-void fat_hash_init(void) {
+void fat_hash_init(void)
+{
 	int i;
-	for(i=0;i<FAT_HASH_SIZE;i++) {
+	for(i = 0; i < FAT_HASH_SIZE; i++) {
 		INIT_LIST_HEAD(&fat_inode_hashtable[i]);
 	}
 }
@@ -91,19 +86,21 @@
 static inline unsigned long fat_hash(struct super_block *sb, int i_pos)
 {
 	unsigned long tmp = (unsigned long)i_pos | (unsigned long) sb;
-	tmp = tmp + (tmp >> FAT_HASH_BITS) + (tmp >> FAT_HASH_BITS*2);
+	tmp = tmp + (tmp >> FAT_HASH_BITS) + (tmp >> FAT_HASH_BITS * 2);
 	return tmp & FAT_HASH_MASK;
 }
 
-void fat_attach(struct inode *inode, int i_pos) {
+void fat_attach(struct inode *inode, int i_pos)
+{
 	spin_lock(&fat_inode_lock);
 	MSDOS_I(inode)->i_location = i_pos;
 	list_add(&MSDOS_I(inode)->i_fat_hash,
-		fat_inode_hashtable+fat_hash(inode->i_sb, i_pos));
+		fat_inode_hashtable + fat_hash(inode->i_sb, i_pos));
 	spin_unlock(&fat_inode_lock);
 }
 
-void fat_detach(struct inode *inode) {
+void fat_detach(struct inode *inode)
+{
 	spin_lock(&fat_inode_lock);
 	MSDOS_I(inode)->i_location = 0;
 	list_del(&MSDOS_I(inode)->i_fat_hash);
@@ -111,13 +108,15 @@
 	spin_unlock(&fat_inode_lock);
 }
 
-struct inode *fat_iget(struct super_block *sb, int i_pos) {
+struct inode *fat_iget(struct super_block *sb, int i_pos)
+{
 	struct list_head *p = fat_inode_hashtable + fat_hash(sb, i_pos);
 	struct list_head *walk;
 	struct msdos_inode_info *i;
 	struct inode *inode = NULL;
+
 	spin_lock(&fat_inode_lock);
-	for(walk=p->next;walk!=p;walk=walk->next) {
+	list_for_each(walk, p) {
 		i = list_entry(walk, struct msdos_inode_info, i_fat_hash);
 		if (i->i_fat_inode->i_sb != sb)
 			continue;
@@ -222,6 +221,7 @@
 	opts->quiet = opts->sys_immutable = opts->dotsOK = opts->showexec = 0;
 	opts->codepage = 0;
 	opts->nocase = 0;
+	opts->shortname = 0;
 	opts->utf8 = 0;
 	opts->iocharset = NULL;
 	*debug = *fat = 0;
@@ -330,16 +330,22 @@
 		}
 		else if (!strcmp(this_char,"iocharset") && value) {
 			p = value;
-			while (*value && *value != ',') value++;
+			while (*value && *value != ',')
+				value++;
 			len = value - p;
-			if (len) { 
-				char * buffer = kmalloc(len+1, GFP_KERNEL);
-				if (buffer) {
+			if (len) {
+				char *buffer;
+
+				if (opts->iocharset != NULL) {
+					kfree(opts->iocharset);
+					opts->iocharset = NULL;
+				}
+				buffer = kmalloc(len + 1, GFP_KERNEL);
+				if (buffer != NULL) {
 					opts->iocharset = buffer;
 					memcpy(buffer, p, len);
 					buffer[len] = 0;
-					printk("MSDOS FS: IO charset %s\n",
-						buffer);
+					printk("MSDOS FS: IO charset %s\n", buffer);
 				} else
 					ret = 0;
 			}
@@ -647,7 +653,7 @@
 		fsinfo_offset =
 			(sbi->fsinfo_sector * logical_sector_size) % hard_blksize;
 		fsinfo_bh = bh;
-		if (bh->b_blocknr != fsinfo_block) {
+		if (fsinfo_block != 0) {
 			fsinfo_bh = bread(sb->s_dev, fsinfo_block, hard_blksize);
 			if (fsinfo_bh == NULL) {
 				printk("FAT: bread failed, FSINFO block"
@@ -667,7 +673,7 @@
 			sbi->free_clusters = CF_LE_L(fsinfo->free_clusters);
 		}
 
-		if (bh->b_blocknr != fsinfo_block)
+		if (fsinfo_block != 0)
 			brelse(fsinfo_bh);
 	} else {
 		fat32 = 0;
@@ -705,6 +711,9 @@
 	}
 	brelse(bh);
 
+	if (error)
+		goto out_invalid;
+
 	sb->s_blocksize = logical_sector_size;
 	sb->s_blocksize_bits = ffs(logical_sector_size) - 1;
 	set_blocksize(sb->s_dev, sb->s_blocksize);
@@ -740,7 +749,6 @@
 
 	sb->s_magic = MSDOS_SUPER_MAGIC;
 	/* set up enough so that it can read an inode */
-	init_waitqueue_head(&sbi->fat_wait);
 	init_MUTEX(&sbi->fat_lock);
 	sbi->prev_free = 0;
 
@@ -957,7 +965,7 @@
 	struct super_block *sb = inode->i_sb;
 	struct buffer_head *bh;
 	struct msdos_dir_entry *raw_entry;
-	int i_pos;
+	unsigned int i_pos;
 
 retry:
 	i_pos = MSDOS_I(inode)->i_location;
@@ -1036,7 +1044,9 @@
 	if (error)
 		return MSDOS_SB(sb)->options.quiet ? 0 : error;
 
-	inode_setattr(inode, attr);
+	error = inode_setattr(inode, attr);
+	if (error)
+		return error;
 
 	if (S_ISDIR(inode->i_mode))
 		inode->i_mode |= S_IXUGO;
@@ -1046,3 +1056,4 @@
 	    ~MSDOS_SB(sb)->options.fs_umask;
 	return 0;
 }
+MODULE_LICENSE("GPL");
diff -urN linux-2.4.13-pre1/fs/fat/misc.c linux/fs/fat/misc.c
--- linux-2.4.13-pre1/fs/fat/misc.c	Thu May 24 15:36:34 2001
+++ linux/fs/fat/misc.c	Mon Dec  3 23:17:33 2001
@@ -2,6 +2,8 @@
  *  linux/fs/fat/misc.c
  *
  *  Written 1992,1993 by Werner Almesberger
+ *  22/11/2000 - Fixed fat_date_unix2dos for dates earlier than 01/01/1980
+ *		 and date_dos2unix for date==0 by Igor Zhbanov(bsg@uniyar.ac.ru)
  */
 
 #include <linux/fs.h>
@@ -12,8 +14,6 @@
 #include <linux/string.h>
 #include <linux/stat.h>
 
-#include "msbuffer.h"
-
 #if 0
 #  define PRINTK(x)	printk x
 #else
@@ -75,30 +75,11 @@
 	}
 }
 
-
-/* File creation lock. This is system-wide to avoid deadlocks in rename. */
-/* (rename might deadlock before detecting cross-FS moves.) */
-
-static DECLARE_MUTEX(creation_lock);
-
-void fat_lock_creation(void)
-{
-	down(&creation_lock);
-}
-
-
-void fat_unlock_creation(void)
-{
-	up(&creation_lock);
-}
-
-
 void lock_fat(struct super_block *sb)
 {
 	down(&(MSDOS_SB(sb)->fat_lock));
 }
 
-
 void unlock_fat(struct super_block *sb)
 {
 	up(&(MSDOS_SB(sb)->fat_lock));
@@ -132,39 +113,44 @@
 }
 
 /*
- * fat_add_cluster tries to allocate a new cluster and adds it to the file
- * represented by inode. The cluster is zero-initialized.
+ * fat_add_cluster tries to allocate a new cluster and adds it to the
+ * file represented by inode.
  */
-
-/* not a directory */
-
 int fat_add_cluster(struct inode *inode)
 {
 	struct super_block *sb = inode->i_sb;
-	int count,nr,limit,last,curr,file_cluster;
+	int count, nr, limit, last, curr, file_cluster;
+	int cluster_size = MSDOS_SB(sb)->cluster_size;
 	int res = -ENOSPC;
-
-	if (!MSDOS_SB(sb)->free_clusters) return res;
+	
 	lock_fat(sb);
+	
+	if (MSDOS_SB(sb)->free_clusters == 0) {
+		unlock_fat(sb);
+		return res;
+	}
 	limit = MSDOS_SB(sb)->clusters;
 	nr = limit; /* to keep GCC happy */
 	for (count = 0; count < limit; count++) {
-		nr = ((count+MSDOS_SB(sb)->prev_free) % limit)+2;
-		if (fat_access(sb,nr,-1) == 0) break;
+		nr = ((count + MSDOS_SB(sb)->prev_free) % limit) + 2;
+		if (fat_access(sb, nr, -1) == 0)
+			break;
 	}
-	MSDOS_SB(sb)->prev_free = (count+MSDOS_SB(sb)->prev_free+1) % limit;
 	if (count >= limit) {
 		MSDOS_SB(sb)->free_clusters = 0;
 		unlock_fat(sb);
 		return res;
 	}
-	fat_access(sb,nr,EOF_FAT(sb));
+	
+	MSDOS_SB(sb)->prev_free = (count + MSDOS_SB(sb)->prev_free + 1) % limit;
+	fat_access(sb, nr, EOF_FAT(sb));
 	if (MSDOS_SB(sb)->free_clusters != -1)
 		MSDOS_SB(sb)->free_clusters--;
 	if (MSDOS_SB(sb)->fat_bits == 32)
 		fat_clusters_flush(sb);
+	
 	unlock_fat(sb);
-
+	
 	/* We must locate the last cluster of the file to add this
 	   new one (nr) to the end of the link list (the FAT).
 	   
@@ -177,12 +163,12 @@
 	*/
 	last = file_cluster = 0;
 	if ((curr = MSDOS_I(inode)->i_start) != 0) {
-		fat_cache_lookup(inode,INT_MAX,&last,&curr);
+		fat_cache_lookup(inode, INT_MAX, &last, &curr);
 		file_cluster = last;
 		while (curr && curr != -1){
 			file_cluster++;
 			if (!(curr = fat_access(sb, last = curr,-1))) {
-				fat_fs_panic(sb,"File without EOF");
+				fat_fs_panic(sb, "File without EOF");
 				return res;
 			}
 		}
@@ -195,94 +181,34 @@
 		MSDOS_I(inode)->i_logstart = nr;
 		mark_inode_dirty(inode);
 	}
+	if (file_cluster
+	    != inode->i_blocks / cluster_size / (sb->s_blocksize / 512)) {
+		printk ("file_cluster badly computed!!! %d <> %ld\n",
+			file_cluster,
+			inode->i_blocks / cluster_size / (sb->s_blocksize / 512));
+		fat_cache_inval_inode(inode);
+	}
 	inode->i_blocks += (1 << MSDOS_SB(sb)->cluster_bits) / 512;
-	return 0;
+
+	return nr;
 }
 
 struct buffer_head *fat_extend_dir(struct inode *inode)
 {
 	struct super_block *sb = inode->i_sb;
-	int count,nr,limit,last,curr,sector,last_sector,file_cluster;
-	struct buffer_head *bh, *res=NULL;
+	int nr, sector, last_sector;
+	struct buffer_head *bh, *res = NULL;
 	int cluster_size = MSDOS_SB(sb)->cluster_size;
 
 	if (MSDOS_SB(sb)->fat_bits != 32) {
 		if (inode->i_ino == MSDOS_ROOT_INO)
 			return res;
 	}
-	if (!MSDOS_SB(sb)->free_clusters)
-		return res;
-
-	lock_fat(sb);
 
-	limit = MSDOS_SB(sb)->clusters;
-	nr = limit; /* to keep GCC happy */
-	for (count = 0; count < limit; count++) {
-		nr = ((count + MSDOS_SB(sb)->prev_free) % limit) + 2;
-		if (fat_access(sb, nr, -1) == 0)
-			break;
-	}
-	PRINTK (("cnt = %d --", count));
-#ifdef DEBUG
-	printk("free cluster: %d\n", nr);
-#endif
-	if (count >= limit) {
-		MSDOS_SB(sb)->free_clusters = 0;
-		unlock_fat(sb);
+	nr = fat_add_cluster(inode);
+	if (nr < 0)
 		return res;
-	}
-
-	MSDOS_SB(sb)->prev_free = (count + MSDOS_SB(sb)->prev_free + 1) % limit;
-	fat_access(sb, nr, EOF_FAT(sb));
-	if (MSDOS_SB(sb)->free_clusters != -1)
-		MSDOS_SB(sb)->free_clusters--;
-	if (MSDOS_SB(sb)->fat_bits == 32)
-		fat_clusters_flush(sb);
-
-	unlock_fat(sb);
-
-#ifdef DEBUG
-	printk("set to %x\n", fat_access(sb, nr, -1));
-#endif
-
-	/* We must locate the last cluster of the file to add this
-	   new one (nr) to the end of the link list (the FAT).
-	   
-	   Here file_cluster will be the number of the last cluster of the
-	   file (before we add nr).
-	   
-	   last is the corresponding cluster number on the disk. We will
-	   use last to plug the nr cluster. We will use file_cluster to
-	   update the cache.
-	*/
-	last = file_cluster = 0;
-	if ((curr = MSDOS_I(inode)->i_start) != 0) {
-		fat_cache_lookup(inode, INT_MAX, &last, &curr);
-		file_cluster = last;
-		while (curr && curr != -1){
-			PRINTK (("."));
-			file_cluster++;
-			if (!(curr = fat_access(sb, last = curr, -1))) {
-				fat_fs_panic(sb,"File without EOF");
-				return res;
-			}
-		}
-		PRINTK ((" --  "));
-	}
-#ifdef DEBUG
-	printk("last = %d\n", last);
-#endif
-	if (last)
-		fat_access(sb, last, nr);
-	else {
-		MSDOS_I(inode)->i_start = nr;
-		MSDOS_I(inode)->i_logstart = nr;
-		mark_inode_dirty(inode);
-	}
-#ifdef DEBUG
-	if (last)
-		printk("next set to %d\n",fat_access(sb, last, -1));
-#endif
+	
 	sector = MSDOS_SB(sb)->data_start + (nr - 2) * cluster_size;
 	last_sector = sector + cluster_size;
 	if (MSDOS_SB(sb)->cvf_format && MSDOS_SB(sb)->cvf_format->zero_out_cluster)
@@ -305,23 +231,15 @@
 			}
 		}
 	}
-	if (file_cluster
-	    != inode->i_blocks / cluster_size / (sb->s_blocksize / 512)) {
-		printk ("file_cluster badly computed!!! %d <> %ld\n",
-			file_cluster,
-			inode->i_blocks / cluster_size / (sb->s_blocksize / 512));
-	}else{
-		fat_cache_add(inode, file_cluster, nr);
-	}
-	inode->i_blocks += (1 << MSDOS_SB(sb)->cluster_bits) / 512;
 	if (inode->i_size & (sb->s_blocksize - 1)) {
 		fat_fs_panic(sb, "Odd directory size");
-		inode->i_size = (inode->i_size + sb->s_blocksize) &
-			~(sb->s_blocksize - 1);
+		inode->i_size = (inode->i_size + sb->s_blocksize)
+			& ~(sb->s_blocksize - 1);
 	}
 	inode->i_size += 1 << MSDOS_SB(sb)->cluster_bits;
 	MSDOS_I(inode)->mmu_private += 1 << MSDOS_SB(sb)->cluster_bits;
 	mark_inode_dirty(inode);
+
 	return res;
 }
 
@@ -340,7 +258,9 @@
 {
 	int month,year,secs;
 
-	month = ((date >> 5) & 15)-1;
+	/* first subtract and mask after that... Otherwise, if
+	   date == 0, bad things happen */
+	month = ((date >> 5) - 1) & 15;
 	year = date >> 9;
 	secs = (time & 31)*2+60*((time >> 5) & 63)+(time >> 11)*3600+86400*
 	    ((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3) == 0 &&
@@ -359,7 +279,10 @@
 	int day,year,nl_day,month;
 
 	unix_date -= sys_tz.tz_minuteswest*60;
-	if (sys_tz.tz_dsttime) unix_date += 3600;
+
+	/* Jan 1 GMT 00:00:00 1980. But what about another time zone? */
+	if (unix_date < 315532800)
+		unix_date = 315532800;
 
 	*time = (unix_date % 60)/2+(((unix_date/60) % 60) << 5)+
 	    (((unix_date/3600) % 24) << 11);
@@ -592,61 +515,9 @@
 }
 
 /*
- * fat_parent_ino returns the inode number of the parent directory of dir.
- * File creation has to be deferred while fat_parent_ino is running to
- * prevent renames.
- *
- * AV. Bad, bad, bad... We need a mapping that would give us inode by
- * first cluster. Sheeeeit... OK, we can do it on fat_fill_inode() and
- * update on fat_add_cluster(). When will we remove it? fat_clear_inode()
- * and fat_truncate() to zero?
- */
-
-int fat_parent_ino(struct inode *dir,int locked)
-{
-	static int zero = 0;
-	int error,curr,prev,nr;
-
-	PRINTK(("fat_parent_ino: Debug 0\n"));
-	if (!S_ISDIR(dir->i_mode)) panic("Non-directory fed to m_p_i");
-	if (dir->i_ino == MSDOS_ROOT_INO) return dir->i_ino;
-	if (!locked) fat_lock_creation(); /* prevent renames */
-	if ((curr = raw_scan(dir->i_sb,MSDOS_I(dir)->i_start,MSDOS_DOTDOT,
-	    &zero,NULL,NULL,NULL)) < 0) {
-		if (!locked) fat_unlock_creation();
-		return curr;
-	}
-	PRINTK(("fat_parent_ino: Debug 1 curr=%d\n", curr));
-	if (!curr) nr = MSDOS_ROOT_INO;
-	else {
-		PRINTK(("fat_parent_ino: Debug 2\n"));
-		if ((prev = raw_scan(dir->i_sb,curr,MSDOS_DOTDOT,&zero,NULL,
-		    NULL,NULL)) < 0) {
-			PRINTK(("fat_parent_ino: Debug 3 prev=%d\n", prev));
-			if (!locked) fat_unlock_creation();
-			return prev;
-		}
-		PRINTK(("fat_parent_ino: Debug 4 prev=%d\n", prev));
-		if (prev == 0 && MSDOS_SB(dir->i_sb)->fat_bits == 32) {
-			prev = MSDOS_SB(dir->i_sb)->root_cluster;
-		}
-		if ((error = raw_scan(dir->i_sb,prev,NULL,&curr,&nr,NULL,
-		    NULL)) < 0) {
-			PRINTK(("fat_parent_ino: Debug 5 error=%d\n", error));
-			if (!locked) fat_unlock_creation();
-			return error;
-		}
-		PRINTK(("fat_parent_ino: Debug 6 nr=%d\n", nr));
-	}
-	if (!locked) fat_unlock_creation();
-	return nr;
-}
-
-/*
  * fat_subdirs counts the number of sub-directories of dir. It can be run
  * on directories being created.
  */
-
 int fat_subdirs(struct inode *dir)
 {
 	int count;
diff -urN linux-2.4.13-pre1/fs/fat/msbuffer.h linux/fs/fat/msbuffer.h
--- linux-2.4.13-pre1/fs/fat/msbuffer.h	Tue Sep  5 14:07:29 2000
+++ linux/fs/fat/msbuffer.h	Wed Dec 31 16:00:00 1969
@@ -1,14 +0,0 @@
-/* Number of bytes to readahead on disc access */
-#define FAT_READAHEAD (18*1024)
-
-struct buffer_head *fat_bread (struct super_block *sb, int block);
-struct buffer_head *fat_getblk (struct super_block *sb, int block);
-void fat_brelse (struct super_block *sb, struct buffer_head *bh);
-void fat_mark_buffer_dirty (struct super_block *sb,
-	 struct buffer_head *bh);
-void fat_set_uptodate (struct super_block *sb,
-	 struct buffer_head *bh,
-	 int val);
-int fat_is_uptodate (struct super_block *sb, struct buffer_head *bh);
-void fat_ll_rw_block (struct super_block *sb, int opr,
-	int nbreq, struct buffer_head *bh[32]);
diff -urN linux-2.4.13-pre1/fs/fat/tables.c linux/fs/fat/tables.c
--- linux-2.4.13-pre1/fs/fat/tables.c	Thu Oct 23 14:00:15 1997
+++ linux/fs/fat/tables.c	Wed Dec 31 16:00:00 1969
@@ -1,76 +0,0 @@
-/*
- * linux/fs/fat/tables.c
- *
- * Unicode escape translation tables for VFAT filename handling.
- * By Gordon Chaffee.
- *
- * Note: This file is used by all fat-based filesystems.
- */
-
-#include <linux/kernel.h>
-#include <linux/string.h>
-#include <linux/msdos_fs.h>
-
-unsigned char fat_uni2esc[64] = {
-	'0', '1', '2', '3', '4', '5', '6', '7',
-	'8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
-	'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
-	'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
-	'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
-	'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
-	'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
-	'u', 'v', 'w', 'x', 'y', 'z', '+', '-'
-};
-
-unsigned char fat_esc2uni[256] = {
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0x3e, 0xff, 0x3f, 0xff, 0xff, 
-	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
-	0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 
-	0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 
-	0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 
-	0x21, 0x22, 0x23, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 
-	0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 
-	0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 
-	0x3b, 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
-};
-
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-indent-level: 8
- * c-brace-imaginary-offset: 0
- * c-brace-offset: -8
- * c-argdecl-indent: 8
- * c-label-offset: -8
- * c-continued-statement-offset: 8
- * c-continued-brace-offset: 0
- * End:
- */
diff -urN linux-2.4.13-pre1/fs/fat/tables.h linux/fs/fat/tables.h
--- linux-2.4.13-pre1/fs/fat/tables.h	Tue Mar  5 03:03:27 1996
+++ linux/fs/fat/tables.h	Wed Dec 31 16:00:00 1969
@@ -1,35 +0,0 @@
-struct unicode_value {
-	unsigned char uni1;
-	unsigned char uni2;
-};
-
-extern unsigned char fat_a2alias[];		/* Ascii to alias name conversion table */
-extern struct unicode_value fat_a2uni[];	/* Ascii to Unicode conversion table */
-extern unsigned char *fat_uni2asc_pg[];
-
-/*
- * Since Linux can't deal with Unicode in filenames, these provide
- * a method to encode the Unicode names in a manner that the vfat
- * filesystem can them decode back to Unicode.  This conversion
- * only occurs when the filesystem was mounted with the 'uni_xlate' mount
- * option.
- */
-extern unsigned char fat_uni2code[];
-extern unsigned char fat_code2uni[];
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-indent-level: 8
- * c-brace-imaginary-offset: 0
- * c-brace-offset: -8
- * c-argdecl-indent: 8
- * c-label-offset: -8
- * c-continued-statement-offset: 8
- * c-continued-brace-offset: 0
- * End:
- */
diff -urN linux-2.4.13-pre1/fs/isofs/inode.c linux/fs/isofs/inode.c
--- linux-2.4.13-pre1/fs/isofs/inode.c	Sun Aug 12 10:56:56 2001
+++ linux/fs/isofs/inode.c	Mon Dec  3 23:17:33 2001
@@ -1184,11 +1184,14 @@
 		inode->i_size = isonum_733 (de->size);
 	}
 
-	/* There are defective discs out there - we do this to protect
-	   ourselves.  A cdrom will never contain more than 800Mb 
-	   .. but a DVD may be up to 1Gig (Ulrich Habel) */
-
-	if ((inode->i_size < 0 || inode->i_size > 1073741824) &&
+	/*
+	 * The ISO-9660 filesystem only stores 32 bits for file size.
+	 * mkisofs handles files up to 2GB-2 = 2147483646 = 0x7FFFFFFE bytes
+	 * in size. This is according to the large file summit paper from 1996.
+	 * WARNING: ISO-9660 filesystems > 1 GB and even > 2 GB are fully
+	 *	    legal. Do not prevent to use DVD's schilling@fokus.gmd.de
+	 */
+	if ((inode->i_size < 0 || inode->i_size > 0x7FFFFFFE) &&
 	    inode->i_sb->u.isofs_sb.s_cruft == 'n') {
 		printk(KERN_WARNING "Warning: defective CD-ROM.  "
 		       "Enabling \"cruft\" mount option.\n");
diff -urN linux-2.4.13-pre1/fs/msdos/namei.c linux/fs/msdos/namei.c
--- linux-2.4.13-pre1/fs/msdos/namei.c	Tue Aug 28 10:54:43 2001
+++ linux/fs/msdos/namei.c	Mon Dec  3 23:17:33 2001
@@ -17,8 +17,6 @@
 
 #include <asm/uaccess.h>
 
-#include "../fat/msbuffer.h"
-
 #define MSDOS_DEBUG 0
 #define PRINTK(x)
 
diff -urN linux-2.4.13-pre1/fs/open.c linux/fs/open.c
--- linux-2.4.13-pre1/fs/open.c	Fri Oct  5 12:23:53 2001
+++ linux/fs/open.c	Mon Dec  3 23:17:33 2001
@@ -104,7 +104,12 @@
 		goto out;
 	inode = nd.dentry->d_inode;
 
-	error = -EACCES;
+	/* For directories it's -EISDIR, for other non-regulars - -EINVAL */
+	error = -EISDIR;
+	if (S_ISDIR(inode->i_mode))
+		goto dput_and_out;
+
+	error = -EINVAL;
 	if (!S_ISREG(inode->i_mode))
 		goto dput_and_out;
 
@@ -146,10 +151,11 @@
 
 asmlinkage long sys_truncate(const char * path, unsigned long length)
 {
-	return do_sys_truncate(path, length);
+	/* on 32-bit boxen it will cut the range 2^31--2^32-1 off */
+	return do_sys_truncate(path, (long)length);
 }
 
-static inline long do_sys_ftruncate(unsigned int fd, loff_t length)
+static inline long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
 {
 	struct inode * inode;
 	struct dentry *dentry;
@@ -163,13 +169,24 @@
 	file = fget(fd);
 	if (!file)
 		goto out;
+
+	/* explicitly opened as large or we are on 64-bit box */
+	if (file->f_flags & O_LARGEFILE)
+		small = 0;
+
 	dentry = file->f_dentry;
 	inode = dentry->d_inode;
-	error = -EACCES;
+	error = -EINVAL;
 	if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE))
 		goto out_putf;
+
+	error = -EINVAL;
+	/* Cannot ftruncate over 2^31 bytes without large file support */
+	if (small && length > MAX_NON_LFS)
+		goto out_putf;
+
 	error = -EPERM;
-	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
+	if (IS_APPEND(inode))
 		goto out_putf;
 
 	error = locks_verify_truncate(inode, file, length);
@@ -183,7 +200,7 @@
 
 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length)
 {
-	return do_sys_ftruncate(fd, length);
+	return do_sys_ftruncate(fd, length, 1);
 }
 
 /* LFS versions of truncate are only needed on 32 bit machines */
@@ -195,7 +212,7 @@
 
 asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length)
 {
-	return do_sys_ftruncate(fd, length);
+	return do_sys_ftruncate(fd, length, 0);
 }
 #endif
 
@@ -507,7 +524,7 @@
 
 	error = -ENOENT;
 	if (!(inode = dentry->d_inode)) {
-		printk("chown_common: NULL inode\n");
+		printk(KERN_ERR "chown_common: NULL inode\n");
 		goto out;
 	}
 	error = -EROFS;
@@ -744,7 +761,7 @@
 #if 1
 	/* Sanity check */
 	if (files->fd[fd] != NULL) {
-		printk("get_unused_fd: slot %d not NULL!\n", fd);
+		printk(KERN_WARNING "get_unused_fd: slot %d not NULL!\n", fd);
 		files->fd[fd] = NULL;
 	}
 #endif
@@ -807,7 +824,7 @@
 	int retval;
 
 	if (!file_count(filp)) {
-		printk("VFS: Close: file count is 0\n");
+		printk(KERN_ERR "VFS: Close: file count is 0\n");
 		return 0;
 	}
 	retval = 0;
diff -urN linux-2.4.13-pre1/fs/partitions/check.c linux/fs/partitions/check.c
--- linux-2.4.13-pre1/fs/partitions/check.c	Mon Dec  3 23:17:24 2001
+++ linux/fs/partitions/check.c	Mon Dec  3 23:17:33 2001
@@ -386,6 +386,12 @@
 	if (!size || minors == 1)
 		return;
 
+	if (dev->sizes) {
+		dev->sizes[first_minor] = size >> (BLOCK_SIZE_BITS - 9);
+		for (i = first_minor + 1; i < end_minor; i++)
+			dev->sizes[i] = 0;
+	}
+	blk_size[dev->major] = dev->sizes;
 	check_partition(dev, MKDEV(dev->major, first_minor), 1 + first_minor);
 
  	/*
@@ -395,7 +401,6 @@
 	if (dev->sizes != NULL) {	/* optional safeguard in ll_rw_blk.c */
 		for (i = first_minor; i < end_minor; i++)
 			dev->sizes[i] = dev->part[i].nr_sects >> (BLOCK_SIZE_BITS - 9);
-		blk_size[dev->major] = dev->sizes;
 	}
 }
 
diff -urN linux-2.4.13-pre1/fs/reiserfs/Makefile linux/fs/reiserfs/Makefile
--- linux-2.4.13-pre1/fs/reiserfs/Makefile	Mon Jan 15 12:42:32 2001
+++ linux/fs/reiserfs/Makefile	Mon Dec  3 23:17:33 2001
@@ -13,6 +13,16 @@
 
 obj-m   := $(O_TARGET)
 
+# gcc -O2 (the kernel default)  is overaggressive on ppc when many inline
+# functions are used.  This causes the compiler to advance the stack
+# pointer out of the available stack space, corrupting kernel space,
+# and causing a panic. Since this behavior only affects ppc, this ifeq
+# will work around it. If any other architecture displays this behavior,
+# add it here.
+ifeq ($(shell uname -m),ppc) 
+EXTRA_CFLAGS := -O1
+endif
+
 include $(TOPDIR)/Rules.make
 
 TAGS:
diff -urN linux-2.4.13-pre1/fs/reiserfs/README linux/fs/reiserfs/README
--- linux-2.4.13-pre1/fs/reiserfs/README	Mon Jan 15 12:42:32 2001
+++ linux/fs/reiserfs/README	Mon Dec  3 23:17:33 2001
@@ -145,6 +145,10 @@
 
 Vitaly Fertman is doing fsck.
 
+Jeff Mahoney, of SuSE, contributed a few cleanup fixes, most notably
+the endian safe patches which allow ReiserFS to run on any platform
+supported by the Linux kernel.
+
 SuSE, IntegratedLinux.com, Ecila, MP3.com, bigstorage.com, and the
 Alpha PC Company made it possible for me to not have a day job
 anymore, and to dramatically increase our staffing.  Ecila funded
diff -urN linux-2.4.13-pre1/fs/reiserfs/bitmap.c linux/fs/reiserfs/bitmap.c
--- linux-2.4.13-pre1/fs/reiserfs/bitmap.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/bitmap.c	Mon Dec  3 23:17:33 2001
@@ -116,7 +116,7 @@
 
   reiserfs_prepare_for_journal(s, sbh, 1) ;
   /* update super block */
-  rs->s_free_blocks = cpu_to_le32 (le32_to_cpu (rs->s_free_blocks) + 1);
+  set_sb_free_blocks( rs, sb_free_blocks(rs) + 1 );
 
   journal_mark_dirty (th, s, sbh);
   s->s_dirt = 1;
@@ -304,8 +304,7 @@
 
   /* We continue the while loop if another process snatches our found
    * free block from us after we find it but before we successfully
-   * mark it as in use, or if we need to use sync to free up some
-   * blocks on the preserve list.  */
+   * mark it as in use */
 
   while (amount_needed--) {
     /* skip over any blocknrs already gotten last time. */
@@ -405,26 +404,26 @@
 
   reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
   /* update free block count in super block */
-  s->u.reiserfs_sb.s_rs->s_free_blocks = cpu_to_le32 (SB_FREE_BLOCKS (s) - init_amount_needed);
+  PUT_SB_FREE_BLOCKS( s, SB_FREE_BLOCKS(s) - init_amount_needed );
   journal_mark_dirty (th, s, SB_BUFFER_WITH_SB (s));
   s->s_dirt = 1;
 
   return CARRY_ON;
 }
 
-// this is called only by get_empty_nodes with for_preserve_list==0
+// this is called only by get_empty_nodes
 int reiserfs_new_blocknrs (struct reiserfs_transaction_handle *th, unsigned long * free_blocknrs,
 			    unsigned long search_start, int amount_needed) {
-  return do_reiserfs_new_blocknrs(th, free_blocknrs, search_start, amount_needed, 0/*for_preserve_list-priority*/, 0/*for_formatted*/, 0/*for_prealloc */) ;
+  return do_reiserfs_new_blocknrs(th, free_blocknrs, search_start, amount_needed, 0/*priority*/, 0/*for_formatted*/, 0/*for_prealloc */) ;
 }
 
 
-// called by get_new_buffer and by reiserfs_get_block with amount_needed == 1 and for_preserve_list == 0
+// called by get_new_buffer and by reiserfs_get_block with amount_needed == 1
 int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle *th, unsigned long * free_blocknrs,
 			      unsigned long search_start) {
   return do_reiserfs_new_blocknrs(th, free_blocknrs, search_start, 
                                   1/*amount_needed*/,
-				  0/*for_preserve_list-priority*/, 
+				  0/*priority*/, 
 				  1/*for formatted*/,
 				  0/*for prealloc */) ;
 }
@@ -666,10 +665,10 @@
   if (inode->u.reiserfs_i.i_prealloc_count < 0)
      reiserfs_warning("zam-4001:" __FUNCTION__ ": inode has negative prealloc blocks count.\n");
 #endif  
-  if (inode->u.reiserfs_i.i_prealloc_count > 0) {
+    if (inode->u.reiserfs_i.i_prealloc_count > 0) {
     __discard_prealloc(th, inode);
   }
-}
+      }
 
 void reiserfs_discard_all_prealloc (struct reiserfs_transaction_handle *th)
 {
@@ -684,6 +683,6 @@
     }
 #endif    
     __discard_prealloc(th, inode);
-  }
+    }
 }
 #endif
diff -urN linux-2.4.13-pre1/fs/reiserfs/dir.c linux/fs/reiserfs/dir.c
--- linux-2.4.13-pre1/fs/reiserfs/dir.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/dir.c	Mon Dec  3 23:17:33 2001
@@ -39,22 +39,10 @@
 };
 
 int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, int datasync) {
-  int ret = 0 ;
-  int windex ;
-  struct reiserfs_transaction_handle th ;
-
   lock_kernel();
-
-  journal_begin(&th, dentry->d_inode->i_sb, 1) ;
-  windex = push_journal_writer("dir_fsync") ;
-  reiserfs_prepare_for_journal(th.t_super, SB_BUFFER_WITH_SB(th.t_super), 1) ;
-  journal_mark_dirty(&th, dentry->d_inode->i_sb, SB_BUFFER_WITH_SB (dentry->d_inode->i_sb)) ;
-  pop_journal_writer(windex) ;
-  journal_end_sync(&th, dentry->d_inode->i_sb, 1) ;
-
-  unlock_kernel();
-
-  return ret ;
+  reiserfs_commit_for_inode(dentry->d_inode) ;
+  unlock_kernel() ;
+  return 0 ;
 }
 
 
@@ -210,24 +198,3 @@
     reiserfs_check_path(&path_to_entry) ;
     return 0;
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff -urN linux-2.4.13-pre1/fs/reiserfs/do_balan.c linux/fs/reiserfs/do_balan.c
--- linux-2.4.13-pre1/fs/reiserfs/do_balan.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/do_balan.c	Mon Dec  3 23:17:33 2001
@@ -104,20 +104,9 @@
     switch (flag) {
     case M_DELETE:   /* delete item in S[0] */
 
-	 RFALSE( le16_to_cpu (ih->ih_item_len) + IH_SIZE != -tb->insert_size [0],
-		 "vs-12013: mode Delete, insert size %d, ih to be deleted %h", 
-		 ih);
-
-#if 0 /* rigth delim key not supported */
-	if ( ! item_pos && (! tb->L[0] || COMP_KEYS(B_PRIGHT_DELIM_KEY(tb->L[0]), B_N_PKEY(tbS0, 0))) ) {
-	    print_cur_tb ("12015");
-	    reiserfs_panic (tb->tb_sb, "PAP-12015: balance_leaf_when_delete: L0's rkey does not match to 1st key of S0: "
-			    "rkey in L %k, first key in S0 %k, rkey in CFL %k",
-			    tb->L[0] ? B_PRIGHT_DELIM_KEY(tb->L[0]) : 0, 
-			    B_N_PKEY(tbS0, 0),
-			    tb->CFL[0] ? B_N_PDELIM_KEY(tb->CFL[0],tb->lkey[0]) : 0);
-	}
-#endif
+	RFALSE( ih_item_len(ih) + IH_SIZE != -tb->insert_size[0],
+	        "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
+                ih);
 
 	bi.tb = tb;
 	bi.bi_bh = tbS0;
@@ -128,18 +117,10 @@
 	if ( ! item_pos && tb->CFL[0] ) {
 	    if ( B_NR_ITEMS(tbS0) ) {
 		replace_key(tb, tb->CFL[0],tb->lkey[0],tbS0,0);
-#if 0 /* right delim key support */
-		copy_key(B_PRIGHT_DELIM_KEY(tb->L[0]), B_N_PKEY(tbS0, 0));
-		reiserfs_mark_buffer_dirty (tb->L[0], 0);
-#endif
 	    }
 	    else {
 		if ( ! PATH_H_POSITION (tb->tb_path, 1) )
 		    replace_key(tb, tb->CFL[0],tb->lkey[0],PATH_H_PPARENT(tb->tb_path, 0),0);
-#if 0 /* right delim key support */
-		copy_key(B_PRIGHT_DELIM_KEY(tb->L[0]), B_PRIGHT_DELIM_KEY(tbS0));
-		reiserfs_mark_buffer_dirty (tb->L[0], 0);
-#endif
 	    }
 	} 
 
@@ -155,14 +136,6 @@
 	bi.bi_position = PATH_H_POSITION (tb->tb_path, 1);
 	if (is_direntry_le_ih (ih)) {
 
-#ifdef CONFIG_REISERFS_CHECK
-#if 0 /* right delim key support */
-	    if ( ! item_pos && ! pos_in_item && (! tb->L[0] || COMP_KEYS(B_PRIGHT_DELIM_KEY(tb->L[0]), 
-									 B_N_PKEY(tbS0, 0))) )
-		reiserfs_panic(tb->tb_sb, "PAP-12025: balance_leaf_when_delete: illegal right delimiting key");
-#endif
-#endif
-
 	    /* UFS unlink semantics are such that you can only delete one directory entry at a time. */
 	    /* when we cut a directory tb->insert_size[0] means number of entries to be cut (always 1) */
 	    tb->insert_size[0] = -1;
@@ -174,16 +147,12 @@
 
 	    if ( ! item_pos && ! pos_in_item && tb->CFL[0] ) {
 		replace_key(tb, tb->CFL[0],tb->lkey[0],tbS0,0);
-#if 0/* right delim key support */
-		copy_key(B_PRIGHT_DELIM_KEY(tb->L[0]), B_N_PKEY(tbS0, 0));
-		reiserfs_mark_buffer_dirty (tb->L[0], 0);
-#endif
 	    }
 	} else {
 	    leaf_cut_from_buffer (&bi, item_pos, pos_in_item, -tb->insert_size[0]);
 
-	    RFALSE( ! ih->ih_item_len,
-		    "PAP-12035: cut must leave non-zero dynamic length of item");
+	    RFALSE( ! ih_item_len(ih),
+		"PAP-12035: cut must leave non-zero dynamic length of item");
 	}
 	break;
     }
@@ -208,17 +177,9 @@
 		    if ( PATH_H_POSITION (tb->tb_path, 1) == 0 && 1 < B_NR_ITEMS(tb->FR[0]) )
 			replace_key(tb, tb->CFL[0],tb->lkey[0],tb->FR[0],1);
 
-		    /* update right_delimiting_key field */
-#if 0
-		    copy_key (B_PRIGHT_DELIM_KEY (tb->L[0]), B_PRIGHT_DELIM_KEY (tb->R[0]));
-#endif
 		    leaf_move_items (LEAF_FROM_S_TO_L, tb, n, -1, 0);
 		    leaf_move_items (LEAF_FROM_R_TO_L, tb, B_NR_ITEMS(tb->R[0]), -1, 0);
 
-#if 0/*preserve list*/
-		    preserve_invalidate(tb, tbS0, tb->L[0]); 
-		    preserve_invalidate(tb, tb->R[0], tb->L[0]);
-#endif
 		    reiserfs_invalidate_buffer (tb, tbS0);
 		    reiserfs_invalidate_buffer (tb, tb->R[0]);
 
@@ -231,11 +192,6 @@
 		/* right_delimiting_key is correct in R[0] */
 		replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0);
 
-#if 0
-		/* mark tb->R[0] as suspected recipient */
-		preserve_invalidate(tb,tbS0, tb->R[0]);
-		preserve_invalidate(tb,tb->L[0], tb->R[0]); 
-#endif
 		reiserfs_invalidate_buffer (tb, tbS0);
 		reiserfs_invalidate_buffer (tb, tb->L[0]);
 
@@ -247,9 +203,6 @@
 	    /* all contents of L[0] and S[0] will be in L[0] */
 	    leaf_shift_left(tb, n, -1);
 
-#if 0/*preserve list*/
-	    preserve_invalidate(tb, tbS0, tb->L[0]);  /* preserved, shifting */
-#endif
 	    reiserfs_invalidate_buffer (tb, tbS0);
 
 	    return 0;
@@ -272,10 +225,6 @@
 	leaf_shift_left (tb, tb->lnum[0], tb->lbytes);
 	leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
 
-#if 0/*preserve list*/
-	preserve_invalidate (tb, tbS0, tb->L[0]);
-	mark_suspected_recipient (tb->tb_sb, tb->R[0]);
-#endif
 	reiserfs_invalidate_buffer (tb, tbS0);
 
 	return 0;
@@ -284,9 +233,6 @@
     if ( tb->rnum[0] == -1 ) {
 	/* all contents of R[0] and S[0] will be in R[0] */
 	leaf_shift_right(tb, n, -1);
-#if 0/*preserve list*/
-	preserve_invalidate(tb, tbS0, tb->R[0]); 
-#endif
 	reiserfs_invalidate_buffer (tb, tbS0);
 	return 0;
     }
@@ -310,10 +256,6 @@
     )
 {
     struct buffer_head * tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#if 0/*preserve list*/
-    struct buffer_head * tbF0 = PATH_H_PPARENT (tb->tb_path, 0);
-    int S0_b_item_order = PATH_H_B_ITEM_ORDER (tb->tb_path, 0);
-#endif
     int item_pos = PATH_LAST_POSITION (tb->tb_path);	/*  index into the array of item headers in S[0] 
 							    of the affected item */
     struct buffer_info bi;
@@ -344,7 +286,7 @@
   
     zeros_num = 0;
     if (flag == M_INSERT && body == 0)
-	zeros_num = le16_to_cpu (ih->ih_item_len); 
+	zeros_num = ih_item_len( ih );
 
     pos_in_item = tb->tb_path->pos_in_item;
     /* for indirect item pos_in_item is measured in unformatted node
@@ -366,27 +308,18 @@
 		    int new_item_len;
 		    int version;
 
-		    RFALSE( !is_direct_le_ih (ih),
+		    RFALSE (!is_direct_le_ih (ih),
 			    "PAP-12075: only direct inserted item can be broken. %h", ih);
 		    ret_val = leaf_shift_left (tb, tb->lnum[0]-1, -1);
-		    /* when reading the if conditions preceding the subsequent preserve_shifted
-		       lines understand that their goal is to determine if all that we are
-		       shifting is the new data being added */
-#if 0/*preserve list*/
-		    if (tb->lnum[0] - 1 > 0) {
-			preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->L[0]);
-			tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-		    }
-#endif
 
 		    /* Calculate item length to insert to S[0] */
-		    new_item_len = le16_to_cpu (ih->ih_item_len) - tb->lbytes;
+		    new_item_len = ih_item_len(ih) - tb->lbytes;
 		    /* Calculate and check item length to insert to L[0] */
-		    ih->ih_item_len -= new_item_len;
+		    put_ih_item_len(ih, ih_item_len(ih) - new_item_len );
 
-		    RFALSE( (int)(ih->ih_item_len) <= 0,
+		    RFALSE( ih_item_len(ih) <= 0,
 			    "PAP-12080: there is nothing to insert into L[0]: ih_item_len=%d",
-			    (int)ih->ih_item_len);
+                            ih_item_len(ih));
 
 		    /* Insert new item into L[0] */
 		    bi.tb = tb;
@@ -394,14 +327,14 @@
 		    bi.bi_parent = tb->FL[0];
 		    bi.bi_position = get_left_neighbor_position (tb, 0);
 		    leaf_insert_into_buf (&bi, n + item_pos - ret_val, ih, body,
-					  zeros_num > ih->ih_item_len ? ih->ih_item_len : zeros_num);
+					  zeros_num > ih_item_len(ih) ? ih_item_len(ih) : zeros_num);
 
 		    version = ih_version (ih);
 
 		    /* Calculate key component, item length and body to insert into S[0] */
-		    set_le_key_k_offset (ih_version (ih), &(ih->ih_key),
-					 le_key_k_offset (ih_version (ih), &(ih->ih_key)) + tb->lbytes);
-		    ih->ih_item_len = cpu_to_le16 (new_item_len);
+                    set_le_ih_k_offset( ih, le_ih_k_offset( ih ) + tb->lbytes );
+
+		    put_ih_item_len( ih, new_item_len );
 		    if ( tb->lbytes >  zeros_num ) {
 			body += (tb->lbytes - zeros_num);
 			zeros_num = 0;
@@ -409,30 +342,19 @@
 		    else
 			zeros_num -= tb->lbytes;
 
-		    RFALSE( (int)(ih->ih_item_len) <= 0,
-			    "PAP-12085: there is nothing to insert into S[0]: ih_item_len=%d",
-			    (int)ih->ih_item_len);
+		    RFALSE( ih_item_len(ih) <= 0,
+			"PAP-12085: there is nothing to insert into S[0]: ih_item_len=%d",
+			ih_item_len(ih));
 		} else {
 		    /* new item in whole falls into L[0] */
 		    /* Shift lnum[0]-1 items to L[0] */
 		    ret_val = leaf_shift_left(tb, tb->lnum[0]-1, tb->lbytes);
-#if 0/*preserve list*/
-		    if (tb->lnum[0] > 1) {
-			preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->L[0]);
-			tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-		    }
-#endif
 		    /* Insert new item into L[0] */
 		    bi.tb = tb;
 		    bi.bi_bh = tb->L[0];
 		    bi.bi_parent = tb->FL[0];
 		    bi.bi_position = get_left_neighbor_position (tb, 0);
 		    leaf_insert_into_buf (&bi, n + item_pos - ret_val, ih, body, zeros_num);
-#if 0/*preserve list*/
-		    if (tb->preserve_mode == PRESERVE_INDIRECT_TO_DIRECT){
-			mark_suspected_recipient (tb->tb_sb, bi.bi_bh);
-		    }
-#endif
 		    tb->insert_size[0] = 0;
 		    zeros_num = 0;
 		}
@@ -454,10 +376,6 @@
 							  
 			    /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 entries from given directory item */
 			    ret_val = leaf_shift_left(tb, tb->lnum[0], tb->lbytes - 1);
-#if 0/*preserve list*/
-			    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->L[0]);
-			    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 			    if ( ret_val && ! item_pos ) {
 				pasted =  B_N_PITEM_HEAD(tb->L[0],B_NR_ITEMS(tb->L[0])-1);
 				l_pos_in_item += I_ENTRY_COUNT(pasted) - (tb->lbytes-1);
@@ -485,10 +403,6 @@
 			    /* new directory item doesn't fall into L[0] */
 			    /* Shift lnum[0]-1 items in whole. Shift lbytes directory entries from directory item number lnum[0] */
 			    leaf_shift_left (tb, tb->lnum[0], tb->lbytes);
-#if 0/*preserve list*/
-			    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->L[0]);
-			    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 			}
 			/* Calculate new position to append in item body */
 			pos_in_item -= tb->lbytes;
@@ -496,11 +410,12 @@
 		    else {
 			/* regular object */
 			RFALSE( tb->lbytes <= 0,
-				"PAP-12095: there is nothing to shift to L[0]. lbytes=%d",
+			        "PAP-12095: there is nothing to shift to L[0]. lbytes=%d",
 				tb->lbytes);
-			RFALSE( pos_in_item != B_N_PITEM_HEAD(tbS0, item_pos)->ih_item_len,
-				"PAP-12100: incorrect position to paste: item_len=%d, pos_in_item=%d",
-				B_N_PITEM_HEAD(tbS0,item_pos)->ih_item_len, pos_in_item);
+			RFALSE( pos_in_item != ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)),
+                                "PAP-12100: incorrect position to paste: item_len=%d, pos_in_item=%d",
+				ih_item_len(B_N_PITEM_HEAD(tbS0,item_pos)), pos_in_item);
+
 			if ( tb->lbytes >= pos_in_item ) {
 			    /* appended item will be in L[0] in whole */
 			    int l_n;
@@ -515,11 +430,7 @@
 				    "PAP-12105: there is nothing to paste into L[0]. insert_size=%d",
 				    tb->insert_size[0]);
 			    ret_val =  leaf_shift_left(tb,tb->lnum[0], 
-						       B_N_PITEM_HEAD(tbS0,item_pos)->ih_item_len);
-#if 0/*preserve list*/
-			    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->L[0]);
-			    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
+						       ih_item_len(B_N_PITEM_HEAD(tbS0,item_pos)));
 			    /* Append to body of item in L[0] */
 			    bi.tb = tb;
 			    bi.bi_bh = tb->L[0];
@@ -527,7 +438,7 @@
 			    bi.bi_position = get_left_neighbor_position (tb, 0);
 			    leaf_paste_in_buffer(
 				&bi,n + item_pos - ret_val,
-				B_N_PITEM_HEAD(tb->L[0],n+item_pos-ret_val)->ih_item_len,
+				ih_item_len( B_N_PITEM_HEAD(tb->L[0],n+item_pos-ret_val)),
 				l_n,body, zeros_num > l_n ? l_n : zeros_num
 				);
 
@@ -541,15 +452,13 @@
 			    {
 			      int version;
 
-			      version = le16_to_cpu (B_N_PITEM_HEAD (tbS0, 0)->ih_version);
+			      version = ih_version (B_N_PITEM_HEAD (tbS0, 0));
 			      set_le_key_k_offset (version, B_N_PKEY (tbS0, 0), 
 						   le_key_k_offset (version, B_N_PKEY (tbS0, 0)) + l_n);
+			      version = ih_version (B_N_PITEM_HEAD(tb->CFL[0],tb->lkey[0]));
 			      set_le_key_k_offset (version, B_N_PDELIM_KEY(tb->CFL[0],tb->lkey[0]),
 						   le_key_k_offset (version, B_N_PDELIM_KEY(tb->CFL[0],tb->lkey[0])) + l_n);
 			    }
-			    /*    k_offset (B_N_PKEY (tbS0, 0)) += l_n;
-				  k_offset (B_N_PDELIM_KEY(tb->CFL[0],tb->lkey[0])) += l_n;
-				  k_offset (B_PRIGHT_DELIM_KEY(tb->L[0])) += l_n;*/
 
 			    /* Calculate new body, position in item and insert_size[0] */
 			    if ( l_n > zeros_num ) {
@@ -581,10 +490,6 @@
 
 			    /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */
 			    leaf_shift_left(tb,tb->lnum[0],tb->lbytes);
-#if 0/*preserve list*/
-			    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->L[0]);
-			    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 			}
 		    }
 		}
@@ -597,17 +502,13 @@
 			    /* then increment pos_in_item by the size of the last item in L[0] */
 			    pasted = B_N_PITEM_HEAD(tb->L[0],n-1);
 			    if ( is_direntry_le_ih (pasted) )
-				pos_in_item += le16_to_cpu (pasted->u.ih_entry_count);
+				pos_in_item += ih_entry_count(pasted);
 			    else
-				pos_in_item += le16_to_cpu (pasted->ih_item_len);
+				pos_in_item += ih_item_len(pasted);
 			}
 
 		    /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */
 		    ret_val = leaf_shift_left(tb,tb->lnum[0],tb->lbytes);
-#if 0/*preserve list*/
-		    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->L[0]);
-		    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 		    /* Append to body of item in L[0] */
 		    bi.tb = tb;
 		    bi.bi_bh = tb->L[0];
@@ -637,10 +538,6 @@
 	} else { 
 	    /* new item doesn't fall into L[0] */
 	    leaf_shift_left(tb,tb->lnum[0],tb->lbytes);
-#if 0/*preserve list*/
-	    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->L[0]);
-	    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 	}
     }	/* tb->lnum[0] > 0 */
 
@@ -667,22 +564,16 @@
 			    ih);
 
 		    leaf_shift_right(tb,tb->rnum[0]-1,-1);
-#if 0/*preserve list*/
-		    if (tb->rnum[0]>1) {
-			preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->R[0]);
-			tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-		    }
-#endif
 
-		    version = le16_to_cpu (ih->ih_version);
+		    version = ih_version(ih);
 		    /* Remember key component and item length */
-		    old_key_comp = le_key_k_offset (version, &(ih->ih_key));
-		    old_len = le16_to_cpu (ih->ih_item_len);
+                    old_key_comp = le_ih_k_offset( ih );
+		    old_len = ih_item_len(ih);
 
 		    /* Calculate key component and item length to insert into R[0] */
-		    offset = le_key_k_offset (version, &(ih->ih_key)) + (old_len - tb->rbytes);
-		    set_le_key_k_offset (version, &(ih->ih_key), offset);
-		    ih->ih_item_len = cpu_to_le16 (tb->rbytes);
+                    offset = le_ih_k_offset( ih ) + (old_len - tb->rbytes );
+                    set_le_ih_k_offset( ih, offset );
+		    put_ih_item_len( ih, tb->rbytes);
 		    /* Insert part of the item into R[0] */
 		    bi.tb = tb;
 		    bi.bi_bh = tb->R[0];
@@ -704,8 +595,8 @@
 		    replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0);
 
 		    /* Calculate key component and item length to insert into S[0] */
-		    set_le_key_k_offset (version, &(ih->ih_key), old_key_comp);
-		    ih->ih_item_len = cpu_to_le16 (old_len - tb->rbytes);
+                    set_le_ih_k_offset( ih, old_key_comp );
+		    put_ih_item_len( ih, old_len - tb->rbytes );
 
 		    tb->insert_size[0] -= tb->rbytes;
 
@@ -714,33 +605,16 @@
 		{					  
 		    /* Shift rnum[0]-1 items to R[0] */
 		    ret_val = leaf_shift_right(tb,tb->rnum[0]-1,tb->rbytes);
-#if 0/*preserve list*/
-		    if (tb->rnum[0]>1) {
-			preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->R[0]);
-			tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-		    }
-#endif
 		    /* Insert new item into R[0] */
 		    bi.tb = tb;
 		    bi.bi_bh = tb->R[0];
 		    bi.bi_parent = tb->FR[0];
 		    bi.bi_position = get_right_neighbor_position (tb, 0);
 		    leaf_insert_into_buf (&bi, item_pos - n + tb->rnum[0] - 1, ih, body, zeros_num);
-#if 0/*preserve list*/
-		    if (tb->preserve_mode == PRESERVE_INDIRECT_TO_DIRECT){
-			mark_suspected_recipient (tb->tb_sb, bi.bi_bh);
-		    }
-#endif
 
-		    /* If we insert new item in the begin of R[0] change the right delimiting key */
 		    if ( item_pos - n + tb->rnum[0] - 1 == 0 ) {
 			replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0);
 
-#if 0
-			/* update right delimiting key */
-			copy_key(B_PRIGHT_DELIM_KEY(tbS0), &(ih->ih_key));
-			reiserfs_mark_buffer_dirty (tbS0, 0);
-#endif
 		    }
 		    zeros_num = tb->insert_size[0] = 0;
 		}
@@ -748,10 +622,6 @@
 	    else /* new item or part of it doesn't fall into R[0] */
 	    {
 		leaf_shift_right(tb,tb->rnum[0],tb->rbytes);
-#if 0/*preserve list*/
-		preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->R[0]);
-		tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 	    }
 	    break;
 
@@ -779,13 +649,6 @@
 				    tb->rbytes, entry_count);
 			    /* Shift rnum[0]-1 items in whole. Shift rbytes-1 directory entries from directory item number rnum[0] */
 			    leaf_shift_right(tb,tb->rnum[0],tb->rbytes - 1);
-#if 0/*preserve list*/
-			    /* if we are shifting more than just the new entry */
-			    if (tb->rbytes > 1 || tb->rnum[0] > 1) {
-				preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->R[0]);
-				tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-			    }
-#endif
 			    /* Paste given directory entry to directory item */
 			    paste_entry_position = pos_in_item - entry_count + tb->rbytes - 1;
 			    bi.tb = tb;
@@ -803,10 +666,6 @@
 			    if ( paste_entry_position == 0 ) {
 				/* change delimiting keys */
 				replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0);
-#if 0
-				copy_key(B_PRIGHT_DELIM_KEY(tbS0), B_N_PKEY(tb->R[0], 0));
-				reiserfs_mark_buffer_dirty (tbS0, 0);
-#endif
 			    }
 
 			    tb->insert_size[0] = 0;
@@ -815,10 +674,6 @@
 			else /* new directory entry doesn't fall into R[0] */
 			{
 			    leaf_shift_right(tb,tb->rnum[0],tb->rbytes);
-#if 0/*preserve list*/
-			    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->R[0]);
-			    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 			}
 		    }
 		    else /* regular object */
@@ -830,18 +685,11 @@
 			if ( (n_shift = tb->rbytes - tb->insert_size[0]) < 0 )
 			    n_shift = 0;
 
-			RFALSE( pos_in_item != B_N_PITEM_HEAD (tbS0, item_pos)->ih_item_len,
-				"PAP-12155: invalid position to paste. ih_item_len=%d, pos_in_item=%d",
-				pos_in_item, B_N_PITEM_HEAD(tbS0,item_pos)->ih_item_len);
+			RFALSE(pos_in_item != ih_item_len(B_N_PITEM_HEAD (tbS0, item_pos)),
+			       "PAP-12155: invalid position to paste. ih_item_len=%d, pos_in_item=%d",
+                               pos_in_item, ih_item_len( B_N_PITEM_HEAD(tbS0,item_pos)));
 
 			leaf_shift_right(tb,tb->rnum[0],n_shift);
-#if 0/*preserve list*/
-			/* if we are shifting an old part from the appended item or more than the appended item is going into R */
-			if (n_shift || tb->rnum[0] > 1) {
-			    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->R[0]);
-			    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-			}
-#endif
 			/* Calculate number of bytes which must remain in body after appending to R[0] */
 			if ( (n_rem = tb->insert_size[0] - tb->rbytes) < 0 )
 			    n_rem = 0;
@@ -859,11 +707,6 @@
 		  k_offset (B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0])) += n_rem;*/
 			do_balance_mark_internal_dirty (tb, tb->CFR[0], 0);
 
-#if 0
-			set_le_key_k_offset (B_PRIGHT_DELIM_KEY(tbS0), le_key_k_offset (B_PRIGHT_DELIM_KEY(tbS0)) + n_rem);
-/*		  k_offset (B_PRIGHT_DELIM_KEY(tbS0)) += n_rem;*/
-			reiserfs_mark_buffer_dirty (tbS0, 0);
-#endif
 			/* Append part of body into R[0] */
 			bi.tb = tb;
 			bi.bi_bh = tb->R[0];
@@ -899,10 +742,6 @@
 		    struct item_head * pasted;
 
 		    ret_val = leaf_shift_right(tb,tb->rnum[0],tb->rbytes);
-#if 0/*preserve list*/
-		    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->R[0]);
-		    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 		    /* append item in R[0] */
 		    if ( pos_in_item >= 0 ) {
 			bi.tb = tb;
@@ -927,10 +766,6 @@
 
 			    /* update delimiting keys */
 			    replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0);
-#if 0
-			    copy_key(B_PRIGHT_DELIM_KEY(tbS0),B_N_PKEY(tb->R[0], 0));
-			    reiserfs_mark_buffer_dirty (tbS0, 0);
-#endif
 			}
 		    }
 
@@ -942,10 +777,6 @@
 	    else /* new item doesn't fall into R[0] */
 	    {
 		leaf_shift_right(tb,tb->rnum[0],tb->rbytes);
-#if 0/*preserve list*/
-		preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, tb->R[0]);
-		tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 	    }
 	    break;
 	default:    /* cases d and t */
@@ -967,7 +798,7 @@
     if ( tb->blknum[0] == 0 ) { /* node S[0] is empty now */
 
 	RFALSE( ! tb->lnum[0] || ! tb->rnum[0],
-		"PAP-12190: lnum and rnum must not be zero");
+	        "PAP-12190: lnum and rnum must not be zero");
 	/* if insertion was done before 0-th position in R[0], right
 	   delimiting key of the tb->L[0]'s and left delimiting key are
 	   not set correctly */
@@ -1000,7 +831,7 @@
 	S_new[i] = get_FEB(tb);
 
 	/* initialized block type and tree level */
-	B_BLK_HEAD(S_new[i])->blk_level = cpu_to_le16 (DISK_LEAF_NODE_LEVEL);
+        set_blkh_level( B_BLK_HEAD(S_new[i]), DISK_LEAF_NODE_LEVEL );
 
 
 	n = B_NR_ITEMS(tbS0);
@@ -1024,22 +855,16 @@
 
 		    /* Move snum[i]-1 items from S[0] to S_new[i] */
 		    leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i] - 1, -1, S_new[i]);
-#if 0/*preserve list*/
-		    if (snum[i] > 1 ) {
-			preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, S_new[i]);
-			tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-		    }
-#endif
 		    /* Remember key component and item length */
 		    version = ih_version (ih);
-		    old_key_comp = le_key_k_offset (version, &(ih->ih_key));
-		    old_len = le16_to_cpu (ih->ih_item_len);
+                    old_key_comp = le_ih_k_offset( ih );
+		    old_len = ih_item_len(ih);
 
 		    /* Calculate key component and item length to insert into S_new[i] */
-		    set_le_key_k_offset (version, &(ih->ih_key), 
-					 le_key_k_offset (version, &(ih->ih_key)) + (old_len - sbytes[i]));
+                    set_le_ih_k_offset( ih,
+                                le_ih_k_offset(ih) + (old_len - sbytes[i] ) );
 
-		    ih->ih_item_len = cpu_to_le16 (sbytes[i]);
+		    put_ih_item_len( ih, sbytes[i] );
 
 		    /* Insert part of the item into S_new[i] before 0-th item */
 		    bi.tb = tb;
@@ -1047,21 +872,21 @@
 		    bi.bi_parent = 0;
 		    bi.bi_position = 0;
 
-		    if ( le_key_k_offset (version, &(ih->ih_key)) - old_key_comp > zeros_num ) {
+		    if ( le_ih_k_offset (ih) - old_key_comp > zeros_num ) {
 			r_zeros_number = 0;
-			r_body = body + (le_key_k_offset (version, &(ih->ih_key)) - old_key_comp) - zeros_num;
+			r_body = body + (le_ih_k_offset(ih) - old_key_comp) - zeros_num;
 		    }
 		    else {
 			r_body = body;
-			r_zeros_number = zeros_num - (le_key_k_offset (version, &(ih->ih_key)) - old_key_comp);
+			r_zeros_number = zeros_num - (le_ih_k_offset (ih) - old_key_comp);
 			zeros_num -= r_zeros_number;
 		    }
 
 		    leaf_insert_into_buf (&bi, 0, ih, r_body, r_zeros_number);
 
 		    /* Calculate key component and item length to insert into S[i] */
-		    set_le_key_k_offset (version, &(ih->ih_key), old_key_comp);
-		    ih->ih_item_len = cpu_to_le16 (old_len - sbytes[i]);
+                    set_le_ih_k_offset( ih, old_key_comp );
+		    put_ih_item_len( ih, old_len - sbytes[i] );
 		    tb->insert_size[0] -= sbytes[i];
 		}
 		else /* whole new item falls into S_new[i] */
@@ -1075,11 +900,6 @@
 		    bi.bi_parent = 0;
 		    bi.bi_position = 0;
 		    leaf_insert_into_buf (&bi, item_pos - n + snum[i] - 1, ih, body, zeros_num);
-#if 0/*preserve list*/
-		    if (tb->preserve_mode == PRESERVE_INDIRECT_TO_DIRECT){
-			mark_suspected_recipient (tb->tb_sb, bi.bi_bh);
-		    }
-#endif
 
 		    zeros_num = tb->insert_size[0] = 0;
 		}
@@ -1088,10 +908,6 @@
 	    else /* new item or it part don't falls into S_new[i] */
 	    {
 		leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i], S_new[i]);
-#if 0/*preserve list*/
-		preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, S_new[i]);
-		tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 	    }
 	    break;
 
@@ -1110,7 +926,7 @@
 
 			int entry_count;
 		
-			entry_count = le16_to_cpu (aux_ih->u.ih_entry_count);
+			entry_count = ih_entry_count(aux_ih);
 
 			if ( entry_count - sbytes[i] < pos_in_item  && pos_in_item <= entry_count ) {
 			    /* new directory entry falls into S_new[i] */
@@ -1123,14 +939,6 @@
 
 			    /* Shift snum[i]-1 items in whole. Shift sbytes[i] directory entries from directory item number snum[i] */
 			    leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i]-1, S_new[i]);
-#if 0/*preserve list*/
-			    /* if more than the affected item is shifted, or if more than
-			       one entry (from the affected item) is shifted */
-			    if (snum[i] > 1 || sbytes[i] > 1) {
-				preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, S_new[i]);
-				tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-			    }
-#endif
 			    /* Paste given directory entry to directory item */
 			    bi.tb = tb;
 			    bi.bi_bh = S_new[i];
@@ -1155,9 +963,9 @@
 			int n_shift, n_rem, r_zeros_number;
 			const char * r_body;
 
-			RFALSE( pos_in_item != B_N_PITEM_HEAD(tbS0,item_pos)->ih_item_len ||
-				tb->insert_size[0] <= 0,
-				"PAP-12225: item too short or insert_size <= 0");
+			RFALSE( pos_in_item != ih_item_len(B_N_PITEM_HEAD(tbS0,item_pos)) ||
+			        tb->insert_size[0] <= 0,
+			        "PAP-12225: item too short or insert_size <= 0");
 
 			/* Calculate number of bytes which must be shifted from appended item */
 			n_shift = sbytes[i] - tb->insert_size[0];
@@ -1195,8 +1003,7 @@
 				    reiserfs_panic (tb->tb_sb, "PAP-12230: balance_leaf: invalid action with indirect item");
 				set_ih_free_space (tmp, ((struct unfm_nodeinfo*)body)->unfm_freespace);
 			    }
-			    set_le_key_k_offset (ih_version (tmp), &tmp->ih_key, 
-						 le_key_k_offset (ih_version (tmp), &tmp->ih_key) + n_rem);
+                            set_le_ih_k_offset( tmp, le_ih_k_offset(tmp) + n_rem );
 			}
 
 			tb->insert_size[0] = n_rem;
@@ -1213,17 +1020,12 @@
 #ifdef CONFIG_REISERFS_CHECK
 		    struct item_head * ih = B_N_PITEM_HEAD(tbS0,item_pos);
 
-		    if ( ! is_direntry_le_ih(ih) && (pos_in_item != ih->ih_item_len ||
+		    if ( ! is_direntry_le_ih(ih) && (pos_in_item != ih_item_len(ih) ||
 						     tb->insert_size[0] <= 0) )
 			reiserfs_panic (tb->tb_sb, "PAP-12235: balance_leaf: pos_in_item must be equal to ih_item_len");
 #endif /* CONFIG_REISERFS_CHECK */
 
 		    ret_val = leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i], S_new[i]);
-#if 0/*preserve list*/
-		    /* we must preserve that which we are pasting onto the end of and shifting */
-		    preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, S_new[i]);
-		    tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 
 		    RFALSE( ret_val,
 			    "PAP-12240: unexpected value returned by leaf_move_items (%d)",
@@ -1255,10 +1057,6 @@
 	    else /* pasted item doesn't fall into S_new[i] */
 	    {
 		leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i], S_new[i]);
-#if 0/*preserve list*/
-		preserve_shifted(tb, &(PATH_PLAST_BUFFER (tb->tb_path)), tbF0, S0_b_item_order, S_new[i]);
-		tbS0 = PATH_PLAST_BUFFER (tb->tb_path);
-#endif
 	    }
 	    break;
 	default:    /* cases d and t */
@@ -1275,12 +1073,6 @@
 		   buffer_journal_dirty(S_new[i]))), 
 		"PAP-12247: S_new[%d] : (%b)\n", i, S_new[i]);
 
-#if 0
-	/* update right_delimiting_key fields */
-	copy_key (B_PRIGHT_DELIM_KEY (S_new[i]), B_PRIGHT_DELIM_KEY (tbS0));
-	copy_key (B_PRIGHT_DELIM_KEY (tbS0), B_N_PKEY (S_new[i], 0));
-	reiserfs_mark_buffer_dirty (tbS0, 0);
-#endif
 
     }
 
@@ -1297,29 +1089,12 @@
 	    bi.bi_parent = PATH_H_PPARENT (tb->tb_path, 0);
 	    bi.bi_position = PATH_H_POSITION (tb->tb_path, 1);
 	    leaf_insert_into_buf (&bi, item_pos, ih, body, zeros_num);
-#if 0/*preserve list*/
-	    if (tb->preserve_mode == PRESERVE_INDIRECT_TO_DIRECT){
-		mark_suspected_recipient (tb->tb_sb, bi.bi_bh);
-	    }
-#endif
 
 	    /* If we insert the first key change the delimiting key */
 	    if( item_pos == 0 ) {
 		if (tb->CFL[0]) /* can be 0 in reiserfsck */
 		    replace_key(tb, tb->CFL[0], tb->lkey[0],tbS0,0);
 
-#if 0 /* right delim key support */
-#ifdef CONFIG_REISERFS_CHECK
-		if ( ! tb->CFL[0] || ! tb->L[0] || (B_NR_ITEMS (tbS0) > 1 && 
-						    COMP_KEYS(B_PRIGHT_DELIM_KEY(tb->L[0]), B_N_PKEY(tbS0, 1))) )
-		    reiserfs_panic(tb->tb_sb, "PAP-12250: balance_leaf: invalid right delimiting key");
-		if (!buffer_dirty (tb->L[0]) && !(buffer_journaled(tb->L[0]) ||
-		     buffer_journal_dirty(tb->L[0])))
-		    reiserfs_panic (tb->tb_sb, "PAP-12255: balance_leaf: tb->L[0] must be dirty");
-#endif
-		if (tb->L[0]) /* can be 0 in reiserfsck */
-		    copy_key (B_PRIGHT_DELIM_KEY (tb->L[0]), &(ih->ih_key));   
-#endif /* right delim key support */
 	    }
 	    break;
 
@@ -1329,7 +1104,8 @@
 	    pasted = B_N_PITEM_HEAD (tbS0, item_pos);
 	    /* when directory, may be new entry already pasted */
 	    if (is_direntry_le_ih (pasted)) {
-		if ( pos_in_item >= 0 && pos_in_item <= le16_to_cpu (pasted->u.ih_entry_count) ) {
+		if ( pos_in_item >= 0 &&
+		    pos_in_item <= ih_entry_count(pasted) ) {
 
 		    RFALSE( ! tb->insert_size[0], 
 			    "PAP-12260: insert_size is 0 already");
@@ -1341,15 +1117,6 @@
 		    bi.bi_position = PATH_H_POSITION (tb->tb_path, 1);
 		    leaf_paste_in_buffer(&bi, item_pos, pos_in_item, tb->insert_size[0], body, zeros_num);
 
-
-#ifdef CONFIG_REISERFS_CHECK
-#if 0
-		    if ( ! item_pos && ! pos_in_item  && (! tb->L[0] || COMP_KEYS(B_PRIGHT_DELIM_KEY(tb->L[0]), 
-										  B_N_PKEY(tbS0, 0))) )
-			reiserfs_panic(tb->tb_sb, "PAP-12265: balance_leaf: invalid right delimiting key");
-#endif
-#endif
-
 		    /* paste entry */
 		    leaf_paste_entries (
 			bi.bi_bh, item_pos, pos_in_item, 1, (struct reiserfs_de_head *)body,
@@ -1361,21 +1128,16 @@
 			if (tb->CFL[0]) {
 			    replace_key(tb, tb->CFL[0], tb->lkey[0],tbS0,0);
 
-#if 0
-			    /* update right delimiting key */
-			    copy_key (B_PRIGHT_DELIM_KEY (tb->L[0]), B_N_PKEY(tbS0, 0));   
-			    /* probably not needed as something has been shifted to tb->L[0] already */
-			    reiserfs_mark_buffer_dirty (tb->L[0], 0);
-#endif
 			}
 		    }
 		    tb->insert_size[0] = 0;
 		}
 	    } else { /* regular object */
-		if ( pos_in_item == pasted->ih_item_len ) {
+		if ( pos_in_item == ih_item_len(pasted) ) {
+
 		    RFALSE( tb->insert_size[0] <= 0,
-			    "PAP-12275: insert size must not be %d", 
-			    tb->insert_size[0]);
+			    "PAP-12275: insert size must not be %d",
+                            tb->insert_size[0]);
 		    bi.tb = tb;
 		    bi.bi_bh = tbS0;
 		    bi.bi_parent = PATH_H_PPARENT (tb->tb_path, 0);
@@ -1425,11 +1187,12 @@
 
     RFALSE( bi->bi_bh == NULL, "PAP-12295: pointer to the buffer is NULL");
 
-    (blkh = B_BLK_HEAD(bi->bi_bh))->blk_nr_item = cpu_to_le16 (0);
-    blkh->blk_free_space = cpu_to_le16 (MAX_CHILD_SIZE(bi->bi_bh));
+    blkh = B_BLK_HEAD(bi->bi_bh);
+    set_blkh_nr_item( blkh, 0 );
+    set_blkh_free_space( blkh, MAX_CHILD_SIZE(bi->bi_bh) );
 
     if (bi->bi_parent)
-	B_N_CHILD (bi->bi_parent, bi->bi_position)->dc_size = 0; 
+	B_N_CHILD (bi->bi_parent, bi->bi_position)->dc_size = 0; /* Endian safe if 0 */
 }
 
 
@@ -1494,8 +1257,11 @@
 
 void reiserfs_invalidate_buffer (struct tree_balance * tb, struct buffer_head * bh)
 {
-    B_BLK_HEAD (bh)->blk_level = cpu_to_le16 (FREE_LEVEL)/*0*/;
-    B_BLK_HEAD (bh)->blk_nr_item = cpu_to_le16 (0);
+    struct block_head *blkh;
+    blkh = B_BLK_HEAD(bh);
+    set_blkh_level( blkh, FREE_LEVEL );
+    set_blkh_nr_item( blkh, 0 );
+    
     mark_buffer_clean (bh);
     /* reiserfs_free_block is no longer schedule safe 
     reiserfs_free_block (tb->transaction_handle, tb->tb_sb, bh->b_blocknr);
@@ -1583,7 +1349,7 @@
   dc = B_N_CHILD (bh, 0);
 
   for (i = 0; i <= B_NR_ITEMS (bh); i ++, dc ++) {
-    if (!is_reusable (s, dc->dc_block_number, 1) ) {
+    if (!is_reusable (s, dc_block_number(dc), 1) ) {
       print_cur_tb (mes);
       reiserfs_panic (s, "PAP-12338: check_internal_node: invalid child pointer %y in %b", dc, bh);
     }
@@ -1636,23 +1402,37 @@
 {
     if (tb->lnum[0]) {
 	if (B_FREE_SPACE (tb->L[0]) != 
-	    MAX_CHILD_SIZE (tb->L[0]) - B_N_CHILD (tb->FL[0], get_left_neighbor_position (tb, 0))->dc_size) {
+	    MAX_CHILD_SIZE (tb->L[0]) - dc_size(B_N_CHILD (tb->FL[0], get_left_neighbor_position (tb, 0)))) {
 	    print_cur_tb ("12221");
 	    reiserfs_panic (tb->tb_sb, "PAP-12355: check_after_balance_leaf: shift to left was incorrect");
 	}
     }
     if (tb->rnum[0]) {
 	if (B_FREE_SPACE (tb->R[0]) != 
-	    MAX_CHILD_SIZE (tb->R[0]) - B_N_CHILD (tb->FR[0], get_right_neighbor_position (tb, 0))->dc_size) {
+	    MAX_CHILD_SIZE (tb->R[0]) - dc_size(B_N_CHILD (tb->FR[0], get_right_neighbor_position (tb, 0)))) {
 	    print_cur_tb ("12222");
 	    reiserfs_panic (tb->tb_sb, "PAP-12360: check_after_balance_leaf: shift to right was incorrect");
 	}
     }
-    if (PATH_H_PBUFFER(tb->tb_path,1) && (B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) != 
-					  (MAX_CHILD_SIZE (PATH_H_PBUFFER(tb->tb_path,0)) -
-					   B_N_CHILD (PATH_H_PBUFFER(tb->tb_path,1),
-						      PATH_H_POSITION (tb->tb_path, 1))->dc_size))) {
+    if (PATH_H_PBUFFER(tb->tb_path,1) &&
+	(B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) != 
+		    (MAX_CHILD_SIZE (PATH_H_PBUFFER(tb->tb_path,0)) -
+		    dc_size(B_N_CHILD (PATH_H_PBUFFER(tb->tb_path,1),
+		    PATH_H_POSITION (tb->tb_path, 1)))) )) {
+	int left = B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0));
+	int right = (MAX_CHILD_SIZE (PATH_H_PBUFFER(tb->tb_path,0)) -
+		    dc_size(B_N_CHILD (PATH_H_PBUFFER(tb->tb_path,1),
+			PATH_H_POSITION (tb->tb_path, 1))));
 	print_cur_tb ("12223");
+	reiserfs_warning(
+	    "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; "
+    	    "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d\n",
+	    left,
+	    MAX_CHILD_SIZE (PATH_H_PBUFFER(tb->tb_path,0)),
+	    PATH_H_PBUFFER(tb->tb_path,1),
+	    PATH_H_POSITION (tb->tb_path, 1),
+	    dc_size(B_N_CHILD (PATH_H_PBUFFER(tb->tb_path,1), PATH_H_POSITION (tb->tb_path, 1 )) ),
+	    right );
 	reiserfs_panic (tb->tb_sb, "PAP-12365: check_after_balance_leaf: S is incorrect");
     }
 }
@@ -1783,8 +1563,8 @@
 			       existing file or to insert a directory
 			       entry.  */
 {
-    int child_pos,					/* position of a child node in its parent */
-	h;								/* level of the tree being processed */
+    int child_pos, /* position of a child node in its parent */
+	h;	   /* level of the tree being processed */
     struct item_head insert_key[2]; /* in our processing of one level
 				       we sometimes determine what
 				       must be inserted into the next
diff -urN linux-2.4.13-pre1/fs/reiserfs/file.c linux/fs/reiserfs/file.c
--- linux-2.4.13-pre1/fs/reiserfs/file.c	Mon Sep 17 13:16:30 2001
+++ linux/fs/reiserfs/file.c	Mon Dec  3 23:17:33 2001
@@ -42,6 +42,7 @@
     lock_kernel() ;
     down (&inode->i_sem); 
     journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT * 3) ;
+    reiserfs_update_inode_transaction(inode) ;
 
 #ifdef REISERFS_PREALLOCATE
     reiserfs_discard_prealloc (&th, inode);
@@ -75,10 +76,7 @@
 			      int datasync
 			      ) {
   struct inode * p_s_inode = p_s_dentry->d_inode;
-  struct reiserfs_transaction_handle th ;
   int n_err;
-  int windex ;
-  int jbegin_count = 1 ;
 
   lock_kernel() ;
 
@@ -87,14 +85,7 @@
 
   n_err = fsync_inode_buffers(p_s_inode) ;
   n_err |= fsync_inode_data_buffers(p_s_inode);
-  /* commit the current transaction to flush any metadata
-  ** changes.  sys_fsync takes care of flushing the dirty pages for us
-  */
-  journal_begin(&th, p_s_inode->i_sb, jbegin_count) ;
-  windex = push_journal_writer("sync_file") ;
-  reiserfs_update_sd(&th, p_s_inode);
-  pop_journal_writer(windex) ;
-  journal_end_sync(&th, p_s_inode->i_sb,jbegin_count) ;
+  reiserfs_commit_for_inode(p_s_inode) ;
   unlock_kernel() ;
   return ( n_err < 0 ) ? -EIO : 0;
 }
diff -urN linux-2.4.13-pre1/fs/reiserfs/fix_node.c linux/fs/reiserfs/fix_node.c
--- linux-2.4.13-pre1/fs/reiserfs/fix_node.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/fix_node.c	Mon Dec  3 23:17:33 2001
@@ -124,7 +124,7 @@
 	/* get item number in source node */
 	j = old_item_num (new_num, vn->vn_affected_item_num, vn->vn_mode);
     
-	vi->vi_item_len += ih[j].ih_item_len + IH_SIZE;
+	vi->vi_item_len += ih_item_len(ih + j) + IH_SIZE;
 	vi->vi_ih = ih + j;
 	vi->vi_item = B_I_PITEM (Sh, ih + j);
 	vi->vi_uarea = vn->vn_free_ptr;
@@ -658,9 +658,8 @@
 	    
 	    /* we might check that left neighbor exists and is of the
 	       same directory */
-	    RFALSE( le_key_k_offset 
-		    (ih_version (ih), &(ih->ih_key)) == DOT_OFFSET,
-		    "vs-8130: first directory item can not be removed until directory is not empty");
+	    RFALSE(le_ih_k_offset (ih) == DOT_OFFSET,
+		"vs-8130: first directory item can not be removed until directory is not empty");
       }
     
   }
@@ -857,7 +856,7 @@
 	f = l;
     }
 
-    return (MAX_CHILD_SIZE(f) - le16_to_cpu (B_N_CHILD(f,order)->dc_size));
+    return (MAX_CHILD_SIZE(f) - dc_size(B_N_CHILD(f,order)));
 }
 
 
@@ -879,7 +878,7 @@
       f = r;
   }
 
-  return (MAX_CHILD_SIZE(f) - B_N_CHILD(f,order)->dc_size);
+  return (MAX_CHILD_SIZE(f) - dc_size( B_N_CHILD(f,order)));
 
 }
 
@@ -959,7 +958,7 @@
     struct path * p_s_path = p_s_tb->tb_path;
     struct cpu_key	s_lr_father_key;
     int                   n_counter,
-	n_position = MAX_INT,
+	n_position = INT_MAX,
 	n_first_last_position = 0,
 	n_path_offset = PATH_H_PATH_OFFSET(p_s_path, n_h);
 
@@ -1134,17 +1133,8 @@
     decrement_bcount(p_s_tb->CFR[n_h]);
     p_s_tb->CFR[n_h] = p_s_curcf; /* New initialization of CFR[n_path_offset]. */
 
-#ifdef CONFIG_REISERFS_CHECK
-#if 0
-    if (n_h == 0 && p_s_tb->CFR[n_h] && COMP_KEYS (B_PRIGHT_DELIM_KEY (PATH_H_PBUFFER(p_s_path, n_h)), 
-						   B_N_PDELIM_KEY (p_s_tb->CFR[n_h], p_s_tb->rkey[n_h]))) {
-	reiserfs_panic (p_s_tb->tb_sb, "PAP-8200: get_parents: rdkey in S0 %k, rdkey in CFR0 %k do not match",
-			B_PRIGHT_DELIM_KEY (PATH_H_PBUFFER(p_s_path, n_h)), B_N_PDELIM_KEY (p_s_tb->CFR[n_h], p_s_tb->rkey[n_h]));
-    }
-#endif
-#endif
-    RFALSE( (p_s_curf && !B_IS_IN_TREE (p_s_curf)) || 
-	    (p_s_curcf && !B_IS_IN_TREE (p_s_curcf)),
+    RFALSE( (p_s_curf && !B_IS_IN_TREE (p_s_curf)) ||
+            (p_s_curcf && !B_IS_IN_TREE (p_s_curcf)),
 	    "PAP-8205: FR (%b) or CFR (%b) is invalid", p_s_curf, p_s_curcf);
 
     return CARRY_ON;
@@ -1590,7 +1580,7 @@
 	      int order_L;
 	      
 	      order_L = ((n=PATH_H_B_ITEM_ORDER(tb->tb_path, h))==0) ? B_NR_ITEMS(tb->FL[h]) : n - 1;
-	      n = B_N_CHILD(tb->FL[h],order_L)->dc_size / (DC_SIZE + KEY_SIZE);
+	      n = dc_size(B_N_CHILD(tb->FL[h],order_L)) / (DC_SIZE + KEY_SIZE);
 	      set_parameters (tb, h, -n-1, 0, 0, NULL, -1, -1);
 	      return CARRY_ON;
 	    }
@@ -1602,7 +1592,7 @@
 	      int order_R;
 	    
 	      order_R = ((n=PATH_H_B_ITEM_ORDER(tb->tb_path, h))==B_NR_ITEMS(Fh)) ? 0 : n + 1;
-	      n = B_N_CHILD(tb->FR[h],order_R)->dc_size / (DC_SIZE + KEY_SIZE);
+	      n = dc_size(B_N_CHILD(tb->FR[h],order_R)) / (DC_SIZE + KEY_SIZE);
 	      set_parameters (tb, h, 0, -n-1, 0, NULL, -1, -1);
 	      return CARRY_ON;   
 	    }
@@ -1633,7 +1623,7 @@
 	int order_L;
 	      
 	order_L = ((n=PATH_H_B_ITEM_ORDER(tb->tb_path, h))==0) ? B_NR_ITEMS(tb->FL[h]) : n - 1;
-	n = B_N_CHILD(tb->FL[h],order_L)->dc_size / (DC_SIZE + KEY_SIZE);
+	n = dc_size(B_N_CHILD(tb->FL[h],order_L)) / (DC_SIZE + KEY_SIZE);
 	set_parameters (tb, h, -n-1, 0, 0, NULL, -1, -1);
 	return CARRY_ON;
       }
@@ -1645,7 +1635,7 @@
       int order_R;
 	    
       order_R = ((n=PATH_H_B_ITEM_ORDER(tb->tb_path, h))==B_NR_ITEMS(Fh)) ? 0 : (n + 1);
-      n = B_N_CHILD(tb->FR[h],order_R)->dc_size / (DC_SIZE + KEY_SIZE);
+      n = dc_size(B_N_CHILD(tb->FR[h],order_R)) / (DC_SIZE + KEY_SIZE);
       set_parameters (tb, h, 0, -n-1, 0, NULL, -1, -1);
       return CARRY_ON;   
     }
@@ -1934,14 +1924,14 @@
 	    return REPEAT_SEARCH;
 	}
 	
-	RFALSE( ! B_IS_IN_TREE(p_s_tb->FL[n_h]) || 
-		n_child_position > B_NR_ITEMS(p_s_tb->FL[n_h]) ||
-		B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position) != 
-		p_s_bh->b_blocknr, "PAP-8275: invalid parent");
+	RFALSE( ! B_IS_IN_TREE(p_s_tb->FL[n_h]) ||
+                n_child_position > B_NR_ITEMS(p_s_tb->FL[n_h]) ||
+	        B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position) !=
+                p_s_bh->b_blocknr, "PAP-8275: invalid parent");
 	RFALSE( ! B_IS_IN_TREE(p_s_bh), "PAP-8280: invalid child");
-	RFALSE( ! n_h && 
-		B_FREE_SPACE (p_s_bh) != MAX_CHILD_SIZE (p_s_bh) - B_N_CHILD (p_s_tb->FL[0],n_child_position)->dc_size,
-		"PAP-8290: invalid child size of left neighbor");
+	RFALSE( ! n_h &&
+                B_FREE_SPACE (p_s_bh) != MAX_CHILD_SIZE (p_s_bh) - dc_size(B_N_CHILD (p_s_tb->FL[0],n_child_position)),
+                "PAP-8290: invalid child size of left neighbor");
 
 	decrement_bcount(p_s_tb->L[n_h]);
 	p_s_tb->L[n_h] = p_s_bh;
@@ -1967,10 +1957,10 @@
 	decrement_bcount(p_s_tb->R[n_h]);
 	p_s_tb->R[n_h] = p_s_bh;
 
-	RFALSE( ! n_h && B_FREE_SPACE (p_s_bh) != MAX_CHILD_SIZE (p_s_bh) - B_N_CHILD (p_s_tb->FR[0],n_child_position)->dc_size,
-		"PAP-8300: invalid child size of right neighbor (%d != %d - %d)",
-		B_FREE_SPACE (p_s_bh), MAX_CHILD_SIZE (p_s_bh), 
-		B_N_CHILD (p_s_tb->FR[0],n_child_position)->dc_size);
+	RFALSE( ! n_h && B_FREE_SPACE (p_s_bh) != MAX_CHILD_SIZE (p_s_bh) - dc_size(B_N_CHILD (p_s_tb->FR[0],n_child_position)),
+                "PAP-8300: invalid child size of right neighbor (%d != %d - %d)",
+                B_FREE_SPACE (p_s_bh), MAX_CHILD_SIZE (p_s_bh),
+                dc_size(B_N_CHILD (p_s_tb->FR[0],n_child_position)));
 	
     }
     return CARRY_ON;
@@ -2027,7 +2017,7 @@
     size += sizeof (struct virtual_item);
     if (is_direntry_le_ih (ih))
       /* each entry and new one occupeis 2 byte in the virtual node */
-      size += (le16_to_cpu (ih->u.ih_entry_count) + 1) * sizeof (__u16);
+      size += (ih_entry_count(ih) + 1) * sizeof( __u16 );
   }
   
   /* 1 bit for each bitmap block to note whether bitmap block was
@@ -2544,8 +2534,9 @@
 	    brelse (tb->used[i]);
 	}
     }
+
     if (tb->vn_buf) 
-	reiserfs_kfree (tb->vn_buf, tb->vn_buf_size, tb->tb_sb);
+    reiserfs_kfree (tb->vn_buf, tb->vn_buf_size, tb->tb_sb);
 
 } 
 
diff -urN linux-2.4.13-pre1/fs/reiserfs/hashes.c linux/fs/reiserfs/hashes.c
--- linux-2.4.13-pre1/fs/reiserfs/hashes.c	Sat Sep  8 12:05:32 2001
+++ linux/fs/reiserfs/hashes.c	Mon Dec  3 23:17:33 2001
@@ -48,7 +48,7 @@
 	} while(0)
 
 
-u32 keyed_hash(const char *msg, int len)
+u32 keyed_hash(const signed char *msg, int len)
 {
 	u32 k[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3}; 
 
@@ -174,7 +174,7 @@
 /* What follows in this file is copyright 2000 by Hans Reiser, and the
  * licensing of what follows is governed by reiserfs/README */
 
-u32 yura_hash (const char *msg, int len)
+u32 yura_hash (const signed char *msg, int len)
 {
     int j, pow;
     u32 a, c;
@@ -209,7 +209,7 @@
     return a;
 }
 
-u32 r5_hash (const char *msg, int len)
+u32 r5_hash (const signed char *msg, int len)
 {
   u32 a=0;
   while(*msg) { 
diff -urN linux-2.4.13-pre1/fs/reiserfs/ibalance.c linux/fs/reiserfs/ibalance.c
--- linux-2.4.13-pre1/fs/reiserfs/ibalance.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/ibalance.c	Mon Dec  3 23:17:33 2001
@@ -140,7 +140,8 @@
     if (count <= 0)
 	return;
 
-    nr = le16_to_cpu ((blkh = B_BLK_HEAD(cur))->blk_nr_item);
+    blkh = B_BLK_HEAD(cur);
+    nr = blkh_nr_item(blkh);
 
     RFALSE( count > 2,
 	    "too many children (%d) are to be inserted", count);
@@ -155,9 +156,8 @@
 
     /* copy to_be_insert disk children */
     for (i = 0; i < count; i ++) {
-	new_dc[i].dc_size =
-	    cpu_to_le16 (MAX_CHILD_SIZE(bh[i]) - B_FREE_SPACE (bh[i]));
-	new_dc[i].dc_block_number = cpu_to_le32 (bh[i]->b_blocknr);
+	put_dc_size( &(new_dc[i]), MAX_CHILD_SIZE(bh[i]) - B_FREE_SPACE(bh[i]));
+	put_dc_block_number( &(new_dc[i]), bh[i]->b_blocknr );
     }
     memcpy (dc, new_dc, DC_SIZE * count);
 
@@ -173,8 +173,9 @@
 	memcpy (ih + 1, inserted + 1, KEY_SIZE);
 
     /* sizes, item number */
-    blkh->blk_nr_item = cpu_to_le16 (le16_to_cpu (blkh->blk_nr_item) + count);
-    blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) - count * (DC_SIZE + KEY_SIZE));
+    set_blkh_nr_item( blkh, blkh_nr_item(blkh) + count );
+    set_blkh_free_space( blkh,
+                        blkh_free_space(blkh) - count * (DC_SIZE + KEY_SIZE ) );
 
     do_balance_mark_internal_dirty (cur_bi->tb, cur,0);
 
@@ -183,7 +184,8 @@
     /*&&&&&&&&&&&&&&&&&&&&&&&&*/
 
     if (cur_bi->bi_parent) {
-	B_N_CHILD (cur_bi->bi_parent,cur_bi->bi_position)->dc_size += count * (DC_SIZE + KEY_SIZE);
+	struct disk_child *t_dc = B_N_CHILD (cur_bi->bi_parent,cur_bi->bi_position);
+	put_dc_size( t_dc, dc_size(t_dc) + (count * (DC_SIZE + KEY_SIZE)));
 	do_balance_mark_internal_dirty(cur_bi->tb, cur_bi->bi_parent, 0);
 
 	/*&&&&&&&&&&&&&&&&&&&&&&&&*/
@@ -210,17 +212,18 @@
   struct disk_child * dc;
 
   RFALSE( cur == NULL, "buffer is 0");
-  RFALSE( del_num < 0, 
-	  "negative number of items (%d) can not be deleted", del_num);
+  RFALSE( del_num < 0,
+          "negative number of items (%d) can not be deleted", del_num);
   RFALSE( first_p < 0 || first_p + del_num > B_NR_ITEMS (cur) + 1 || first_i < 0,
-	  "first pointer order (%d) < 0 or "
-	  "no so many pointers (%d), only (%d) or "
-	  "first key order %d < 0", first_p, 
-	  first_p + del_num, B_NR_ITEMS (cur) + 1, first_i);
+          "first pointer order (%d) < 0 or "
+          "no so many pointers (%d), only (%d) or "
+          "first key order %d < 0", first_p, 
+          first_p + del_num, B_NR_ITEMS (cur) + 1, first_i);
   if ( del_num == 0 )
     return;
 
-  nr = le16_to_cpu ((blkh = B_BLK_HEAD(cur))->blk_nr_item);
+  blkh = B_BLK_HEAD(cur);
+  nr = blkh_nr_item(blkh);
 
   if ( first_p == 0 && del_num == nr + 1 ) {
     RFALSE( first_i != 0, "1st deleted key must have order 0, not %d", first_i);
@@ -229,9 +232,9 @@
   }
 
   RFALSE( first_i + del_num > B_NR_ITEMS (cur),
-	  "first_i = %d del_num = %d "
-	  "no so many keys (%d) in the node (%b)(%z)", 
-	  first_i, del_num, first_i + del_num, cur, cur);
+          "first_i = %d del_num = %d "
+          "no so many keys (%d) in the node (%b)(%z)",
+          first_i, del_num, first_i + del_num, cur, cur);
 
 
   /* deleting */
@@ -243,8 +246,9 @@
 
 
   /* sizes, item number */
-  blkh->blk_nr_item = cpu_to_le16 (le16_to_cpu (blkh->blk_nr_item) - del_num);
-  blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) + del_num * (KEY_SIZE +  DC_SIZE));
+  set_blkh_nr_item( blkh, blkh_nr_item(blkh) - del_num );
+  set_blkh_free_space( blkh,
+                    blkh_free_space(blkh) + (del_num * (KEY_SIZE + DC_SIZE) ) );
 
   do_balance_mark_internal_dirty (cur_bi->tb, cur, 0);
   /*&&&&&&&&&&&&&&&&&&&&&&&*/
@@ -252,7 +256,10 @@
   /*&&&&&&&&&&&&&&&&&&&&&&&*/
  
   if (cur_bi->bi_parent) {
-    B_N_CHILD (cur_bi->bi_parent, cur_bi->bi_position)->dc_size -= del_num * (KEY_SIZE +  DC_SIZE);
+    struct disk_child *t_dc;
+    t_dc = B_N_CHILD (cur_bi->bi_parent, cur_bi->bi_position);
+    put_dc_size( t_dc, dc_size(t_dc) - (del_num * (KEY_SIZE + DC_SIZE) ) );
+
     do_balance_mark_internal_dirty (cur_bi->tb, cur_bi->bi_parent,0);
     /*&&&&&&&&&&&&&&&&&&&&&&&&*/
     check_internal (cur_bi->bi_parent);
@@ -312,7 +319,8 @@
     return;
 
 	/* coping */
-  nr_dest = le16_to_cpu ((blkh = B_BLK_HEAD(dest))->blk_nr_item);
+  blkh = B_BLK_HEAD(dest);
+  nr_dest = blkh_nr_item(blkh);
 
   /*dest_order = (last_first == LAST_TO_FIRST) ? 0 : nr_dest;*/
   /*src_order = (last_first == LAST_TO_FIRST) ? (nr_src - cpy_num + 1) : 0;*/
@@ -338,8 +346,9 @@
   memcpy (key, B_N_PDELIM_KEY (src, src_order), KEY_SIZE * (cpy_num - 1));
 
   /* sizes, item number */
-  blkh->blk_nr_item = cpu_to_le16 (le16_to_cpu (blkh->blk_nr_item) + (cpy_num - 1));
-  blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) - (KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num));
+  set_blkh_nr_item( blkh, blkh_nr_item(blkh) + (cpy_num - 1 ) );
+  set_blkh_free_space( blkh,
+      blkh_free_space(blkh) - (KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num ) );
 
   do_balance_mark_internal_dirty (dest_bi->tb, dest, 0);
 
@@ -348,8 +357,9 @@
   /*&&&&&&&&&&&&&&&&&&&&&&&&*/
 
   if (dest_bi->bi_parent) {
-    B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position)->dc_size +=
-      KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num;
+    struct disk_child *t_dc;
+    t_dc = B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position);
+    put_dc_size( t_dc, dc_size(t_dc) + (KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num) );
 
     do_balance_mark_internal_dirty (dest_bi->tb, dest_bi->bi_parent,0);
     /*&&&&&&&&&&&&&&&&&&&&&&&&*/
@@ -413,7 +423,8 @@
     RFALSE( B_FREE_SPACE (dest) < KEY_SIZE,
 	    "no enough free space (%d) in dest buffer", B_FREE_SPACE (dest));
 
-    nr = le16_to_cpu ((blkh=B_BLK_HEAD(dest))->blk_nr_item);
+    blkh = B_BLK_HEAD(dest);
+    nr = blkh_nr_item(blkh);
 
     /* prepare space for inserting key */
     key = B_N_PDELIM_KEY (dest, dest_position_before);
@@ -423,13 +434,17 @@
     memcpy (key, B_N_PDELIM_KEY(src, src_position), KEY_SIZE);
 
     /* Change dirt, free space, item number fields. */
-    blkh->blk_nr_item = cpu_to_le16 (le16_to_cpu (blkh->blk_nr_item) + 1);
-    blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) - KEY_SIZE);
+
+    set_blkh_nr_item( blkh, blkh_nr_item(blkh) + 1 );
+    set_blkh_free_space( blkh, blkh_free_space(blkh) - KEY_SIZE );
 
     do_balance_mark_internal_dirty (dest_bi->tb, dest, 0);
 
     if (dest_bi->bi_parent) {
-	B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position)->dc_size += KEY_SIZE;
+	struct disk_child *t_dc;
+	t_dc = B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position);
+	put_dc_size( t_dc, dc_size(t_dc) + KEY_SIZE );
+
 	do_balance_mark_internal_dirty (dest_bi->tb, dest_bi->bi_parent,0);
     }
 }
@@ -607,9 +622,9 @@
 	    else
 		new_root = tb->L[h-1];
 	    /* switch super block's tree root block number to the new value */
-	    tb->tb_sb->u.reiserfs_sb.s_rs->s_root_block = cpu_to_le32 (new_root->b_blocknr);
+            PUT_SB_ROOT_BLOCK( tb->tb_sb, new_root->b_blocknr );
 	    //tb->tb_sb->u.reiserfs_sb.s_rs->s_tree_height --;
-	    tb->tb_sb->u.reiserfs_sb.s_rs->s_tree_height = cpu_to_le16 (SB_TREE_HEIGHT (tb->tb_sb) - 1);
+            PUT_SB_TREE_HEIGHT( tb->tb_sb, SB_TREE_HEIGHT(tb->tb_sb) - 1 );
 
 	    do_balance_mark_sb_dirty (tb, tb->tb_sb->u.reiserfs_sb.s_sbh, 1);
 	    /*&&&&&&&&&&&&&&&&&&&&&&*/
@@ -818,8 +833,8 @@
 
 	    /* replace the first node-ptr in S[h] by node-ptr to insert_ptr[k] */
 	    dc = B_N_CHILD(tbSh, 0);
-	    dc->dc_size = cpu_to_le16 (MAX_CHILD_SIZE(insert_ptr[k]) - B_FREE_SPACE (insert_ptr[k]));
-	    dc->dc_block_number = cpu_to_le32 (insert_ptr[k]->b_blocknr);
+	    put_dc_size( dc, MAX_CHILD_SIZE(insert_ptr[k]) - B_FREE_SPACE (insert_ptr[k]));
+	    put_dc_block_number( dc, insert_ptr[k]->b_blocknr );
 
 	    do_balance_mark_internal_dirty (tb, tbSh, 0);
 
@@ -874,10 +889,9 @@
 
 		/* replace the first node-ptr in R[h] by node-ptr insert_ptr[insert_num-k-1]*/
 		dc = B_N_CHILD(tb->R[h], 0);
-		dc->dc_size =
-		    cpu_to_le16 (MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]) -
-				 B_FREE_SPACE (insert_ptr[insert_num-k-1]));
-		dc->dc_block_number = cpu_to_le32 (insert_ptr[insert_num-k-1]->b_blocknr);
+		put_dc_size( dc, MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]) -
+    				    B_FREE_SPACE (insert_ptr[insert_num-k-1]));
+		put_dc_block_number( dc, insert_ptr[insert_num-k-1]->b_blocknr );
 
 		do_balance_mark_internal_dirty (tb, tb->R[h],0);
 
@@ -902,22 +916,24 @@
 	/* create new root */
 	struct disk_child  * dc;
 	struct buffer_head * tbSh_1 = PATH_H_PBUFFER (tb->tb_path, h - 1);
+        struct block_head *  blkh;
 
 
 	if ( tb->blknum[h] != 1 )
 	    reiserfs_panic(0, "balance_internal", "One new node required for creating the new root");
 	/* S[h] = empty buffer from the list FEB. */
 	tbSh = get_FEB (tb);
-	B_BLK_HEAD(tbSh)->blk_level = cpu_to_le16 (h + 1);
+        blkh = B_BLK_HEAD(tbSh);
+        set_blkh_level( blkh, h + 1 );
 
 	/* Put the unique node-pointer to S[h] that points to S[h-1]. */
 
 	dc = B_N_CHILD(tbSh, 0);
-	dc->dc_block_number = cpu_to_le32 (tbSh_1->b_blocknr);
-	dc->dc_size = cpu_to_le16 (MAX_CHILD_SIZE (tbSh_1) - B_FREE_SPACE (tbSh_1));
+	put_dc_block_number( dc, tbSh_1->b_blocknr );
+	put_dc_size( dc, (MAX_CHILD_SIZE (tbSh_1) - B_FREE_SPACE (tbSh_1)));
 
 	tb->insert_size[h] -= DC_SIZE;
-	B_BLK_HEAD(tbSh)->blk_free_space = cpu_to_le16 (B_FREE_SPACE (tbSh) - DC_SIZE);
+        set_blkh_free_space( blkh, blkh_free_space(blkh) - DC_SIZE );
 
 	do_balance_mark_internal_dirty (tb, tbSh, 0);
 
@@ -929,8 +945,8 @@
 	PATH_OFFSET_PBUFFER(tb->tb_path, ILLEGAL_PATH_ELEMENT_OFFSET) = tbSh;
 
 	/* Change root in structure super block. */
-	tb->tb_sb->u.reiserfs_sb.s_rs->s_root_block = cpu_to_le32 (tbSh->b_blocknr);
-	tb->tb_sb->u.reiserfs_sb.s_rs->s_tree_height = cpu_to_le16 (SB_TREE_HEIGHT (tb->tb_sb) + 1);
+        PUT_SB_ROOT_BLOCK( tb->tb_sb, tbSh->b_blocknr );
+        PUT_SB_TREE_HEIGHT( tb->tb_sb, SB_TREE_HEIGHT(tb->tb_sb) + 1 );
 	do_balance_mark_sb_dirty (tb, tb->tb_sb->u.reiserfs_sb.s_sbh, 1);
 	tb->tb_sb->s_dirt = 1;
     }
@@ -943,7 +959,7 @@
 	/* S_new = free buffer from list FEB */
 	S_new = get_FEB(tb);
 
-	B_BLK_HEAD(S_new)->blk_level = cpu_to_le16 (h + 1);
+        set_blkh_level( B_BLK_HEAD(S_new), h + 1 );
 
 	dest_bi.tb = tb;
 	dest_bi.bi_bh = S_new;
@@ -998,9 +1014,9 @@
 	    /* replace first node-ptr in S_new by node-ptr to insert_ptr[insert_num-k-1] */
 
 	    dc = B_N_CHILD(S_new,0);
-	    dc->dc_size = cpu_to_le16 (MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]) -
-				       B_FREE_SPACE(insert_ptr[insert_num-k-1]));
-	    dc->dc_block_number =	cpu_to_le32 (insert_ptr[insert_num-k-1]->b_blocknr);
+	    put_dc_size( dc, (MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]) -
+				B_FREE_SPACE(insert_ptr[insert_num-k-1])) );
+	    put_dc_block_number( dc, insert_ptr[insert_num-k-1]->b_blocknr );
 
 	    do_balance_mark_internal_dirty (tb, S_new,0);
 			
diff -urN linux-2.4.13-pre1/fs/reiserfs/inode.c linux/fs/reiserfs/inode.c
--- linux-2.4.13-pre1/fs/reiserfs/inode.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/inode.c	Mon Dec  3 23:17:33 2001
@@ -8,6 +8,7 @@
 #include <linux/locks.h>
 #include <linux/smp_lock.h>
 #include <asm/uaccess.h>
+#include <asm/unaligned.h>
 
 /* args for the create parameter of reiserfs_get_block */
 #define GET_BLOCK_NO_CREATE 0 /* don't create new blocks or convert tails */
@@ -34,6 +35,7 @@
 	down (&inode->i_sem); 
 
 	journal_begin(&th, inode->i_sb, jbegin_count) ;
+	reiserfs_update_inode_transaction(inode) ;
 	windex = push_journal_writer("delete_inode") ;
 
 	reiserfs_delete_object (&th, inode);
@@ -53,26 +55,26 @@
 }
 
 static void _make_cpu_key (struct cpu_key * key, int version, __u32 dirid, __u32 objectid, 
-			   loff_t offset, int type, int length)
+	       loff_t offset, int type, int length )
 {
-  key->version = version;
+    key->version = version;
 
-  key->on_disk_key.k_dir_id = dirid;
-  key->on_disk_key.k_objectid = objectid;
-  set_cpu_key_k_offset (key, offset);
-  set_cpu_key_k_type (key, type);  
-  key->key_length = length;
+    key->on_disk_key.k_dir_id = dirid;
+    key->on_disk_key.k_objectid = objectid;
+    set_cpu_key_k_offset (key, offset);
+    set_cpu_key_k_type (key, type);  
+    key->key_length = length;
 }
 
 
 /* take base of inode_key (it comes from inode always) (dirid, objectid) and version from an inode, set
    offset and type of key */
 void make_cpu_key (struct cpu_key * key, const struct inode * inode, loff_t offset,
-		   int type, int length)
+	      int type, int length )
 {
   _make_cpu_key (key, inode_items_version (inode), le32_to_cpu (INODE_PKEY (inode)->k_dir_id),
-					  le32_to_cpu (INODE_PKEY (inode)->k_objectid), 
-		 offset, type, length);
+	  	   le32_to_cpu (INODE_PKEY (inode)->k_objectid), 
+		   offset, type, length);
 }
 
 
@@ -86,14 +88,14 @@
 	ih->ih_key.k_dir_id = cpu_to_le32 (key->on_disk_key.k_dir_id);
 	ih->ih_key.k_objectid = cpu_to_le32 (key->on_disk_key.k_objectid);
     }
-    ih->ih_version = cpu_to_le16 (version);
+    put_ih_version( ih, version );
     set_le_ih_k_offset (ih, offset);
     set_le_ih_k_type (ih, type);
-    ih->ih_item_len = cpu_to_le16 (length);
+    put_ih_item_len( ih, length );
     /*    set_ih_free_space (ih, 0);*/
     // for directory items it is entry count, for directs and stat
     // datas - 0xffff, for indirects - 0
-    ih->u.ih_entry_count = cpu_to_le16 (entry_count);
+    put_ih_entry_count( ih, entry_count );
 }
 
 static void add_to_flushlist(struct inode *inode, struct buffer_head *bh) {
@@ -159,6 +161,7 @@
 static b_blocknr_t find_tag (struct buffer_head * bh, struct item_head * ih,
 			     __u32 * item, int pos_in_item)
 {
+  __u32 block ;
   if (!is_indirect_le_ih (ih))
 	 /* something more complicated could be here */
 	 return bh->b_blocknr;
@@ -168,8 +171,9 @@
   if (pos_in_item == I_UNFM_NUM (ih))
 	 pos_in_item --;
   while (pos_in_item >= 0) {
-	 if (item [pos_in_item])
-		return item [pos_in_item];
+	 block = get_block_num(item, pos_in_item) ;
+	 if (block)
+		return block ;
 	 pos_in_item --;
   }
   return bh->b_blocknr;
@@ -184,7 +188,8 @@
 {
   if (allocated)
 	 return 0;
-  if (retval == POSITION_FOUND && is_indirect_le_ih (ih) && item[pos_in_item])
+  if (retval == POSITION_FOUND && is_indirect_le_ih (ih) && 
+      get_block_num(item, pos_in_item))
 	 return 0;
   return 1;
 }
@@ -226,6 +231,7 @@
   reiserfs_update_sd(th, inode) ;
   journal_end(th, s, len) ;
   journal_begin(th, s, len) ;
+  reiserfs_update_inode_transaction(inode) ;
 }
 
 // it is called by get_block when create == 0. Returns block number
@@ -276,7 +282,7 @@
 	/* FIXME: here we could cache indirect item or part of it in
 	   the inode to avoid search_by_key in case of subsequent
 	   access to file */
-	blocknr = le32_to_cpu (ind_item [path.pos_in_item]);
+	blocknr = get_block_num(ind_item, path.pos_in_item) ;
 	ret = 0 ;
 	if (blocknr) {
 	    bh_result->b_dev = inode->i_dev;
@@ -320,10 +326,10 @@
     ** kmap schedules
     */
     if (!p) {
-	p = (char *)kmap(bh_result->b_page) ;
-	if (fs_changed (fs_gen, inode->i_sb) && item_moved (&tmp_ih, &path)) {
-	    goto research;
-	}
+    p = (char *)kmap(bh_result->b_page) ;
+    if (fs_changed (fs_gen, inode->i_sb) && item_moved (&tmp_ih, &path)) {
+        goto research;
+    }
     }
     p += offset ;
     memset (p, 0, inode->i_sb->s_blocksize);
@@ -342,7 +348,7 @@
 	    chars = inode->i_size - (le_ih_k_offset(ih) - 1) - path.pos_in_item;
 	    done = 1 ;
 	} else {
-	    chars = le16_to_cpu (ih->ih_item_len) - path.pos_in_item;
+	    chars = ih_item_len(ih) - path.pos_in_item;
 	}
 	memcpy (p, B_I_PITEM (bh, ih) + path.pos_in_item, chars);
 
@@ -565,6 +571,7 @@
 		  TYPE_ANY, 3/*key length*/);
     if ((new_offset + inode->i_sb->s_blocksize - 1) > inode->i_size) {
 	journal_begin(&th, inode->i_sb, jbegin_count) ;
+	reiserfs_update_inode_transaction(inode) ;
 	transaction_started = 1 ;
     }
  research:
@@ -589,6 +596,7 @@
 	if (!transaction_started) {
 	    pathrelse(&path) ;
 	    journal_begin(&th, inode->i_sb, jbegin_count) ;
+	    reiserfs_update_inode_transaction(inode) ;
 	    transaction_started = 1 ;
 	    goto research ;
 	}
@@ -616,12 +624,11 @@
     }
 
     if (indirect_item_found (retval, ih)) {
-	b_blocknr_t unfm_ptr;
-
+        b_blocknr_t unfm_ptr;
 	/* 'block'-th block is in the file already (there is
 	   corresponding cell in some indirect item). But it may be
 	   zero unformatted node pointer (hole) */
-	unfm_ptr = le32_to_cpu (item[pos_in_item]);
+        unfm_ptr = get_block_num (item, pos_in_item);
 	if (unfm_ptr == 0) {
 	    /* use allocated block to plug the hole */
 	    reiserfs_prepare_for_journal(inode->i_sb, bh, 1) ;
@@ -630,8 +637,8 @@
 		goto research;
 	    }
 	    bh_result->b_state |= (1UL << BH_New);
-	    item[pos_in_item] = cpu_to_le32 (allocated_block_nr);
-	    unfm_ptr = allocated_block_nr;
+	    put_block_num(item, pos_in_item, allocated_block_nr) ;
+            unfm_ptr = allocated_block_nr;
 	    journal_mark_dirty (&th, inode->i_sb, bh);
 	    inode->i_blocks += (inode->i_sb->s_blocksize / 512) ;
 	    reiserfs_update_sd(&th, inode) ;
@@ -658,6 +665,7 @@
 	*/
 	pathrelse(&path) ;
 	journal_begin(&th, inode->i_sb, jbegin_count) ;
+	reiserfs_update_inode_transaction(inode) ;
 	transaction_started = 1 ;
 	goto research;
     }
@@ -758,7 +766,7 @@
 	    struct cpu_key tmp_key;
 	    struct unfm_nodeinfo un = {0, 0};
 
-	    RFALSE( pos_in_item != le16_to_cpu (ih->ih_item_len) / UNFM_P_SIZE,
+	    RFALSE( pos_in_item != ih_item_len(ih) / UNFM_P_SIZE,
 		    "vs-804: invalid position for append");
 	    /* indirect item has to be appended, set up key of that position */
 	    make_cpu_key (&tmp_key, inode,
@@ -871,16 +879,16 @@
 	unsigned long blocks;
 
 	inode_items_version (inode) = ITEM_VERSION_1;
-	inode->i_mode = le16_to_cpu (sd->sd_mode);
-	inode->i_nlink = le16_to_cpu (sd->sd_nlink);
-	inode->i_uid = le16_to_cpu (sd->sd_uid);
-	inode->i_gid = le16_to_cpu (sd->sd_gid);
-	inode->i_size = le32_to_cpu (sd->sd_size);
-	inode->i_atime = le32_to_cpu (sd->sd_atime);
-	inode->i_mtime = le32_to_cpu (sd->sd_mtime);
-	inode->i_ctime = le32_to_cpu (sd->sd_ctime);
+	inode->i_mode  = sd_v1_mode(sd);
+	inode->i_nlink = sd_v1_nlink(sd);
+	inode->i_uid   = sd_v1_uid(sd);
+	inode->i_gid   = sd_v1_gid(sd);
+	inode->i_size  = sd_v1_size(sd);
+	inode->i_atime = sd_v1_atime(sd);
+	inode->i_mtime = sd_v1_mtime(sd);
+	inode->i_ctime = sd_v1_ctime(sd);
 
-	inode->i_blocks = le32_to_cpu (sd->u.sd_blocks);
+	inode->i_blocks = sd_v1_blocks(sd);
 	inode->i_generation = INODE_PKEY (inode)->k_dir_id;
 	blocks = (inode->i_size + 511) >> 9;
 	blocks = _ROUND_UP (blocks, inode->i_blksize >> 9);
@@ -893,8 +901,8 @@
 	    inode->i_blocks = blocks;
 	}
 
-	rdev = le32_to_cpu (sd->u.sd_rdev);
-	inode->u.reiserfs_i.i_first_direct_byte = le32_to_cpu (sd->sd_first_direct_byte);
+        rdev = sd_v1_rdev(sd);
+	inode->u.reiserfs_i.i_first_direct_byte = sd_v1_first_direct_byte(sd);
     } else {
 	// new stat data found, but object may have old items
 	// (directories and symlinks)
@@ -902,24 +910,26 @@
 
 	/* both old and new directories have old keys */
 	//version = (S_ISDIR (sd->sd_mode) ? ITEM_VERSION_1 : ITEM_VERSION_2);
-	if (S_ISDIR (sd->sd_mode) || S_ISLNK (sd->sd_mode))
-	    inode_items_version (inode) = ITEM_VERSION_1;
-	else
-	    inode_items_version (inode) = ITEM_VERSION_2;
-	inode->i_mode = le16_to_cpu (sd->sd_mode);
-	inode->i_nlink = le32_to_cpu (sd->sd_nlink);
-	inode->i_uid = le32_to_cpu (sd->sd_uid);
-	inode->i_size = le64_to_cpu (sd->sd_size);
-	inode->i_gid = le32_to_cpu (sd->sd_gid);
-	inode->i_mtime = le32_to_cpu (sd->sd_mtime);
-	inode->i_atime = le32_to_cpu (sd->sd_atime);
-	inode->i_ctime = le32_to_cpu (sd->sd_ctime);
-	inode->i_blocks = le32_to_cpu (sd->sd_blocks);
-	rdev = le32_to_cpu (sd->u.sd_rdev);
+
+	inode->i_mode   = sd_v2_mode(sd);
+	inode->i_nlink  = sd_v2_nlink(sd);
+	inode->i_uid    = sd_v2_uid(sd);
+	inode->i_size   = sd_v2_size(sd);
+	inode->i_gid    = sd_v2_gid(sd);
+	inode->i_mtime  = sd_v2_mtime(sd);
+	inode->i_atime  = sd_v2_atime(sd);
+	inode->i_ctime  = sd_v2_ctime(sd);
+	inode->i_blocks = sd_v2_blocks(sd);
+        rdev            = sd_v2_rdev(sd);
 	if( S_ISCHR( inode -> i_mode ) || S_ISBLK( inode -> i_mode ) )
 	    inode->i_generation = INODE_PKEY (inode)->k_dir_id;
 	else
-	    inode->i_generation = le32_to_cpu( sd->u.sd_generation );
+            inode->i_generation = sd_v2_generation(sd);
+
+	if (S_ISDIR (inode->i_mode) || S_ISLNK (inode->i_mode))
+	    inode_items_version (inode) = ITEM_VERSION_1;
+	else
+	    inode_items_version (inode) = ITEM_VERSION_2;
     }
 
     /* nopack = 0, by default */
@@ -948,19 +958,21 @@
 {
     struct stat_data * sd_v2 = (struct stat_data *)sd;
 
-    sd_v2->sd_mode = cpu_to_le16 (inode->i_mode);
-    sd_v2->sd_nlink = cpu_to_le16 (inode->i_nlink);
-    sd_v2->sd_uid = cpu_to_le32 (inode->i_uid);
-    sd_v2->sd_size = cpu_to_le64 (inode->i_size);
-    sd_v2->sd_gid = cpu_to_le32 (inode->i_gid);
-    sd_v2->sd_mtime = cpu_to_le32 (inode->i_mtime);
-    sd_v2->sd_atime = cpu_to_le32 (inode->i_atime);
-    sd_v2->sd_ctime = cpu_to_le32 (inode->i_ctime);
-    sd_v2->sd_blocks = cpu_to_le32 (inode->i_blocks);
+    set_sd_v2_mode(sd_v2, inode->i_mode );
+    set_sd_v2_nlink(sd_v2, inode->i_nlink );
+    set_sd_v2_uid(sd_v2, inode->i_uid );
+    set_sd_v2_size(sd_v2, inode->i_size );
+    set_sd_v2_gid(sd_v2, inode->i_gid );
+    set_sd_v2_mtime(sd_v2, inode->i_mtime );
+    set_sd_v2_atime(sd_v2, inode->i_atime );
+    set_sd_v2_ctime(sd_v2, inode->i_ctime );
+    set_sd_v2_blocks(sd_v2, inode->i_blocks );
     if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
-	sd_v2->u.sd_rdev = cpu_to_le32 (inode->i_rdev);
-    } else {
-	sd_v2->u.sd_generation = cpu_to_le32( inode -> i_generation );
+        set_sd_v2_rdev(sd_v2, inode->i_rdev );
+}
+    else
+    {
+        set_sd_v2_generation(sd_v2, inode->i_generation);
     }
 }
 
@@ -970,21 +982,22 @@
 {
     struct stat_data_v1 * sd_v1 = (struct stat_data_v1 *)sd;
 
-    sd_v1->sd_mode = cpu_to_le16 (inode->i_mode);
-    sd_v1->sd_uid = cpu_to_le16 (inode->i_uid);
-    sd_v1->sd_gid = cpu_to_le16 (inode->i_gid);
-    sd_v1->sd_nlink = cpu_to_le16 (inode->i_nlink);
-    sd_v1->sd_size = cpu_to_le32 (inode->i_size);
-    sd_v1->sd_atime = cpu_to_le32 (inode->i_atime);
-    sd_v1->sd_ctime = cpu_to_le32 (inode->i_ctime);
-    sd_v1->sd_mtime = cpu_to_le32 (inode->i_mtime);
+    set_sd_v1_mode(sd_v1, inode->i_mode );
+    set_sd_v1_uid(sd_v1, inode->i_uid );
+    set_sd_v1_gid(sd_v1, inode->i_gid );
+    set_sd_v1_nlink(sd_v1, inode->i_nlink );
+    set_sd_v1_size(sd_v1, inode->i_size );
+    set_sd_v1_atime(sd_v1, inode->i_atime );
+    set_sd_v1_ctime(sd_v1, inode->i_ctime );
+    set_sd_v1_mtime(sd_v1, inode->i_mtime );
+
     if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
-	sd_v1->u.sd_rdev = cpu_to_le32 (inode->i_rdev);
+        set_sd_v1_rdev(sd_v1, inode->i_rdev );
     else
-	sd_v1->u.sd_blocks = cpu_to_le32 (inode->i_blocks);
+        set_sd_v1_blocks(sd_v1, inode->i_blocks );
 
     // Sigh. i_first_direct_byte is back
-    sd_v1->sd_first_direct_byte = cpu_to_le32 (inode->u.reiserfs_i.i_first_direct_byte);
+    set_sd_v1_first_direct_byte(sd_v1, inode->u.reiserfs_i.i_first_direct_byte);
 }
 
 
@@ -1110,8 +1123,8 @@
     retval = search_item (inode->i_sb, &key, &path_to_sd);
     if (retval == IO_ERROR) {
 	reiserfs_warning ("vs-13070: reiserfs_read_inode2: "
-			  "i/o failure occurred trying to find stat data of %K\n",
-			  &key);
+                    "i/o failure occurred trying to find stat data of %K\n",
+                    &key);
 	make_bad_inode(inode) ;
 	return;
     }
@@ -1297,6 +1310,10 @@
         return ;
     }
     lock_kernel() ;
+
+    /* this is really only used for atime updates, so they don't have
+    ** to be included in O_SYNC or fsync
+    */
     journal_begin(&th, inode->i_sb, 1) ;
     reiserfs_update_sd (&th, inode);
     journal_end(&th, inode->i_sb, 1) ;
@@ -1317,7 +1334,8 @@
 /* stat data of new object is inserted already, this inserts the item
    containing "." and ".." entries */
 static int reiserfs_new_directory (struct reiserfs_transaction_handle *th, 
-				   struct item_head * ih, struct path * path, const struct inode * dir)
+				   struct item_head * ih, struct path * path,
+				   const struct inode * dir)
 {
     struct super_block * sb = th->t_super;
     char empty_dir [EMPTY_DIR_SIZE];
@@ -1335,14 +1353,14 @@
 	make_le_item_head (ih, 0, ITEM_VERSION_1, DOT_OFFSET, TYPE_DIRENTRY, EMPTY_DIR_SIZE_V1, 2);
 	
 	make_empty_dir_item_v1 (body, ih->ih_key.k_dir_id, ih->ih_key.k_objectid,
-				le32_to_cpu (INODE_PKEY (dir)->k_dir_id), 
-				le32_to_cpu (INODE_PKEY (dir)->k_objectid));
+				INODE_PKEY (dir)->k_dir_id, 
+				INODE_PKEY (dir)->k_objectid );
     } else {
 	make_le_item_head (ih, 0, ITEM_VERSION_1, DOT_OFFSET, TYPE_DIRENTRY, EMPTY_DIR_SIZE, 2);
 	
 	make_empty_dir_item (body, ih->ih_key.k_dir_id, ih->ih_key.k_objectid,
-			     le32_to_cpu (INODE_PKEY (dir)->k_dir_id), 
-			     le32_to_cpu (INODE_PKEY (dir)->k_objectid));
+		   		INODE_PKEY (dir)->k_dir_id, 
+		   		INODE_PKEY (dir)->k_objectid );
     }
     
     /* look for place in the tree for new item */
@@ -1671,6 +1689,7 @@
     ** (it will unmap bh if it packs).
     */
     journal_begin(&th, p_s_inode->i_sb,  JOURNAL_PER_BALANCE_CNT * 2 ) ;
+    reiserfs_update_inode_transaction(p_s_inode) ;
     windex = push_journal_writer("reiserfs_vfs_truncate_file") ;
     reiserfs_do_truncate (&th, p_s_inode, page, update_timestamps) ;
     pop_journal_writer(windex) ;
@@ -1717,6 +1736,7 @@
 start_over:
     lock_kernel() ;
     journal_begin(&th, inode->i_sb, jbegin_count) ;
+    reiserfs_update_inode_transaction(inode) ;
 
     make_cpu_key(&key, inode, byte_offset, TYPE_ANY, 3) ;
 
@@ -1737,18 +1757,18 @@
 	if (bytes_copied > 0) {
 	    reiserfs_warning("clm-6002: bytes_copied %d\n", bytes_copied) ;
 	}
-        if (!item[pos_in_item]) {
+        if (!get_block_num(item, pos_in_item)) {
 	    /* crap, we are writing to a hole */
 	    use_get_block = 1;
 	    goto out ;
 	}
-	set_block_dev_mapped(bh_result, le32_to_cpu(item[pos_in_item]), inode);
-	mark_buffer_uptodate(bh_result, 1);
+	set_block_dev_mapped(bh_result, get_block_num(item,pos_in_item),inode);
+        mark_buffer_uptodate(bh_result, 1);
     } else if (is_direct_le_ih(ih)) {
         char *p ; 
         p = page_address(bh_result->b_page) ;
         p += (byte_offset -1) & (PAGE_CACHE_SIZE - 1) ;
-        copy_size = le16_to_cpu(ih->ih_item_len) - pos_in_item ;
+        copy_size = ih_item_len(ih) - pos_in_item;
 
 	fs_gen = get_generation(inode->i_sb) ;
 	copy_item_head(&tmp_ih, ih) ;
@@ -1763,7 +1783,7 @@
 	journal_mark_dirty(&th, inode->i_sb, bh) ;
 	bytes_copied += copy_size ;
 	set_block_dev_mapped(bh_result, 0, inode);
-	mark_buffer_uptodate(bh_result, 1);
+        mark_buffer_uptodate(bh_result, 1);
 
 	/* are there still bytes left? */
         if (bytes_copied < bh_result->b_size && 
@@ -1944,26 +1964,38 @@
   return generic_block_bmap(as, block, reiserfs_bmap) ;
 }
 
-static int reiserfs_commit_write(struct file *f, struct page *page,
-			         unsigned from, unsigned to) {
-    struct inode *inode = page->mapping->host;
-    int ret ;
-
+static int reiserfs_commit_write(struct file *f, struct page *page, 
+                                 unsigned from, unsigned to) {
+    struct inode *inode = page->mapping->host ;
+    loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
+    int ret ; 
+    
     reiserfs_wait_on_write_block(inode->i_sb) ;
+ 
+    /* generic_commit_write does this for us, but does not update the
+    ** transaction tracking stuff when the size changes.  So, we have
+    ** to do the i_size updates here.
+    */
+    if (pos > inode->i_size) {
+	struct reiserfs_transaction_handle th ;
+	lock_kernel() ;
+	journal_begin(&th, inode->i_sb, 1) ;
+	reiserfs_update_inode_transaction(inode) ;
+	inode->i_size = pos ;
+	reiserfs_update_sd(&th, inode) ;
+	journal_end(&th, inode->i_sb, 1) ;
+	unlock_kernel() ;
+    }
+ 
     ret = generic_commit_write(f, page, from, to) ;
 
     /* we test for O_SYNC here so we can commit the transaction
     ** for any packed tails the file might have had
     */
     if (f->f_flags & O_SYNC) {
-	struct reiserfs_transaction_handle th ;
 	lock_kernel() ;
-	journal_begin(&th, inode->i_sb, 1) ;
-	reiserfs_prepare_for_journal(inode->i_sb, 
-	                             SB_BUFFER_WITH_SB(inode->i_sb), 1) ;
-	journal_mark_dirty(&th, inode->i_sb, SB_BUFFER_WITH_SB(inode->i_sb)) ;
-	journal_end_sync(&th, inode->i_sb, 1) ;
-	unlock_kernel() ;
+ 	reiserfs_commit_for_inode(inode) ;
+	unlock_kernel();
     }
     return ret ;
 }
diff -urN linux-2.4.13-pre1/fs/reiserfs/item_ops.c linux/fs/reiserfs/item_ops.c
--- linux-2.4.13-pre1/fs/reiserfs/item_ops.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/item_ops.c	Mon Dec  3 23:17:33 2001
@@ -48,13 +48,15 @@
     if (stat_data_v1 (ih)) {
       	struct stat_data_v1 * sd = (struct stat_data_v1 *)item;
 
-	printk ("\t0%-6o | %6u | %2u | %d | %s\n", sd->sd_mode, sd->sd_size,
-		sd->sd_nlink, sd->sd_first_direct_byte, print_time (sd->sd_mtime));
+	printk ("\t0%-6o | %6u | %2u | %d | %s\n", sd_v1_mode(sd),
+                sd_v1_size(sd), sd_v1_nlink(sd), sd_v1_first_direct_byte(sd),
+                print_time( sd_v1_mtime(sd) ) );
     } else {
 	struct stat_data * sd = (struct stat_data *)item;
 
-	printk ("\t0%-6o | %6Lu | %2u | %d | %s\n", sd->sd_mode, (unsigned long long)(sd->sd_size),
-		sd->sd_nlink, sd->u.sd_rdev, print_time (sd->sd_mtime));
+	printk ("\t0%-6o | %6Lu | %2u | %d | %s\n", sd_v2_mode(sd),
+            (unsigned long long)sd_v2_size(sd), sd_v2_nlink(sd),
+            sd_v2_rdev(sd), print_time(sd_v2_mtime(sd)));
     }
 }
 
@@ -130,7 +132,7 @@
 //
 static int direct_bytes_number (struct item_head * ih, int block_size)
 {
-  return le16_to_cpu (ih->ih_item_len);
+  return ih_item_len(ih);
 }
 
 
@@ -156,7 +158,7 @@
 
 //    return;
     printk ("\"");
-    while (j < ih->ih_item_len)
+    while (j < ih_item_len(ih))
 	printk ("%c", item[j++]);
     printk ("\"\n");
 }
@@ -234,7 +236,7 @@
 
 static int indirect_bytes_number (struct item_head * ih, int block_size)
 {
-  return le16_to_cpu (ih->ih_item_len) / UNFM_P_SIZE * block_size; //- get_ih_free_space (ih);
+  return ih_item_len(ih) / UNFM_P_SIZE * block_size; //- get_ih_free_space (ih);
 }
 
 
@@ -299,14 +301,14 @@
 
     unp = (__u32 *)item;
 
-    if (ih->ih_item_len % UNFM_P_SIZE)
+    if (ih_item_len(ih) % UNFM_P_SIZE)
 	printk ("indirect_print_item: invalid item len");  
 
     printk ("%d pointers\n[ ", (int)I_UNFM_NUM (ih));
     for (j = 0; j < I_UNFM_NUM (ih); j ++) {
-	if (sequence_finished (prev, &num, unp[j])) {
+	if (sequence_finished (prev, &num, get_block_num(unp, j))) {
 	    print_sequence (prev, num);
-	    start_new_sequence (&prev, &num, unp[j]);
+	    start_new_sequence (&prev, &num, get_block_num(unp, j));
 	}
     }
     print_sequence (prev, num);
@@ -424,8 +426,8 @@
     deh = (struct reiserfs_de_head *)item;
 
     for (i = 0; i < I_ENTRY_COUNT (ih); i ++, deh ++) {
-	namelen = (i ? ((deh - 1)->deh_location) : ih->ih_item_len) - deh->deh_location;
-	name = item + deh->deh_location;
+	namelen = (i ? (deh_location(deh - 1)) : ih_item_len(ih)) - deh_location(deh);
+	name = item + deh_location(deh);
 	if (name[namelen-1] == 0)
 	  namelen = strlen (name);
 	namebuf[0] = '"';
@@ -441,7 +443,7 @@
 
 	printk ("%d:  %-15s%-15d%-15d%-15Ld%-15Ld(%s)\n", 
 		i, namebuf,
-		deh->deh_dir_id, deh->deh_objectid,
+		deh_dir_id(deh), deh_objectid(deh),
 		GET_HASH_VALUE (deh_offset (deh)), GET_GENERATION_NUMBER ((deh_offset (deh))),
 		(de_hidden (deh)) ? "HIDDEN" : "VISIBLE");
     }
@@ -466,9 +468,9 @@
 
 struct direntry_uarea {
     int flags;
-    short entry_count;
-    short entry_sizes[1];
-};
+    __u16 entry_count;
+    __u16 entry_sizes[1];
+} __attribute__ ((__packed__)) ;
 
 
 /*
@@ -531,8 +533,9 @@
     
     for (i = 0; i < dir_u->entry_count; i ++) {
 	j = old_entry_num (is_affected, i, vn->vn_pos_in_item, vn->vn_mode);
-	dir_u->entry_sizes[i] = (j ? le16_to_cpu (deh[j - 1].deh_location) : le16_to_cpu (vi->vi_ih->ih_item_len)) -
-	    le16_to_cpu (deh[j].deh_location) + DEH_SIZE;
+        dir_u->entry_sizes[i] = (j ? deh_location( &(deh[j - 1]) ) :
+                                ih_item_len (vi->vi_ih)) -
+                                deh_location( &(deh[j])) + DEH_SIZE;
     }
 
     size += (dir_u->entry_count * sizeof (short));
diff -urN linux-2.4.13-pre1/fs/reiserfs/journal.c linux/fs/reiserfs/journal.c
--- linux-2.4.13-pre1/fs/reiserfs/journal.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/journal.c	Mon Dec  3 23:17:33 2001
@@ -746,7 +746,7 @@
   }
   atomic_set(&(jl->j_commit_flushing), 0) ;
   wake_up(&(jl->j_commit_wait)) ;
-  
+
   s->s_dirt = 1 ;
   return 0 ;
 }
@@ -1936,7 +1936,7 @@
                                          where it belongs */
 
   INIT_LIST_HEAD (&SB_JOURNAL(p_s_sb)->j_prealloc_list);
-  
+
   if (reiserfs_dont_log (p_s_sb))
     return 0;
 
@@ -2319,6 +2319,11 @@
 ** will wait until the current transaction is done/commited before returning 
 */
 int journal_end_sync(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, unsigned long nblocks) {
+
+  if (SB_JOURNAL(p_s_sb)->j_len == 0) {
+    reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), 1) ;
+    journal_mark_dirty(th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)) ;
+  }
   return do_journal_end(th, p_s_sb, nblocks, COMMIT_NOW | WAIT) ;
 }
 
@@ -2416,8 +2421,8 @@
     journal_mark_dirty(&th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)) ;
     do_journal_end(&th, p_s_sb,1, COMMIT_NOW | WAIT) ;
   }
-  reiserfs_journal_kupdate(p_s_sb) ;
-  return 0 ;
+   reiserfs_journal_kupdate(p_s_sb) ;
+   return 0 ;
 }
 
 /*
@@ -2603,6 +2608,41 @@
   return 0 ;
 }
 
+void reiserfs_update_inode_transaction(struct inode *inode) {
+  
+  inode->u.reiserfs_i.i_trans_index = SB_JOURNAL_LIST_INDEX(inode->i_sb);
+
+  inode->u.reiserfs_i.i_trans_id = SB_JOURNAL(inode->i_sb)->j_trans_id ;
+}
+
+static int reiserfs_inode_in_this_transaction(struct inode *inode) {
+  if (inode->u.reiserfs_i.i_trans_id == SB_JOURNAL(inode->i_sb)->j_trans_id || 
+      inode->u.reiserfs_i.i_trans_id == 0) {
+    return 1; 
+  } 
+  return 0 ;
+}
+
+void reiserfs_commit_for_inode(struct inode *inode) {
+  struct reiserfs_journal_list *jl ;
+  struct reiserfs_transaction_handle th ;
+  struct super_block *sb = inode->i_sb ;
+
+  jl = SB_JOURNAL_LIST(sb) + inode->u.reiserfs_i.i_trans_index ;
+
+  /* is it from the current transaction, or from an unknown transaction? */
+  if (reiserfs_inode_in_this_transaction(inode)) {
+    journal_join(&th, sb, 1) ;
+    reiserfs_update_inode_transaction(inode) ;
+    journal_end_sync(&th, sb, 1) ;
+  } else if (jl->j_trans_id == inode->u.reiserfs_i.i_trans_id) {
+    flush_commit_list(sb, jl, 1) ;
+  }
+  /* if the transaction id does not match, this list is long since flushed
+  ** and we don't have to do anything here
+  */
+}
+
 void reiserfs_restore_prepared_buffer(struct super_block *p_s_sb, 
                                       struct buffer_head *bh) {
   if (reiserfs_dont_log (p_s_sb))
@@ -2645,7 +2685,7 @@
   }
 }
 
-/*
+/* 
 ** long and ugly.  If flush, will not return until all commit
 ** blocks and all real buffers in the trans are on disk.
 ** If no_async, won't return until all commit blocks are on disk.
diff -urN linux-2.4.13-pre1/fs/reiserfs/lbalance.c linux/fs/reiserfs/lbalance.c
--- linux-2.4.13-pre1/fs/reiserfs/lbalance.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/lbalance.c	Mon Dec  3 23:17:33 2001
@@ -42,9 +42,10 @@
     /* length of all record to be copied and first byte of the last of them */
     deh = B_I_DEH (source, ih);
     if (copy_count) {
-	copy_records_len = (from ? deh[from - 1].deh_location : ih->ih_item_len) - 
-	    deh[from + copy_count - 1].deh_location;
-	records = source->b_data + ih->ih_item_location + deh[from + copy_count - 1].deh_location;
+	copy_records_len = (from ? deh_location( &(deh[from - 1]) ) :
+            ih_item_len(ih)) - deh_location( &(deh[from + copy_count - 1]));
+	records = source->b_data + ih_location(ih) +
+                                deh_location( &(deh[from + copy_count - 1]));
     } else {
 	copy_records_len = 0;
 	records = 0;
@@ -55,26 +56,26 @@
 
     /* if there are no items in dest or the first/last item in dest is not item of the same directory */
     if ( (item_num_in_dest == - 1) ||
-	(last_first == FIRST_TO_LAST && le_key_k_offset (ih_version (ih), &(ih->ih_key)) == DOT_OFFSET) ||
+	(last_first == FIRST_TO_LAST && le_ih_k_offset (ih) == DOT_OFFSET) ||
 	    (last_first == LAST_TO_FIRST && comp_short_le_keys/*COMP_SHORT_KEYS*/ (&ih->ih_key, B_N_PKEY (dest, item_num_in_dest)))) {
 	/* create new item in dest */
 	struct item_head new_ih;
 
 	/* form item header */
 	memcpy (&new_ih.ih_key, &ih->ih_key, KEY_SIZE);
-	new_ih.ih_version = cpu_to_le16 (ITEM_VERSION_1);
+	put_ih_version( &new_ih, ITEM_VERSION_1 );
 	/* calculate item len */
-	new_ih.ih_item_len = cpu_to_le16 (DEH_SIZE * copy_count + copy_records_len);
-	I_ENTRY_COUNT(&new_ih) = 0;
+	put_ih_item_len( &new_ih, DEH_SIZE * copy_count + copy_records_len );
+	put_ih_entry_count( &new_ih, 0 );
     
 	if (last_first == LAST_TO_FIRST) {
 	    /* form key by the following way */
 	    if (from < I_ENTRY_COUNT(ih)) {
-		set_le_ih_k_offset (&new_ih, cpu_to_le32 (le32_to_cpu (deh[from].deh_offset)));
+		set_le_ih_k_offset( &new_ih, deh_offset( &(deh[from]) ) );
 		/*memcpy (&new_ih.ih_key.k_offset, &deh[from].deh_offset, SHORT_KEY_SIZE);*/
 	    } else {
 		/* no entries will be copied to this item in this function */
-		set_le_ih_k_offset (&new_ih, cpu_to_le32 (U32_MAX));
+		set_le_ih_k_offset (&new_ih, U32_MAX);
 		/* this item is not yet valid, but we want I_IS_DIRECTORY_ITEM to return 1 for it, so we -1 */
 	    }
 	    set_le_key_k_type (ITEM_VERSION_1, &(new_ih.ih_key), TYPE_DIRENTRY);
@@ -123,12 +124,12 @@
       /* there is nothing to merge */
       return 0;
       
-    RFALSE( ! ih->ih_item_len, "vs-10010: item can not have empty length");
+    RFALSE( ! ih_item_len(ih), "vs-10010: item can not have empty length");
       
     if ( is_direntry_le_ih (ih) ) {
       if ( bytes_or_entries == -1 )
 	/* copy all entries to dest */
-	bytes_or_entries = le16_to_cpu (ih->u.ih_entry_count);
+	bytes_or_entries = ih_entry_count(ih);
       leaf_copy_dir_entries (dest_bi, src, FIRST_TO_LAST, 0, 0, bytes_or_entries);
       return 1;
     }
@@ -137,11 +138,11 @@
        part defined by 'bytes_or_entries'; if bytes_or_entries == -1 copy whole body; don't create new item header
        */
     if ( bytes_or_entries == -1 )
-      bytes_or_entries = le16_to_cpu (ih->ih_item_len);
+      bytes_or_entries = ih_item_len(ih);
 
 #ifdef CONFIG_REISERFS_CHECK
     else {
-      if (bytes_or_entries == le16_to_cpu (ih->ih_item_len) && is_indirect_le_ih(ih))
+      if (bytes_or_entries == ih_item_len(ih) && is_indirect_le_ih(ih))
 	if (get_ih_free_space (ih))
 	  reiserfs_panic (0, "vs-10020: leaf_copy_boundary_item: "
 			  "last unformatted node must be filled entirely (%h)",
@@ -152,14 +153,14 @@
     /* merge first item (or its part) of src buffer with the last
        item of dest buffer. Both are of the same file */
     leaf_paste_in_buffer (dest_bi,
-			  dest_nr_item - 1, dih->ih_item_len, bytes_or_entries, B_I_PITEM(src,ih), 0
+			  dest_nr_item - 1, ih_item_len(dih), bytes_or_entries, B_I_PITEM(src,ih), 0
 			  );
       
     if (is_indirect_le_ih (dih)) {
       RFALSE( get_ih_free_space (dih),
-	      "vs-10030: merge to left: last unformatted node of non-last indirect item %h must have zero free space", 
-	      ih);
-      if (bytes_or_entries == le16_to_cpu (ih->ih_item_len))
+              "vs-10030: merge to left: last unformatted node of non-last indirect item %h must have zerto free space",
+              ih);
+      if (bytes_or_entries == ih_item_len(ih))
 	set_ih_free_space (dih, get_ih_free_space (ih));
     }
     
@@ -182,9 +183,9 @@
   if ( is_direntry_le_ih (ih)) {
     if ( bytes_or_entries == -1 )
       /* bytes_or_entries = entries number in last item body of SOURCE */
-      bytes_or_entries = le16_to_cpu (ih->u.ih_entry_count);
+      bytes_or_entries = ih_entry_count(ih);
     
-    leaf_copy_dir_entries (dest_bi, src, LAST_TO_FIRST, src_nr_item - 1, le16_to_cpu (ih->u.ih_entry_count) - bytes_or_entries, bytes_or_entries);
+    leaf_copy_dir_entries (dest_bi, src, LAST_TO_FIRST, src_nr_item - 1, ih_entry_count(ih) - bytes_or_entries, bytes_or_entries);
     return 1;
   }
 
@@ -194,16 +195,16 @@
      */
   
   RFALSE( is_indirect_le_ih(ih) && get_ih_free_space (ih),
-	  "vs-10040: merge to right: last unformatted node of non-last indirect item must be filled entirely (%h)",
+          "vs-10040: merge to right: last unformatted node of non-last indirect item must be filled entirely (%h)",
 		    ih);
 
   if ( bytes_or_entries == -1 ) {
     /* bytes_or_entries = length of last item body of SOURCE */
-    bytes_or_entries = ih->ih_item_len;
+    bytes_or_entries = ih_item_len(ih);
 
-    RFALSE( le_ih_k_offset (dih) != 
-	    le_ih_k_offset (ih) + op_bytes_number (ih, src->b_size),
-	    "vs-10050: items %h and %h do not match", ih, dih);
+    RFALSE( le_ih_k_offset (dih) !=
+            le_ih_k_offset (ih) + op_bytes_number (ih, src->b_size),
+            "vs-10050: items %h and %h do not match", ih, dih);
 
     /* change first item key of the DEST */
     set_le_ih_k_offset (dih, le_ih_k_offset (ih));
@@ -213,9 +214,9 @@
     set_le_ih_k_type (dih, le_ih_k_type (ih));
   } else {
     /* merge to right only part of item */
-    RFALSE( le16_to_cpu (ih->ih_item_len) <= bytes_or_entries,
-	    "vs-10060: no so much bytes %lu (needed %lu)",
-	    ih->ih_item_len, bytes_or_entries);
+    RFALSE( ih_item_len(ih) <= bytes_or_entries,
+            "vs-10060: no so much bytes %lu (needed %lu)",
+            ih_item_len(ih), bytes_or_entries);
     
     /* change first item key of the DEST */
     if ( is_direct_le_ih (dih) ) {
@@ -223,15 +224,15 @@
 	      "vs-10070: dih %h, bytes_or_entries(%d)", dih, bytes_or_entries);
       set_le_ih_k_offset (dih, le_ih_k_offset (dih) - bytes_or_entries);
     } else {
-      RFALSE( le_ih_k_offset (dih) <= 
-	      (bytes_or_entries / UNFM_P_SIZE) * dest->b_size,
-	      "vs-10080: dih %h, bytes_or_entries(%d)",
-	      dih, (bytes_or_entries/UNFM_P_SIZE)*dest->b_size);
+      RFALSE( le_ih_k_offset (dih) <=
+              (bytes_or_entries / UNFM_P_SIZE) * dest->b_size,
+              "vs-10080: dih %h, bytes_or_entries(%d)",
+              dih, (bytes_or_entries/UNFM_P_SIZE)*dest->b_size);
       set_le_ih_k_offset (dih, le_ih_k_offset (dih) - ((bytes_or_entries / UNFM_P_SIZE) * dest->b_size));
     }
   }
   
-  leaf_paste_in_buffer (dest_bi, 0, 0, bytes_or_entries, B_I_PITEM(src,ih) + ih->ih_item_len - bytes_or_entries, 0);
+  leaf_paste_in_buffer (dest_bi, 0, 0, bytes_or_entries, B_I_PITEM(src,ih) + ih_item_len(ih) - bytes_or_entries, 0);
   return 1;
 }
 
@@ -244,7 +245,7 @@
 				      int first, int cpy_num)
 {
     struct buffer_head * dest;
-    int nr;
+    int nr, free_space;
     int dest_before;
     int last_loc, last_inserted_loc, location;
     int i, j;
@@ -266,7 +267,9 @@
     if (cpy_num == 0)
 	return;
 
-    nr = le16_to_cpu ((blkh = B_BLK_HEAD(dest))->blk_nr_item);
+    blkh = B_BLK_HEAD(dest);
+    nr = blkh_nr_item( blkh );
+    free_space = blkh_free_space(blkh);
   
     /* we will insert items before 0-th or nr-th item in dest buffer. It depends of last_first parameter */
     dest_before = (last_first == LAST_TO_FIRST) ? 0 : nr;
@@ -274,9 +277,9 @@
     /* location of head of first new item */
     ih = B_N_PITEM_HEAD (dest, dest_before);
 
-    RFALSE( le16_to_cpu (blkh->blk_free_space) < cpy_num * IH_SIZE,
-	    "vs-10140: not enough free space for headers %d (needed %d)",
-	    B_FREE_SPACE (dest), cpy_num * IH_SIZE);
+    RFALSE( blkh_free_space(blkh) < cpy_num * IH_SIZE,
+            "vs-10140: not enough free space for headers %d (needed %d)",
+            B_FREE_SPACE (dest), cpy_num * IH_SIZE);
 
     /* prepare space for headers */
     memmove (ih + cpy_num, ih, (nr-dest_before) * IH_SIZE);
@@ -284,22 +287,24 @@
     /* copy item headers */
     memcpy (ih, B_N_PITEM_HEAD (src, first), cpy_num * IH_SIZE);
 
-    blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) - IH_SIZE * cpy_num);
+    free_space -= (IH_SIZE * cpy_num);
+    set_blkh_free_space( blkh, free_space );
 
     /* location of unmovable item */
-    j = location = (dest_before == 0) ? dest->b_size : (ih-1)->ih_item_location;
-    for (i = dest_before; i < nr + cpy_num; i ++)
-	ih[i-dest_before].ih_item_location =
-	    (location -= ih[i-dest_before].ih_item_len);
+    j = location = (dest_before == 0) ? dest->b_size : ih_location(ih-1);
+    for (i = dest_before; i < nr + cpy_num; i ++) {
+        location -= ih_item_len( ih + i - dest_before );
+        put_ih_location( ih + i - dest_before, location );
+    }
 
     /* prepare space for items */
-    last_loc = ih[nr+cpy_num-1-dest_before].ih_item_location;
-    last_inserted_loc = ih[cpy_num-1].ih_item_location;
+    last_loc = ih_location( &(ih[nr+cpy_num-1-dest_before]) );
+    last_inserted_loc = ih_location( &(ih[cpy_num-1]) );
 
     /* check free space */
-    RFALSE( le16_to_cpu (blkh->blk_free_space) < j - last_inserted_loc,
+    RFALSE( free_space < j - last_inserted_loc,
 	    "vs-10150: not enough free space for items %d (needed %d)",
-	    le16_to_cpu (blkh->blk_free_space), j - last_inserted_loc);
+            free_space, j - last_inserted_loc);
 
     memmove (dest->b_data + last_loc,
 	     dest->b_data + last_loc + j - last_inserted_loc,
@@ -310,17 +315,18 @@
 	    j - last_inserted_loc);
 
     /* sizes, item number */
-    blkh->blk_nr_item = cpu_to_le16 (le16_to_cpu (blkh->blk_nr_item) + cpy_num);
-    blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) - (j - last_inserted_loc));
+    set_blkh_nr_item( blkh, nr + cpy_num );
+    set_blkh_free_space( blkh, free_space - (j - last_inserted_loc) );
 
     do_balance_mark_leaf_dirty (dest_bi->tb, dest, 0);
 
     if (dest_bi->bi_parent) {
-	RFALSE( B_N_CHILD (dest_bi->bi_parent, dest_bi->bi_position)->dc_block_number != dest->b_blocknr,
-		"vs-10160: block number in bh does not match to field in disk_child structure %lu and %lu",
-		dest->b_blocknr, B_N_CHILD (dest_bi->bi_parent, dest_bi->bi_position)->dc_block_number);
-	B_N_CHILD (dest_bi->bi_parent, dest_bi->bi_position)->dc_size +=
-	    j - last_inserted_loc + IH_SIZE * cpy_num;
+	struct disk_child *t_dc;
+	t_dc = B_N_CHILD (dest_bi->bi_parent, dest_bi->bi_position);
+	RFALSE( dc_block_number(t_dc) != dest->b_blocknr,
+	        "vs-10160: block number in bh does not match to field in disk_child structure %lu and %lu",
+                dest->b_blocknr, dc_block_number(t_dc));
+	put_dc_size( t_dc, dc_size(t_dc) + (j - last_inserted_loc + IH_SIZE * cpy_num ) );
     
 	do_balance_mark_internal_dirty (dest_bi->tb, dest_bi->bi_parent, 0);
     }
@@ -349,18 +355,17 @@
 	       n_ih = new item_header;
 	    */
 	    memcpy (&n_ih, ih, IH_SIZE);
-	    n_ih.ih_item_len = cpu_to_le16 (cpy_bytes);
+	    put_ih_item_len( &n_ih, cpy_bytes );
 	    if (is_indirect_le_ih (ih)) {
-		RFALSE( cpy_bytes == le16_to_cpu (ih->ih_item_len) && 
-			get_ih_free_space (ih),
-			"vs-10180: when whole indirect item is bottle to left neighbor, it must have free_space==0 (not %lu)",
-			get_ih_free_space (ih));
+		RFALSE( cpy_bytes == ih_item_len(ih) && get_ih_free_space(ih),
+		        "vs-10180: when whole indirect item is bottle to left neighbor, it must have free_space==0 (not %lu)",
+                        get_ih_free_space (ih));
 		set_ih_free_space (&n_ih, 0);
 	    }
 
 	    RFALSE( op_is_left_mergeable (&(ih->ih_key), src->b_size),
 		    "vs-10190: bad mergeability of item %h", ih);
-	    n_ih.ih_version = ih->ih_version;;
+	    n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */
 	    leaf_insert_into_buf (dest_bi, B_NR_ITEMS(dest), &n_ih, B_N_PITEM (src, item_num), 0);
 	}
     } else {
@@ -375,24 +380,28 @@
 	       n_ih = new item_header;
 	    */
 	    memcpy (&n_ih, ih, SHORT_KEY_SIZE);
-	    n_ih.ih_version = cpu_to_le16 (ih_version (ih));
+
+	    n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */
+
 	    if (is_direct_le_ih (ih)) {
-		set_le_ih_k_offset (&n_ih, le_ih_k_offset (ih) + le16_to_cpu (ih->ih_item_len) - cpy_bytes);
+		set_le_ih_k_offset (&n_ih, le_ih_k_offset (ih) + ih_item_len(ih) - cpy_bytes);
 		set_le_ih_k_type (&n_ih, TYPE_DIRECT);
 		set_ih_free_space (&n_ih, MAX_US_INT);
 	    } else {
 		/* indirect item */
 		RFALSE( !cpy_bytes && get_ih_free_space (ih),
-			"vs-10200: ih->ih_free_space must be 0 when indirect item will be appended");
-		set_le_ih_k_offset (&n_ih, le_ih_k_offset (ih) + (le16_to_cpu (ih->ih_item_len) - cpy_bytes) / UNFM_P_SIZE * dest->b_size);
+		        "vs-10200: ih->ih_free_space must be 0 when indirect item will be appended");
+		set_le_ih_k_offset (&n_ih, le_ih_k_offset (ih) + (ih_item_len(ih) - cpy_bytes) / UNFM_P_SIZE * dest->b_size);
 		set_le_ih_k_type (&n_ih, TYPE_INDIRECT);
 		set_ih_free_space (&n_ih, get_ih_free_space (ih));
 	    }
       
 	    /* set item length */
-	    n_ih.ih_item_len = cpu_to_le16 (cpy_bytes);
-	    n_ih.ih_version = cpu_to_le16 (le16_to_cpu (ih->ih_version));
-	    leaf_insert_into_buf (dest_bi, 0, &n_ih, B_N_PITEM(src,item_num) + le16_to_cpu (ih->ih_item_len) - cpy_bytes, 0);
+	    put_ih_item_len( &n_ih, cpy_bytes );
+
+	    n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */
+
+	    leaf_insert_into_buf (dest_bi, 0, &n_ih, B_N_PITEM(src,item_num) + ih_item_len(ih) - cpy_bytes, 0);
 	}
     }
 }
@@ -602,21 +611,13 @@
       if (PATH_H_POSITION (tb->tb_path, 1) == 0)
 	replace_key (tb, tb->CFL[0], tb->lkey[0], PATH_H_PPARENT (tb->tb_path, 0), 0);
 
-#if 0      
-      /* change right_delimiting_key field in L0's block header */
-      copy_key (B_PRIGHT_DELIM_KEY(tb->L[0]), B_PRIGHT_DELIM_KEY (S0));
-#endif
     } else {     
       /* replace lkey in CFL[0] by 0-th key from S[0]; */
       replace_key (tb, tb->CFL[0], tb->lkey[0], S0, 0);
       
-#if 0
-      /* change right_delimiting_key field in L0's block header */
-      copy_key (B_PRIGHT_DELIM_KEY(tb->L[0]), B_N_PKEY (S0, 0));
-#endif
-      RFALSE( (shift_bytes != -1 && 
-	       !(is_direntry_le_ih (B_N_PITEM_HEAD (S0, 0))
-		 && !I_ENTRY_COUNT (B_N_PITEM_HEAD (S0, 0)))) &&
+      RFALSE( (shift_bytes != -1 &&
+              !(is_direntry_le_ih (B_N_PITEM_HEAD (S0, 0))
+                && !I_ENTRY_COUNT (B_N_PITEM_HEAD (S0, 0)))) &&
 	      (!op_is_left_mergeable (B_N_PKEY (S0, 0), S0->b_size)),
 	      "vs-10280: item must be mergeable");
     }
@@ -651,10 +652,6 @@
   if (shift_num) {
     replace_key (tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
 
-#if 0
-    /* change right_delimiting_key field in S0's block header */
-    copy_key (B_PRIGHT_DELIM_KEY(S0), B_N_PKEY (tb->R[0], 0));
-#endif
   }
 
   return ret_value;
@@ -714,10 +711,10 @@
 
 	    if (is_direntry_le_ih (ih = B_N_PITEM_HEAD(bh, B_NR_ITEMS(bh)-1))) 	/* the last item is directory  */
 	        /* len = numbers of directory entries in this item */
-	        len = le16_to_cpu (ih->u.ih_entry_count);
+		len = ih_entry_count(ih);
 	    else
 	        /* len = body len of item */
- 	        len = le16_to_cpu (ih->ih_item_len);
+		len = ih_item_len(ih);
 
 	    /* delete the part of the last item of the bh 
 	       do not delete item header
@@ -735,7 +732,7 @@
 			   int zeros_number)
 {
     struct buffer_head * bh = bi->bi_bh;
-    int nr;
+    int nr, free_space;
     struct block_head * blkh;
     struct item_head * ih;
     int i;
@@ -743,37 +740,39 @@
     char * to;
 
 
-    nr = le16_to_cpu ((blkh = B_BLK_HEAD (bh))->blk_nr_item);
+    blkh = B_BLK_HEAD(bh);
+    nr = blkh_nr_item(blkh);
+    free_space = blkh_free_space( blkh );
 
     /* check free space */
-    RFALSE( le16_to_cpu (blkh->blk_free_space) < 
-	    le16_to_cpu (inserted_item_ih->ih_item_len) + IH_SIZE,
-	    "not enough free space in block %z, new item %h",
-	    bh, inserted_item_ih);
-    RFALSE( zeros_number > inserted_item_ih->ih_item_len,
-	    "vs-10172: zero number == %d, item length == %d", 
-	    zeros_number, inserted_item_ih->ih_item_len);
+    RFALSE( free_space < ih_item_len(inserted_item_ih) + IH_SIZE,
+            "vs-10170: not enough free space in block %z, new item %h",
+            bh, inserted_item_ih);
+    RFALSE( zeros_number > ih_item_len(inserted_item_ih),
+	    "vs-10172: zero number == %d, item length == %d",
+            zeros_number, ih_item_len(inserted_item_ih));
 
 
     /* get item new item must be inserted before */
     ih = B_N_PITEM_HEAD (bh, before);
 
     /* prepare space for the body of new item */
-    last_loc = nr ? ih[nr - before - 1].ih_item_location : bh->b_size;
-    unmoved_loc = before ? (ih-1)->ih_item_location : bh->b_size;
+    last_loc = nr ? ih_location( &(ih[nr - before - 1]) ) : bh->b_size;
+    unmoved_loc = before ? ih_location( ih-1 ) : bh->b_size;
+
 
-    memmove (bh->b_data + last_loc - inserted_item_ih->ih_item_len, 
+    memmove (bh->b_data + last_loc - ih_item_len(inserted_item_ih), 
 	     bh->b_data + last_loc, unmoved_loc - last_loc);
 
-    to = bh->b_data + unmoved_loc - inserted_item_ih->ih_item_len;
+    to = bh->b_data + unmoved_loc - ih_item_len(inserted_item_ih);
     memset (to, 0, zeros_number);
     to += zeros_number;
 
     /* copy body to prepared space */
     if (inserted_item_body)
-	memmove (to, inserted_item_body, inserted_item_ih->ih_item_len - zeros_number);
+	memmove (to, inserted_item_body, ih_item_len(inserted_item_ih) - zeros_number);
     else
-	memset(to, '\0', inserted_item_ih->ih_item_len - zeros_number);
+	memset(to, '\0', ih_item_len(inserted_item_ih) - zeros_number);
   
     /* insert item header */
     memmove (ih + 1, ih, IH_SIZE * (nr - before));
@@ -781,18 +780,21 @@
   
     /* change locations */
     for (i = before; i < nr + 1; i ++)
-	ih[i-before].ih_item_location =
-	    (unmoved_loc -= ih[i-before].ih_item_len);
+    {
+        unmoved_loc -= ih_item_len( &(ih[i-before]));
+	put_ih_location( &(ih[i-before]), unmoved_loc );
+    }
   
     /* sizes, free space, item number */
-    blkh->blk_nr_item = cpu_to_le16 (le16_to_cpu (blkh->blk_nr_item) + 1);
-    blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) - 
-					(IH_SIZE + inserted_item_ih->ih_item_len));
-
+    set_blkh_nr_item( blkh, blkh_nr_item(blkh) + 1 );
+    set_blkh_free_space( blkh,
+                    free_space - (IH_SIZE + ih_item_len(inserted_item_ih ) ) );
     do_balance_mark_leaf_dirty (bi->tb, bh, 1);
 
     if (bi->bi_parent) { 
-	B_N_CHILD (bi->bi_parent, bi->bi_position)->dc_size += (IH_SIZE + inserted_item_ih->ih_item_len);
+	struct disk_child *t_dc;
+	t_dc = B_N_CHILD (bi->bi_parent, bi->bi_position);
+	put_dc_size( t_dc, dc_size(t_dc) + (IH_SIZE + ih_item_len(inserted_item_ih)));
 	do_balance_mark_internal_dirty (bi->tb, bi->bi_parent, 0);
     }
 }
@@ -806,24 +808,27 @@
 			   int zeros_number)
 {
     struct buffer_head * bh = bi->bi_bh;
-    int nr;
+    int nr, free_space;
     struct block_head * blkh;
     struct item_head * ih;
     int i;
     int last_loc, unmoved_loc;
 
+    blkh = B_BLK_HEAD(bh);
+    nr = blkh_nr_item(blkh);
+    free_space = blkh_free_space(blkh);
 
-    nr = le16_to_cpu ((blkh = B_BLK_HEAD(bh))->blk_nr_item);
 
     /* check free space */
-    RFALSE( le16_to_cpu (blkh->blk_free_space) < paste_size,
-	    "10175: not enough free space: needed %d, available %d",
-	    paste_size, le16_to_cpu (blkh->blk_free_space));
+    RFALSE( free_space < paste_size,
+            "vs-10175: not enough free space: needed %d, available %d",
+            paste_size, free_space);
+
 #ifdef CONFIG_REISERFS_CHECK
     if (zeros_number > paste_size) {
 	print_cur_tb ("10177");
-	reiserfs_panic (0, "vs-10177: leaf_paste_in_buffer: zero number == %d, paste_size == %d",
-			zeros_number, paste_size);
+	reiserfs_panic ( 0, "vs-10177: leaf_paste_in_buffer: ero number == %d, paste_size == %d",
+                         zeros_number, paste_size);
     }
 #endif /* CONFIG_REISERFS_CHECK */
 
@@ -831,8 +836,8 @@
     /* item to be appended */
     ih = B_N_PITEM_HEAD(bh, affected_item_num);
 
-    last_loc = ih[nr - affected_item_num - 1].ih_item_location;
-    unmoved_loc = affected_item_num ? (ih-1)->ih_item_location : bh->b_size;  
+    last_loc = ih_location( &(ih[nr - affected_item_num - 1]) );
+    unmoved_loc = affected_item_num ? ih_location( ih-1 ) : bh->b_size;
 
     /* prepare space */
     memmove (bh->b_data + last_loc - paste_size, bh->b_data + last_loc,
@@ -841,17 +846,18 @@
 
     /* change locations */
     for (i = affected_item_num; i < nr; i ++)
-	ih[i-affected_item_num].ih_item_location -= paste_size;
+	put_ih_location( &(ih[i-affected_item_num]),
+                    ih_location( &(ih[i-affected_item_num])) - paste_size );
 
     if ( body ) {
 	if (!is_direntry_le_ih (ih)) {
 	    if (!pos_in_item) {
 		/* shift data to right */
-		memmove (bh->b_data + ih->ih_item_location + paste_size, 
-			 bh->b_data + ih->ih_item_location, ih->ih_item_len);
+		memmove (bh->b_data + ih_location(ih) + paste_size, 
+			 bh->b_data + ih_location(ih), ih_item_len(ih));
 		/* paste data in the head of item */
-		memset (bh->b_data + ih->ih_item_location, 0, zeros_number);
-		memcpy (bh->b_data + ih->ih_item_location + zeros_number, body, paste_size - zeros_number);
+		memset (bh->b_data + ih_location(ih), 0, zeros_number);
+		memcpy (bh->b_data + ih_location(ih) + zeros_number, body, paste_size - zeros_number);
 	    } else {
 		memset (bh->b_data + unmoved_loc - paste_size, 0, zeros_number);
 		memcpy (bh->b_data + unmoved_loc - paste_size + zeros_number, body, paste_size - zeros_number);
@@ -859,17 +865,18 @@
 	}
     }
     else
-	memset(bh->b_data + unmoved_loc - paste_size,'\0',paste_size);
+	memset(bh->b_data + unmoved_loc - paste_size, '\0', paste_size);
 
-    ih->ih_item_len += paste_size;
+    put_ih_item_len( ih, ih_item_len(ih) + paste_size );
 
     /* change free space */
-    blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) - paste_size);
+    set_blkh_free_space( blkh, free_space - paste_size );
 
     do_balance_mark_leaf_dirty (bi->tb, bh, 0);
 
     if (bi->bi_parent) { 
-	B_N_CHILD (bi->bi_parent, bi->bi_position)->dc_size += paste_size;
+	struct disk_child *t_dc = B_N_CHILD (bi->bi_parent, bi->bi_position);
+	put_dc_size( t_dc, dc_size(t_dc) + paste_size );
 	do_balance_mark_internal_dirty (bi->tb, bi->bi_parent, 0);
     }
 }
@@ -905,26 +912,29 @@
     return 0;
 
   /* first byte of item */
-  item = bh->b_data + ih->ih_item_location;
+  item = bh->b_data + ih_location(ih);
 
   /* entry head array */
   deh = B_I_DEH (bh, ih);
 
   /* first byte of remaining entries, those are BEFORE cut entries
      (prev_record) and length of all removed records (cut_records_len) */
-  prev_record_offset = (from ? deh[from - 1].deh_location : ih->ih_item_len);
-  cut_records_len = prev_record_offset/*from_record*/ - deh[from + del_count - 1].deh_location;
+  prev_record_offset = (from ? deh_location( &(deh[from - 1])) : ih_item_len(ih));
+  cut_records_len = prev_record_offset/*from_record*/ -
+                                deh_location( &(deh[from + del_count - 1]));
   prev_record = item + prev_record_offset;
 
 
   /* adjust locations of remaining entries */
   for (i = I_ENTRY_COUNT(ih) - 1; i > from + del_count - 1; i --)
-    deh[i].deh_location -= (DEH_SIZE * del_count);
+    put_deh_location( &(deh[i]),
+                        deh_location( &deh[i] ) - (DEH_SIZE * del_count ) );
 
   for (i = 0; i < from; i ++)
-    deh[i].deh_location -= DEH_SIZE * del_count + cut_records_len;
+    put_deh_location( &(deh[i]),
+        deh_location( &deh[i] ) - (DEH_SIZE * del_count + cut_records_len) );
 
-  I_ENTRY_COUNT(ih) -= del_count;
+  put_ih_entry_count( ih, ih_entry_count(ih) - del_count );
 
   /* shift entry head array and entries those are AFTER removed entries */
   memmove ((char *)(deh + from),
@@ -933,7 +943,7 @@
   
   /* shift records, those are BEFORE removed entries */
   memmove (prev_record - cut_records_len - DEH_SIZE * del_count,
-	   prev_record, item + ih->ih_item_len - prev_record);
+	   prev_record, item + ih_item_len(ih) - prev_record);
 
   return DEH_SIZE * del_count + cut_records_len;
 }
@@ -957,7 +967,8 @@
     int last_loc, unmoved_loc;
     int i;
 
-    nr = le16_to_cpu ((blkh = B_BLK_HEAD (bh))->blk_nr_item);
+    blkh = B_BLK_HEAD(bh);
+    nr = blkh_nr_item(blkh);
 
     /* item head of truncated item */
     ih = B_N_PITEM_HEAD (bh, cut_item_num);
@@ -967,43 +978,42 @@
         cut_size = leaf_cut_entries (bh, ih, pos_in_item, cut_size);
         if (pos_in_item == 0) {
 	        /* change key */
-	    RFALSE( cut_item_num,
+            RFALSE( cut_item_num,
                     "when 0-th enrty of item is cut, that item must be first in the node, not %d-th", cut_item_num);
             /* change item key by key of first entry in the item */
-	    set_le_ih_k_offset (ih, le32_to_cpu (B_I_DEH (bh, ih)->deh_offset));
+	    set_le_ih_k_offset (ih, deh_offset(B_I_DEH (bh, ih)));
             /*memcpy (&ih->ih_key.k_offset, &(B_I_DEH (bh, ih)->deh_offset), SHORT_KEY_SIZE);*/
 	    }
     } else {
         /* item is direct or indirect */
-	RFALSE( is_statdata_le_ih (ih), "10195: item is stat data");
-	RFALSE( pos_in_item && 
-		pos_in_item + cut_size != le16_to_cpu (ih->ih_item_len),
-		"invalid offset (%lu) or trunc_size (%lu) or ih_item_len (%lu)",
-                pos_in_item, cut_size, le16_to_cpu (ih->ih_item_len));
+        RFALSE( is_statdata_le_ih (ih), "10195: item is stat data");
+        RFALSE( pos_in_item && pos_in_item + cut_size != ih_item_len(ih),
+                "10200: invalid offset (%lu) or trunc_size (%lu) or ih_item_len (%lu)",
+                pos_in_item, cut_size, ih_item_len (ih));
 
         /* shift item body to left if cut is from the head of item */
         if (pos_in_item == 0) {
-            memmove (bh->b_data + le16_to_cpu (ih->ih_item_location), bh->b_data + le16_to_cpu (ih->ih_item_location) + cut_size,
-		     le16_to_cpu (ih->ih_item_len) - cut_size);
+            memmove( bh->b_data + ih_location(ih),
+		     bh->b_data + ih_location(ih) + cut_size,
+		     ih_item_len(ih) - cut_size);
 	    
             /* change key of item */
             if (is_direct_le_ih (ih))
 		set_le_ih_k_offset (ih, le_ih_k_offset (ih) + cut_size);
             else {
 		set_le_ih_k_offset (ih, le_ih_k_offset (ih) + (cut_size / UNFM_P_SIZE) * bh->b_size);
-		RFALSE( le16_to_cpu (ih->ih_item_len) == cut_size && 
-			get_ih_free_space (ih),
-			"10205: invalid ih_free_space (%h)", ih);
+                RFALSE( ih_item_len(ih) == cut_size && get_ih_free_space (ih),
+                        "10205: invalid ih_free_space (%h)", ih);
 	        }
 	    }
     }
   
 
     /* location of the last item */
-    last_loc = le16_to_cpu (ih[nr - cut_item_num - 1].ih_item_location);
+    last_loc = ih_location( &(ih[nr - cut_item_num - 1]) );
 
     /* location of the item, which is remaining at the same place */
-    unmoved_loc = cut_item_num ? le16_to_cpu ((ih-1)->ih_item_location) : bh->b_size;
+    unmoved_loc = cut_item_num ? ih_location(ih-1) : bh->b_size;
 
 
     /* shift */
@@ -1011,8 +1021,7 @@
 	       unmoved_loc - last_loc - cut_size);
 
     /* change item length */
-/*    ih->ih_item_len -= cut_size;*/
-    ih->ih_item_len = cpu_to_le16 (le16_to_cpu (ih->ih_item_len) - cut_size);
+    put_ih_item_len( ih, ih_item_len(ih) - cut_size );
   
     if (is_indirect_le_ih (ih)) {
         if (pos_in_item)
@@ -1021,17 +1030,17 @@
 
     /* change locations */
     for (i = cut_item_num; i < nr; i ++)
-/*        ih[i-cut_item_num].ih_item_location += cut_size;*/
-        ih[i-cut_item_num].ih_item_location = 
-	  cpu_to_le16 (le16_to_cpu (ih[i-cut_item_num].ih_item_location) + cut_size);
+    put_ih_location( &(ih[i-cut_item_num]), ih_location( &ih[i-cut_item_num]) + cut_size );
 
     /* size, free space */
-    blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) + cut_size);
+    set_blkh_free_space( blkh, blkh_free_space(blkh) + cut_size );
 
     do_balance_mark_leaf_dirty (bi->tb, bh, 0);
     
     if (bi->bi_parent) { 
-      B_N_CHILD (bi->bi_parent, bi->bi_position)->dc_size -= cut_size; 
+      struct disk_child *t_dc;
+      t_dc = B_N_CHILD (bi->bi_parent, bi->bi_position);
+      put_dc_size( t_dc, dc_size(t_dc) - cut_size );
       do_balance_mark_internal_dirty (bi->tb, bi->bi_parent, 0);
     }
 }
@@ -1054,10 +1063,11 @@
   if (del_num == 0)
     return;
 
-  nr = le16_to_cpu ((blkh = B_BLK_HEAD(bh))->blk_nr_item);
+  blkh = B_BLK_HEAD(bh);
+  nr = blkh_nr_item(blkh);
 
   RFALSE( first < 0 || first + del_num > nr,
-	  "10220: first=%d, number=%d, there is %d items", first, del_num, nr);
+          "10220: first=%d, number=%d, there is %d items", first, del_num, nr);
 
   if (first == 0 && del_num == nr) {
     /* this does not work */
@@ -1070,11 +1080,11 @@
   ih = B_N_PITEM_HEAD (bh, first);
   
   /* location of unmovable item */
-  j = (first == 0) ? bh->b_size : (ih-1)->ih_item_location;
+  j = (first == 0) ? bh->b_size : ih_location(ih-1);
       
   /* delete items */
-  last_loc = ih[nr-1-first].ih_item_location;
-  last_removed_loc = ih[del_num-1].ih_item_location;
+  last_loc = ih_location( &(ih[nr-1-first]) );
+  last_removed_loc = ih_location( &(ih[del_num-1]) );
 
   memmove (bh->b_data + last_loc + j - last_removed_loc,
 	   bh->b_data + last_loc, last_removed_loc - last_loc);
@@ -1084,16 +1094,18 @@
   
   /* change item location */
   for (i = first; i < nr - del_num; i ++)
-    ih[i-first].ih_item_location += j - last_removed_loc;
+    put_ih_location( &(ih[i-first]), ih_location( &(ih[i-first]) ) + (j - last_removed_loc) );
 
   /* sizes, item number */
-  blkh->blk_nr_item = cpu_to_le16 (le16_to_cpu (blkh->blk_nr_item) - del_num);
-  blkh->blk_free_space = cpu_to_le16 (le16_to_cpu (blkh->blk_free_space) + (j - last_removed_loc + IH_SIZE * del_num));
+  set_blkh_nr_item( blkh, blkh_nr_item(blkh) - del_num );
+  set_blkh_free_space( blkh, blkh_free_space(blkh) + (j - last_removed_loc + IH_SIZE * del_num) );
 
   do_balance_mark_leaf_dirty (bi->tb, bh, 0);
   
   if (bi->bi_parent) {
-    B_N_CHILD (bi->bi_parent, bi->bi_position)->dc_size -= j - last_removed_loc + IH_SIZE * del_num;
+    struct disk_child *t_dc = B_N_CHILD (bi->bi_parent, bi->bi_position);
+    put_dc_size( t_dc, dc_size(t_dc) -
+				(j - last_removed_loc + IH_SIZE * del_num));
     do_balance_mark_internal_dirty (bi->tb, bi->bi_parent, 0);
   }
 }
@@ -1132,27 +1144,28 @@
 
 
   /* first byte of dest item */
-  item = bh->b_data + ih->ih_item_location;
+  item = bh->b_data + ih_location(ih);
 
   /* entry head array */
   deh = B_I_DEH (bh, ih);
 
   /* new records will be pasted at this point */
-  insert_point = item + (before ? deh[before - 1].deh_location : (ih->ih_item_len - paste_size));
+  insert_point = item + (before ? deh_location( &(deh[before - 1])) : (ih_item_len(ih) - paste_size));
 
   /* adjust locations of records that will be AFTER new records */
   for (i = I_ENTRY_COUNT(ih) - 1; i >= before; i --)
-    deh[i].deh_location += DEH_SIZE * new_entry_count;
+    put_deh_location( &(deh[i]),
+                deh_location(&(deh[i])) + (DEH_SIZE * new_entry_count )); 
 
   /* adjust locations of records that will be BEFORE new records */
   for (i = 0; i < before; i ++)
-    deh[i].deh_location += paste_size;
+    put_deh_location( &(deh[i]), deh_location(&(deh[i])) + paste_size );
 
   old_entry_num = I_ENTRY_COUNT(ih);
-  I_ENTRY_COUNT(ih) += new_entry_count;
+  put_ih_entry_count( ih, ih_entry_count(ih) + new_entry_count );
 
   /* prepare space for pasted records */
-  memmove (insert_point + paste_size, insert_point, item + (ih->ih_item_len - paste_size) - insert_point);
+  memmove (insert_point + paste_size, insert_point, item + (ih_item_len(ih) - paste_size) - insert_point);
 
   /* copy new records */
   memcpy (insert_point + DEH_SIZE * new_entry_count, records,
@@ -1168,14 +1181,18 @@
 
   /* set locations of new records */
   for (i = 0; i < new_entry_count; i ++)
-    deh[i].deh_location += 
-      (- new_dehs[new_entry_count - 1].deh_location + insert_point + DEH_SIZE * new_entry_count - item);
+  {
+    put_deh_location( &(deh[i]),
+        deh_location( &(deh[i] )) +
+        (- deh_location( &(new_dehs[new_entry_count - 1])) +
+        insert_point + DEH_SIZE * new_entry_count - item));
+  }
 
 
   /* change item key if neccessary (when we paste before 0-th entry */
   if (!before)
     {
-	set_le_ih_k_offset (ih, le32_to_cpu (new_dehs->deh_offset));
+	set_le_ih_k_offset (ih, deh_offset(new_dehs));
 /*      memcpy (&ih->ih_key.k_offset, 
 		       &new_dehs->deh_offset, SHORT_KEY_SIZE);*/
     }
@@ -1186,13 +1203,13 @@
     /* check record locations */
     deh = B_I_DEH (bh, ih);
     for (i = 0; i < I_ENTRY_COUNT(ih); i ++) {
-      next = (i < I_ENTRY_COUNT(ih) - 1) ? deh[i + 1].deh_location : 0;
-      prev = (i != 0) ? deh[i - 1].deh_location : 0;
+      next = (i < I_ENTRY_COUNT(ih) - 1) ? deh_location( &(deh[i + 1])) : 0;
+      prev = (i != 0) ? deh_location( &(deh[i - 1]) ) : 0;
       
-      if (prev && prev <= deh[i].deh_location)
+      if (prev && prev <= deh_location( &(deh[i])))
 	reiserfs_warning ("vs-10240: leaf_paste_entries: directory item (%h) corrupted (prev %a, cur(%d) %a)\n", 
 			  ih, deh + i - 1, i, deh + i);
-      if (next && next >= deh[i].deh_location)
+      if (next && next >= deh_location( &(deh[i])))
 	reiserfs_warning ("vs-10250: leaf_paste_entries: directory item (%h) corrupted (cur(%d) %a, next %a)\n",
 			  ih, i, deh + i, deh + i + 1);
     }
@@ -1200,6 +1217,3 @@
 #endif
 
 }
-
-
-
diff -urN linux-2.4.13-pre1/fs/reiserfs/namei.c linux/fs/reiserfs/namei.c
--- linux-2.4.13-pre1/fs/reiserfs/namei.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/namei.c	Mon Dec  3 23:17:33 2001
@@ -81,7 +81,7 @@
 
     de->de_entrylen = entry_length (de->de_bh, de->de_ih, de->de_entry_num);
     de->de_namelen = de->de_entrylen - (de_with_sd (deh) ? SD_SIZE : 0);
-    de->de_name = B_I_PITEM (de->de_bh, de->de_ih) + le16_to_cpu (deh->deh_location);
+    de->de_name = B_I_PITEM (de->de_bh, de->de_ih) + deh_location(deh);
     if (de->de_name[de->de_namelen - 1] == 0)
 	de->de_namelen = strlen (de->de_name);
 }
@@ -92,8 +92,8 @@
 {
     if (de->de_entry_num >= ih_entry_count (de->de_ih))
 	BUG ();
-    de->de_dir_id = le32_to_cpu (de->de_deh[de->de_entry_num].deh_dir_id);
-    de->de_objectid = le32_to_cpu (de->de_deh[de->de_entry_num].deh_objectid);
+    de->de_dir_id = deh_dir_id( &(de->de_deh[de->de_entry_num]));
+    de->de_objectid = deh_objectid( &(de->de_deh[de->de_entry_num]));
 }
 
 
@@ -159,7 +159,7 @@
 	COMP_SHORT_KEYS (&(de->de_ih->ih_key), key)) {
 	print_block (de->de_bh, 0, -1, -1);
 	reiserfs_panic (sb, "vs-7005: search_by_entry_key: found item %h is not directory item or "
-			"does not belong to the same directory as key %k", de->de_ih, key);
+                        "does not belong to the same directory as key %K", de->de_ih, key);
     }
 #endif /* CONFIG_REISERFS_CHECK */
 
@@ -322,12 +322,7 @@
 	retval = search_by_entry_key (dir->i_sb, &key_to_search, path_to_entry, de);
 	if (retval == IO_ERROR)
 	    // FIXME: still has to be dealt with
-
-				/* I want you to conform to our error
-                                   printing standard.  How many times
-                                   do I have to ask? -Hans */
-
-	    BUG ();
+	    reiserfs_panic (dir->i_sb, "zam-7001: io error in " __FUNCTION__ "\n");
 
 	/* compare names for all entries having given hash value */
 	retval = linear_search_in_dir_item (&key_to_search, de, name, namelen);
@@ -434,12 +429,12 @@
 
     /* fill buffer : directory entry head, name[, dir objectid | , stat data | ,stat data, dir objectid ] */
     deh = (struct reiserfs_de_head *)buffer;
-    deh->deh_location = 0;
-    deh->deh_offset = cpu_to_le32 (cpu_key_k_offset (&entry_key));
-    deh->deh_state = 0;
+    deh->deh_location = 0; /* JDM Endian safe if 0 */
+    put_deh_offset( deh, cpu_key_k_offset( &entry_key ) );
+    deh->deh_state = 0; /* JDM Endian safe if 0 */
     /* put key (ino analog) to de */
-    deh->deh_dir_id = INODE_PKEY (inode)->k_dir_id;
-    deh->deh_objectid = INODE_PKEY (inode)->k_objectid;
+    deh->deh_dir_id = INODE_PKEY (inode)->k_dir_id; /* safe: k_dir_id is le */
+    deh->deh_objectid = INODE_PKEY (inode)->k_objectid; /* safe: k_objectid is le */
 
     /* copy name */
     memcpy ((char *)(deh + 1), name, namelen);
@@ -454,36 +449,37 @@
     memset (bit_string, 0, sizeof (bit_string));
     de.de_gen_number_bit_string = (char *)bit_string;
     retval = reiserfs_find_entry (dir, name, namelen, &path, &de);
-    if (retval != NAME_NOT_FOUND) {
+    if( retval != NAME_NOT_FOUND ) {
 	if (buffer != small_buf)
 	    reiserfs_kfree (buffer, buflen, dir->i_sb);
 	pathrelse (&path);
-	
-	if (retval != NAME_FOUND) {
+
+        if (retval != NAME_FOUND) {
 	    reiserfs_warning ("zam-7002:" __FUNCTION__ ": \"reiserfs_find_entry\" has returned"
-			      " unexpected value (%d)\n", retval);
-	}
-	
+                              " unexpected value (%d)\n", retval);
+       }
+
 	return -EEXIST;
     }
 
     gen_number = find_first_zero_bit (bit_string, MAX_GENERATION_NUMBER + 1);
     if (gen_number > MAX_GENERATION_NUMBER) {
-	/* there is no free generation number */
-	reiserfs_warning ("reiserfs_add_entry: Congratulations! we have got hash function screwed up\n");
-	if (buffer != small_buf)
-	    reiserfs_kfree (buffer, buflen, dir->i_sb);
-	pathrelse (&path);
-	return -EBUSY;
+      /* there is no free generation number */
+      reiserfs_warning ("reiserfs_add_entry: Congratulations! we have got hash function screwed up\n");
+      if (buffer != small_buf)
+          reiserfs_kfree (buffer, buflen, dir->i_sb);
+      pathrelse (&path);
+      return -EBUSY;
     }
     /* adjust offset of directory enrty */
-    deh->deh_offset = cpu_to_le32 (SET_GENERATION_NUMBER (deh_offset (deh), gen_number));
-    set_cpu_key_k_offset (&entry_key, le32_to_cpu (deh->deh_offset));
-
+    put_deh_offset(deh, SET_GENERATION_NUMBER(deh_offset(deh), gen_number));
+    set_cpu_key_k_offset (&entry_key, deh_offset(deh));
+ 
     if (gen_number != 0) {	/* we need to re-search for the insertion point */
-	if (search_by_entry_key (dir->i_sb, &entry_key, &path, &de) != NAME_NOT_FOUND) {
-	    reiserfs_warning ("vs-7032: reiserfs_add_entry: "
-			      "entry with this key (%k) already exists\n", &entry_key);
+      if (search_by_entry_key (dir->i_sb, &entry_key, &path, &de) != NAME_NOT_FOUND) {
+            reiserfs_warning ("vs-7032: reiserfs_add_entry: "
+                            "entry with this key (%k) already exists\n", &entry_key);
+
 	    if (buffer != small_buf)
 		reiserfs_kfree (buffer, buflen, dir->i_sb);
 	    pathrelse (&path);
@@ -558,6 +554,8 @@
 	iput (inode);
 	return retval;
     }
+    reiserfs_update_inode_transaction(inode) ;
+    reiserfs_update_inode_transaction(dir) ;
 
     d_instantiate(dentry, inode);
     pop_journal_writer(windex) ;
@@ -600,6 +598,9 @@
     //FIXME: needed for block and char devices only
     reiserfs_update_sd (&th, inode);
 
+    reiserfs_update_inode_transaction(inode) ;
+    reiserfs_update_inode_transaction(dir) ;
+
     retval = reiserfs_add_entry (&th, dir, dentry->d_name.name, dentry->d_name.len, 
 				 inode, 1/*visible*/);
     if (retval) {
@@ -655,6 +656,8 @@
 	journal_end(&th, dir->i_sb, jbegin_count) ;
 	return retval;
     }
+    reiserfs_update_inode_transaction(inode) ;
+    reiserfs_update_inode_transaction(dir) ;
 
     inode->i_op = &reiserfs_dir_inode_operations;
     inode->i_fop = &reiserfs_dir_operations;
@@ -723,6 +726,9 @@
     }
     inode = dentry->d_inode;
 
+    reiserfs_update_inode_transaction(inode) ;
+    reiserfs_update_inode_transaction(dir) ;
+
     if (de.de_objectid != inode->i_ino) {
 	// FIXME: compare key of an object and a key found in the
 	// entry
@@ -796,6 +802,9 @@
     }
     inode = dentry->d_inode;
 
+    reiserfs_update_inode_transaction(inode) ;
+    reiserfs_update_inode_transaction(dir) ;
+
     if (de.de_objectid != inode->i_ino) {
 	// FIXME: compare key of an object and a key found in the
 	// entry
@@ -885,6 +894,9 @@
 	return retval;
     }
 
+    reiserfs_update_inode_transaction(inode) ;
+    reiserfs_update_inode_transaction(dir) ;
+
     inode->i_op = &page_symlink_inode_operations;
     inode->i_mapping->a_ops = &reiserfs_address_space_operations;
 
@@ -940,6 +952,10 @@
     /* create new entry */
     retval = reiserfs_add_entry (&th, dir, dentry->d_name.name, dentry->d_name.len,
 				 inode, 1/*visible*/);
+
+    reiserfs_update_inode_transaction(inode) ;
+    reiserfs_update_inode_transaction(dir) ;
+
     if (retval) {
 	pop_journal_writer(windex) ;
 	journal_end(&th, dir->i_sb, jbegin_count) ;
@@ -994,6 +1010,7 @@
 /* sets key of objectid the entry has to point to */
 static void set_ino_in_dir_entry (struct reiserfs_dir_entry * de, struct key * key)
 {
+    /* JDM These operations are endian safe - both are le */
     de->de_deh[de->de_entry_num].deh_dir_id = key->k_dir_id;
     de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid;
 }
@@ -1085,6 +1102,16 @@
 	return retval;
     }
 
+    reiserfs_update_inode_transaction(old_dir) ;
+    reiserfs_update_inode_transaction(new_dir) ;
+
+    /* this makes it so an fsync on an open fd for the old name will
+    ** commit the rename operation
+    */
+    reiserfs_update_inode_transaction(old_inode) ;
+
+    if (new_inode) 
+	reiserfs_update_inode_transaction(new_inode) ;
 
     while (1) {
 	// look for old name using corresponding entry key (found by reiserfs_find_entry)
diff -urN linux-2.4.13-pre1/fs/reiserfs/objectid.c linux/fs/reiserfs/objectid.c
--- linux-2.4.13-pre1/fs/reiserfs/objectid.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/objectid.c	Mon Dec  3 23:17:33 2001
@@ -80,10 +80,9 @@
        first two odd sequences into one sequence.  If so, then the net
        result is to eliminate a pair of objectids from oids.  We do this
        by shifting the entire map to the left. */
-    if (le16_to_cpu (rs->s_oid_cursize) > 2 && map[1] == map[2]) {
-	memmove (map + 1, map + 3, (le16_to_cpu (rs->s_oid_cursize) - 3) * sizeof(__u32));
-	//rs->s_oid_cursize -= 2;
-	rs->s_oid_cursize = cpu_to_le16 (le16_to_cpu (rs->s_oid_cursize) - 2);
+    if (sb_oid_cursize(rs) > 2 && map[1] == map[2]) {
+	memmove (map + 1, map + 3, (sb_oid_cursize(rs) - 3) * sizeof(__u32));
+        set_sb_oid_cursize( rs, sb_oid_cursize(rs) - 2 );
     }
 
     journal_mark_dirty(th, s, SB_BUFFER_WITH_SB (s));
@@ -114,7 +113,7 @@
        what we use, though it is possible that binary search would be
        more efficient after performing lots of deletions (which is
        when oids is large.)  We only check even i's. */
-    while (i < le16_to_cpu (rs->s_oid_cursize)) {
+    while (i < sb_oid_cursize(rs)) {
 	if (objectid_to_release == le32_to_cpu (map[i])) {
 	    /* This incrementation unallocates the objectid. */
 	    //map[i]++;
@@ -124,14 +123,14 @@
 	    if (map[i] == map[i+1]) {
 		/* shrink objectid map */
 		memmove (map + i, map + i + 2, 
-			 (le16_to_cpu (rs->s_oid_cursize) - i - 2) * sizeof (__u32));
+			 (sb_oid_cursize(rs) - i - 2) * sizeof (__u32));
 		//disk_sb->s_oid_cursize -= 2;
-		rs->s_oid_cursize = cpu_to_le16 (le16_to_cpu (rs->s_oid_cursize) - 2);
+                set_sb_oid_cursize( rs, sb_oid_cursize(rs) - 2 );
 
-		RFALSE( le16_to_cpu (rs->s_oid_cursize) < 2 || 
-			le16_to_cpu (rs->s_oid_cursize) > le16_to_cpu (rs->s_oid_maxsize),
-			"vs-15005: objectid map corrupted cur_size == %d (max == %d)",
-			le16_to_cpu (rs->s_oid_cursize), le16_to_cpu (rs->s_oid_maxsize));
+		RFALSE( sb_oid_cursize(rs) < 2 || 
+		        sb_oid_cursize(rs) > sb_oid_maxsize(rs),
+		        "vs-15005: objectid map corrupted cur_size == %d (max == %d)",
+                        sb_oid_cursize(rs), sb_oid_maxsize(rs));
 	    }
 	    return;
 	}
@@ -145,16 +144,17 @@
 		return;
 	    }
 
+            /* JDM comparing two little-endian values for equality -- safe */
 	    if (rs->s_oid_cursize == rs->s_oid_maxsize)
 		/* objectid map must be expanded, but there is no space */
 		return;
 
 	    /* expand the objectid map*/
 	    memmove (map + i + 3, map + i + 1, 
-		     (le16_to_cpu (rs->s_oid_cursize) - i - 1) * sizeof(__u32));
+		     (sb_oid_cursize(rs) - i - 1) * sizeof(__u32));
 	    map[i + 1] = cpu_to_le32 (objectid_to_release);
 	    map[i + 2] = cpu_to_le32 (objectid_to_release + 1);
-	    rs->s_oid_cursize = cpu_to_le16 (le16_to_cpu (rs->s_oid_cursize) + 2);
+            set_sb_oid_cursize( rs, sb_oid_cursize(rs) + 2 );
 	    return;
 	}
 	i += 2;
diff -urN linux-2.4.13-pre1/fs/reiserfs/prints.c linux/fs/reiserfs/prints.c
--- linux-2.4.13-pre1/fs/reiserfs/prints.c	Sat Sep  8 12:05:32 2001
+++ linux/fs/reiserfs/prints.c	Mon Dec  3 23:17:33 2001
@@ -15,7 +15,7 @@
 static char off_buf[80];
 
 
-static char * cpu_offset (struct cpu_key * key)
+static char * reiserfs_cpu_offset (struct cpu_key * key)
 {
   if (cpu_key_k_type(key) == TYPE_DIRENTRY)
     sprintf (off_buf, "%Lu(%Lu)", 
@@ -90,11 +90,21 @@
 {
   if (key)
     sprintf (buf, "[%d %d %s %s]", key->on_disk_key.k_dir_id,
-	     key->on_disk_key.k_objectid, cpu_offset (key), cpu_type (key));
+	     key->on_disk_key.k_objectid, reiserfs_cpu_offset (key),
+             cpu_type (key));
   else
     sprintf (buf, "[NULL]");
 }
 
+static void sprintf_de_head( char *buf, struct reiserfs_de_head *deh )
+{
+    if( deh )
+        sprintf( buf, "[offset=%d dir_id=%d objectid=%d location=%d state=%04x]", deh_offset(deh), deh_dir_id(deh),
+                 deh_objectid(deh), deh_location(deh), deh_state(deh) );
+    else
+        sprintf( buf, "[NULL]" );
+
+}
 
 static void sprintf_item_head (char * buf, struct item_head * ih)
 {
@@ -103,7 +113,7 @@
 	sprintf_le_key (buf + strlen (buf), &(ih->ih_key));
 	sprintf (buf + strlen (buf), ", item_len %d, item_location %d, "
 		 "free_space(entry_count) %d",
-		 ih->ih_item_len, ih->ih_item_location, ih_free_space (ih));
+		 ih_item_len(ih), ih_location(ih), ih_free_space (ih));
     } else
 	sprintf (buf, "[NULL]");
 }
@@ -123,10 +133,6 @@
 {
   sprintf (buf, "level=%d, nr_items=%d, free_space=%d rdkey ",
 	   B_LEVEL (bh), B_NR_ITEMS (bh), B_FREE_SPACE (bh));
-#if 0
-  if (B_LEVEL (bh) == DISK_LEAF_NODE_LEVEL)
-    sprintf_le_key (buf + strlen (buf), B_PRIGHT_DELIM_KEY (bh));
-#endif
 }
 
 
@@ -143,7 +149,7 @@
 
 static void sprintf_disk_child (char * buf, struct disk_child * dc)
 {
-  sprintf (buf, "[dc_number=%d, dc_size=%u]", dc->dc_block_number, dc->dc_size);
+  sprintf (buf, "[dc_number=%d, dc_size=%u]", dc_block_number(dc), dc_size(dc));
 }
 
 
@@ -153,12 +159,10 @@
 
   *skip = 0;
   
-  while (1) {
-    k = strstr (k, "%");
-    if (!k)
-      break;
-    if (k && (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
-	      k[1] == 'z' || k[1] == 'b' || k[1] == 'y')) {
+  while ((k = strstr (k, "%")) != NULL)
+  {
+    if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
+	      k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a' ) {
       *what = k[1];
       break;
     }
@@ -182,59 +186,58 @@
            key->k_offset, key->k_uniqueness); 
 */
 
-#define do_reiserfs_warning \
-{\
-  char * fmt1 = fmt_buf;\
-  va_list args;\
-  int i, j;\
-  char * k;\
-  char * p = error_buf;\
-  int what, skip;\
-\
-  strcpy (fmt1, fmt);\
-  va_start(args, fmt);\
-\
-  while (1) {\
-    k = is_there_reiserfs_struct (fmt1, &what, &skip);\
-    if (k != 0) {\
-      *k = 0;\
-      p += vsprintf (p, fmt1, args);\
-\
-      for (i = 0; i < skip; i ++)\
-	j = va_arg (args, int);\
-\
-      switch (what) {\
-      case 'k':\
-	sprintf_le_key (p, va_arg(args, struct key *));\
-	break;\
-      case 'K':\
-	sprintf_cpu_key (p, va_arg(args, struct cpu_key *));\
-	break;\
-      case 'h':\
-	sprintf_item_head (p, va_arg(args, struct item_head *));\
-	break;\
-      case 't':\
-	sprintf_direntry (p, va_arg(args, struct reiserfs_dir_entry *));\
-	break;\
-      case 'y':\
-	sprintf_disk_child (p, va_arg(args, struct disk_child *));\
-	break;\
-      case 'z':\
-	sprintf_block_head (p, va_arg(args, struct buffer_head *));\
-	break;\
-      case 'b':\
-	sprintf_buffer_head (p, va_arg(args, struct buffer_head *));\
-	break;\
-      }\
-      p += strlen (p);\
-      fmt1 = k + 2;\
-    } else {\
-      i = vsprintf (p, fmt1, args);\
-      break;\
-    }\
-  }\
-\
-  va_end(args);\
+
+static void
+prepare_error_buf( const char *fmt, va_list args )
+{
+    char * fmt1 = fmt_buf;
+    char * k;
+    char * p = error_buf;
+    int i, j, what, skip;
+
+    strcpy (fmt1, fmt);
+
+    while( (k = is_there_reiserfs_struct( fmt1, &what, &skip )) != NULL )
+    {
+        *k = 0;
+
+        p += vsprintf (p, fmt1, args);
+
+        for (i = 0; i < skip; i ++)
+            j = va_arg (args, int);
+
+        switch (what) {
+        case 'k':
+            sprintf_le_key (p, va_arg(args, struct key *));
+            break;
+        case 'K':
+            sprintf_cpu_key (p, va_arg(args, struct cpu_key *));
+            break;
+        case 'h':
+            sprintf_item_head (p, va_arg(args, struct item_head *));
+            break;
+        case 't':
+            sprintf_direntry (p, va_arg(args, struct reiserfs_dir_entry *));
+            break;
+        case 'y':
+            sprintf_disk_child (p, va_arg(args, struct disk_child *));
+            break;
+        case 'z':
+            sprintf_block_head (p, va_arg(args, struct buffer_head *));
+            break;
+        case 'b':
+            sprintf_buffer_head (p, va_arg(args, struct buffer_head *));
+            break;
+        case 'a':
+            sprintf_de_head (p, va_arg(args, struct reiserfs_de_head *));
+            break;
+        }
+
+        p += strlen (p);
+        fmt1 = k + 2;
+    }
+    vsprintf (p, fmt1, args);
+
 }
 
 
@@ -247,9 +250,18 @@
    %z to print block head (arg must be struct buffer_head *
    %b to print buffer_head
 */
+
+#define do_reiserfs_warning(fmt)\
+{\
+    va_list args;\
+    va_start( args, fmt );\
+    prepare_error_buf( fmt, args );\
+    va_end( args );\
+}
+
 void reiserfs_warning (const char * fmt, ...)
 {
-  do_reiserfs_warning;
+  do_reiserfs_warning(fmt);
   /* console_print (error_buf); */
   printk (KERN_WARNING "%s", error_buf);
 }
@@ -257,7 +269,7 @@
 void reiserfs_debug (struct super_block *s, int level, const char * fmt, ...)
 {
 #ifdef CONFIG_REISERFS_CHECK
-  do_reiserfs_warning;
+  do_reiserfs_warning(fmt);
   printk (KERN_DEBUG "%s", error_buf);
 #else
   ; 
@@ -291,7 +303,7 @@
 
     panics in reiserfs_fs.h have numbers from 1000 to 1999
     super.c				        2000 to 2999
-    preserve.c				    3000 to 3999
+    preserve.c (unused)			    3000 to 3999
     bitmap.c				    4000 to 4999
     stree.c				        5000 to 5999
     prints.c				    6000 to 6999
@@ -317,8 +329,8 @@
 void reiserfs_panic (struct super_block * sb, const char * fmt, ...)
 {
   show_reiserfs_locks() ;
-  do_reiserfs_warning;
-  printk ("%s", error_buf);
+  do_reiserfs_warning(fmt);
+  printk ( KERN_EMERG "%s", error_buf);
   BUG ();
   // console_print (error_buf);
   // for (;;);
@@ -437,7 +449,7 @@
 {
     struct block_head * blkh;
     struct item_head * ih;
-    int i;
+    int i, nr;
     int from, to;
 
     if (!B_IS_ITEMS_LEVEL (bh))
@@ -447,23 +459,24 @@
 
     blkh = B_BLK_HEAD (bh);
     ih = B_N_PITEM_HEAD (bh,0);
+    nr = blkh_nr_item(blkh);
 
     printk ("\n===================================================================\n");
     reiserfs_warning ("LEAF NODE (%ld) contains %z\n", bh->b_blocknr, bh);
 
     if (!(print_mode & PRINT_LEAF_ITEMS)) {
 	reiserfs_warning ("FIRST ITEM_KEY: %k, LAST ITEM KEY: %k\n",
-			  &(ih->ih_key), &((ih + le16_to_cpu (blkh->blk_nr_item) - 1)->ih_key));
+			  &(ih->ih_key), &((ih + nr - 1)->ih_key));
 	return 0;
     }
 
-    if (first < 0 || first > le16_to_cpu (blkh->blk_nr_item) - 1) 
+    if (first < 0 || first > nr - 1) 
 	from = 0;
     else 
 	from = first;
 
-    if (last < 0 || last > le16_to_cpu (blkh->blk_nr_item))
-	to = le16_to_cpu (blkh->blk_nr_item);
+    if (last < 0 || last > nr )
+	to = nr;
     else
 	to = last;
 
@@ -500,34 +513,45 @@
 {
     struct reiserfs_super_block * rs = (struct reiserfs_super_block *)(bh->b_data);
     int skipped, data_blocks;
+    char *version;
     
 
-    if (strncmp (rs->s_magic,  REISERFS_SUPER_MAGIC_STRING, strlen ( REISERFS_SUPER_MAGIC_STRING)) &&
-	strncmp (rs->s_magic,  REISER2FS_SUPER_MAGIC_STRING, strlen ( REISER2FS_SUPER_MAGIC_STRING)))
+    if (strncmp (rs->s_magic,  REISERFS_SUPER_MAGIC_STRING,
+                 strlen ( REISERFS_SUPER_MAGIC_STRING)) == 0) {
+        version = "3.5";
+    } else if( strncmp (rs->s_magic,  REISER2FS_SUPER_MAGIC_STRING,
+                        strlen ( REISER2FS_SUPER_MAGIC_STRING)) == 0) {
+        version = "3.6";
+    } else {
 	return 1;
+    }
 
-    printk ("%s\'s super block in block %ld\n======================\n", kdevname (bh->b_dev), bh->b_blocknr);
-    printk ("Reiserfs version %s\n", reiserfs_version (bh->b_data));
-    printk ("Block count %u\n", le32_to_cpu (rs->s_block_count));
-    printk ("Blocksize %d\n", le16_to_cpu (rs->s_blocksize));
-    printk ("Free blocks %u\n", le32_to_cpu (rs->s_free_blocks));
-    skipped = bh->b_blocknr; // FIXME: this would be confusing if
+    printk ("%s\'s super block in block %ld\n======================\n",
+            kdevname (bh->b_dev), bh->b_blocknr);
+    printk ("Reiserfs version %s\n", version );
+    printk ("Block count %u\n", sb_block_count(rs));
+    printk ("Blocksize %d\n", sb_blocksize(rs));
+    printk ("Free blocks %u\n", sb_free_blocks(rs));
+    // FIXME: this would be confusing if
     // someone stores reiserfs super block in some data block ;)
-    data_blocks = le32_to_cpu (rs->s_block_count) - skipped - 1 -
-      le16_to_cpu (rs->s_bmap_nr) - (le32_to_cpu (rs->s_orig_journal_size) + 1) -
-      le32_to_cpu (rs->s_free_blocks);
+//    skipped = (bh->b_blocknr * bh->b_size) / sb_blocksize(rs);
+    skipped = bh->b_blocknr;
+    data_blocks = sb_block_count(rs) - skipped - 1 -
+                  sb_bmap_nr(rs) - (sb_orig_journal_size(rs) + 1) -
+                  sb_free_blocks(rs);
     printk ("Busy blocks (skipped %d, bitmaps - %d, journal blocks - %d\n"
 	    "1 super blocks, %d data blocks\n", 
-	    skipped, le16_to_cpu (rs->s_bmap_nr), 
-	    (le32_to_cpu (rs->s_orig_journal_size) + 1), data_blocks);
-    printk ("Root block %u\n", le32_to_cpu (rs->s_root_block));
-    printk ("Journal block (first) %d\n", le32_to_cpu (rs->s_journal_block));
-    printk ("Journal dev %d\n", le32_to_cpu (rs->s_journal_dev));    
-    printk ("Journal orig size %d\n", le32_to_cpu (rs->s_orig_journal_size));
+	    skipped, sb_bmap_nr(rs), 
+	    (sb_orig_journal_size(rs) + 1), data_blocks);
+    printk ("Root block %u\n", sb_root_block(rs));
+    printk ("Journal block (first) %d\n", sb_journal_block(rs));
+    printk ("Journal dev %d\n", sb_journal_dev(rs));
+    printk ("Journal orig size %d\n", sb_orig_journal_size(rs));
     printk ("Filesystem state %s\n", 
-	    (le16_to_cpu (rs->s_state) == REISERFS_VALID_FS) ? "VALID" : "ERROR");
-    printk ("Hash function \"%s\"\n", le16_to_cpu (rs->s_hash_function_code) == TEA_HASH ? "tea" :
-	    ((le16_to_cpu (rs->s_hash_function_code) == YURA_HASH) ? "rupasov" : "unknown"));
+	    (sb_state(rs) == REISERFS_VALID_FS) ? "VALID" : "ERROR");
+    printk ("Hash function \"%s\"\n",
+            sb_hash_function_code(rs) == TEA_HASH ? "tea" :
+	    ((sb_hash_function_code(rs) == YURA_HASH) ? "rupasov" : "unknown"));
 
 #if 0
     __u32 s_journal_trans_max ;           /* max number of blocks in a transaction.  */
@@ -536,7 +560,7 @@
     __u32 s_journal_max_commit_age ;      /* in seconds, how old can an async commit be */
     __u32 s_journal_max_trans_age ;       /* in seconds, how old can a transaction be */
 #endif
-    printk ("Tree height %d\n", rs->s_tree_height);
+    printk ("Tree height %d\n", sb_tree_height(rs));
     return 0;
 }
 
@@ -665,12 +689,14 @@
 static void check_leaf_block_head (struct buffer_head * bh)
 {
   struct block_head * blkh;
+  int nr;
 
   blkh = B_BLK_HEAD (bh);
-  if (le16_to_cpu (blkh->blk_nr_item) > (bh->b_size - BLKH_SIZE) / IH_SIZE)
+  nr = blkh_nr_item(blkh);
+  if ( nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)
     reiserfs_panic (0, "vs-6010: check_leaf_block_head: invalid item number %z", bh);
-  if (le16_to_cpu (blkh->blk_free_space) > 
-      bh->b_size - BLKH_SIZE - IH_SIZE * le16_to_cpu (blkh->blk_nr_item))
+  if ( blkh_free_space(blkh) > 
+      bh->b_size - BLKH_SIZE - IH_SIZE * nr )
     reiserfs_panic (0, "vs-6020: check_leaf_block_head: invalid free space %z", bh);
     
 }
@@ -718,9 +744,9 @@
 {
 
   /*
-  printk ("reiserfs_put_super: session statistics: balances %d, fix_nodes %d, preserve list freeings %d, \
+  printk ("reiserfs_put_super: session statistics: balances %d, fix_nodes %d, \
 bmap with search %d, without %d, dir2ind %d, ind2dir %d\n",
-	  s->u.reiserfs_sb.s_do_balance, s->u.reiserfs_sb.s_fix_nodes, s->u.reiserfs_sb.s_preserve_list_freeings,
+	  s->u.reiserfs_sb.s_do_balance, s->u.reiserfs_sb.s_fix_nodes,
 	  s->u.reiserfs_sb.s_bmaps, s->u.reiserfs_sb.s_bmaps_without_search,
 	  s->u.reiserfs_sb.s_direct2indirect, s->u.reiserfs_sb.s_indirect2direct);
   */
diff -urN linux-2.4.13-pre1/fs/reiserfs/stree.c linux/fs/reiserfs/stree.c
--- linux-2.4.13-pre1/fs/reiserfs/stree.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/stree.c	Mon Dec  3 23:17:33 2001
@@ -226,8 +226,8 @@
 	to->on_disk_key.u.k_offset_v1.k_offset = le32_to_cpu (from->u.k_offset_v1.k_offset);
 	to->on_disk_key.u.k_offset_v1.k_uniqueness = le32_to_cpu (from->u.k_offset_v1.k_uniqueness);
     } else {
-	to->on_disk_key.u.k_offset_v2.k_offset = le64_to_cpu (from->u.k_offset_v2.k_offset);
-	to->on_disk_key.u.k_offset_v2.k_type = le16_to_cpu (from->u.k_offset_v2.k_type);
+	to->on_disk_key.u.k_offset_v2.k_offset = offset_v2_k_offset(&from->u.k_offset_v2);
+	to->on_disk_key.u.k_offset_v2.k_type = offset_v2_k_type(&from->u.k_offset_v2);
     } 
 }
 
@@ -268,19 +268,19 @@
 				       the item size.                      */
 	      int     * p_n_pos     /* Number of the searched for element. */
             ) {
-  int   n_rbound, n_lbound, n_j;
+    int   n_rbound, n_lbound, n_j;
 
-  for ( n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0))/2; n_lbound <= n_rbound; n_j = (n_rbound + n_lbound)/2 )
-    switch( COMP_KEYS((struct key *)((char * )p_v_base + n_j * p_n_width), (struct cpu_key *)p_v_key) )  {
-    case -1: n_lbound = n_j + 1; continue;
-    case  1: n_rbound = n_j - 1; continue;
-    case  0: *p_n_pos = n_j;     return ITEM_FOUND; /* Key found in the array.  */
-    }
-
-  /* bin_search did not find given key, it returns position of key,
-     that is minimal and greater than the given one. */
-  *p_n_pos = n_lbound;
-  return ITEM_NOT_FOUND;
+   for ( n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0))/2; n_lbound <= n_rbound; n_j = (n_rbound + n_lbound)/2 )
+     switch( COMP_KEYS((struct key *)((char * )p_v_base + n_j * p_n_width), (struct cpu_key *)p_v_key) )  {
+     case -1: n_lbound = n_j + 1; continue;
+     case  1: n_rbound = n_j - 1; continue;
+     case  0: *p_n_pos = n_j;     return ITEM_FOUND; /* Key found in the array.  */
+        }
+
+    /* bin_search did not find given key, it returns position of key,
+        that is minimal and greater than the given one. */
+    *p_n_pos = n_lbound;
+    return ITEM_NOT_FOUND;
 }
 
 #ifdef CONFIG_REISERFS_CHECK
@@ -495,12 +495,12 @@
     int nr;
 
     blkh = (struct block_head *)buf;
-    if (le16_to_cpu (blkh->blk_level) != DISK_LEAF_NODE_LEVEL) {
+    if ( blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) {
 	printk ("is_leaf: this should be caught earlier\n");
 	return 0;
     }
 
-    nr = le16_to_cpu (blkh->blk_nr_item);
+    nr = blkh_nr_item(blkh);
     if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) {
 	/* item number is too big or too small */
 	reiserfs_warning ("is_leaf: nr_item seems wrong: %z\n", bh);
@@ -508,7 +508,7 @@
     }
     ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1;
     used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location (ih));
-    if (used_space != blocksize - le16_to_cpu (blkh->blk_free_space)) {
+    if (used_space != blocksize - blkh_free_space(blkh)) {
 	/* free space does not match to calculated amount of use space */
 	reiserfs_warning ("is_leaf: free space seems wrong: %z\n", bh);
 	return 0;
@@ -549,14 +549,14 @@
     int used_space;
 
     blkh = (struct block_head *)buf;
-    if (le16_to_cpu (blkh->blk_level) <= DISK_LEAF_NODE_LEVEL ||
-	le16_to_cpu (blkh->blk_level) > MAX_HEIGHT) {
+    nr = blkh_level(blkh);
+    if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) {
 	/* this level is not possible for internal nodes */
 	printk ("is_internal: this should be caught earlier\n");
 	return 0;
     }
     
-    nr = le16_to_cpu (blkh->blk_nr_item);
+    nr = blkh_nr_item(blkh);
     if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) {
 	/* for internal which is not root we might check min number of keys */
 	reiserfs_warning ("is_internal: number of key seems wrong: %z\n", bh);
@@ -564,7 +564,7 @@
     }
 
     used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1);
-    if (used_space != blocksize - le16_to_cpu (blkh->blk_free_space)) {
+    if (used_space != blocksize - blkh_free_space(blkh)) {
 	reiserfs_warning ("is_internal: free space seems wrong: %z\n", bh);
 	return 0;
     }
@@ -741,8 +741,10 @@
 		"vs-5152: tree level is less than stop level (%d)",
 		n_node_level, n_stop_level);
 
-	n_retval = bin_search (p_s_key, B_N_PITEM_HEAD(p_s_bh, 0), B_NR_ITEMS(p_s_bh),
-			       ( n_node_level == DISK_LEAF_NODE_LEVEL ) ? IH_SIZE : KEY_SIZE, &(p_s_last_element->pe_position));
+	n_retval = bin_search( p_s_key, B_N_PITEM_HEAD(p_s_bh, 0),
+                B_NR_ITEMS(p_s_bh),
+                ( n_node_level == DISK_LEAF_NODE_LEVEL ) ? IH_SIZE : KEY_SIZE,
+                &(p_s_last_element->pe_position));
 	if (n_node_level == n_stop_level) {
 	    return n_retval;
 	}
@@ -808,16 +810,16 @@
 	return retval;
     if ( retval == ITEM_FOUND )  {
 
-	RFALSE( ! B_N_PITEM_HEAD
-		(PATH_PLAST_BUFFER(p_s_search_path),
-		 PATH_LAST_POSITION(p_s_search_path))->ih_item_len,
-		"PAP-5165: item length equals zero");
+	RFALSE( ! ih_item_len(
+                B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path),
+			       PATH_LAST_POSITION(p_s_search_path))),
+	        "PAP-5165: item length equals zero");
 
 	pos_in_item(p_s_search_path) = 0;
 	return POSITION_FOUND;
     }
 
-    RFALSE( ! PATH_LAST_POSITION(p_s_search_path), 
+    RFALSE( ! PATH_LAST_POSITION(p_s_search_path),
 	    "PAP-5170: position equals zero");
 
     /* Item is not found. Set path to the previous item. */
@@ -846,9 +848,9 @@
     /* Needed byte is not contained in the item pointed to by the
      path. Set pos_in_item out of the item. */
     if ( is_indirect_le_ih (p_le_ih) )
-	pos_in_item (p_s_search_path) = le16_to_cpu (p_le_ih->ih_item_len) / UNFM_P_SIZE;
+	pos_in_item (p_s_search_path) = ih_item_len(p_le_ih) / UNFM_P_SIZE;
     else
-	pos_in_item (p_s_search_path) = le16_to_cpu (p_le_ih->ih_item_len);
+        pos_in_item (p_s_search_path) = ih_item_len( p_le_ih );
   
     return POSITION_NOT_FOUND;
 }
@@ -880,9 +882,9 @@
 	return 1;
 
     /* Compare other items fields. */
-    if ( le16_to_cpu (p_s_path_item->u.ih_entry_count) != p_cpu_ih->u.ih_entry_count ||
-	 le16_to_cpu (p_s_path_item->ih_item_len) != p_cpu_ih->ih_item_len ||
-	 le16_to_cpu ( p_s_path_item->ih_item_location) != p_cpu_ih->ih_item_location )
+    if( ih_entry_count(p_s_path_item) != ih_entry_count(p_cpu_ih) ||
+	ih_item_len(p_s_path_item) != ih_item_len(p_cpu_ih) ||
+	ih_location(p_s_path_item) != ih_location(p_cpu_ih) )
 	return 1;
 
     /* Items are equal. */
@@ -913,7 +915,7 @@
 
     if ( new_file_length == max_reiserfs_offset (inode) ) {
 	/* item has to be deleted */
-	*cut_size = -(IH_SIZE + le16_to_cpu (le_ih->ih_item_len));
+	*cut_size = -(IH_SIZE + ih_item_len(le_ih));
 	return M_DELETE;
     }
 	
@@ -923,12 +925,12 @@
 	round_len = ROUND_UP (new_file_length); 
 	/* this was n_new_file_length < le_ih ... */
 	if ( round_len < le_ih_k_offset (le_ih) )  {
-	    *cut_size = -(IH_SIZE + le16_to_cpu (le_ih->ih_item_len));
+	    *cut_size = -(IH_SIZE + ih_item_len(le_ih));
 	    return M_DELETE; /* Delete this item. */
 	}
 	/* Calculate first position and size for cutting from item. */
 	pos_in_item (path) = round_len - (le_ih_k_offset (le_ih) - 1);
-	*cut_size = -(le16_to_cpu (le_ih->ih_item_len) - pos_in_item(path));
+	*cut_size = -(ih_item_len(le_ih) - pos_in_item(path));
 	
 	return M_CUT; /* Cut from this item. */
     }
@@ -937,11 +939,11 @@
     // old file: items may have any length
 
     if ( new_file_length < le_ih_k_offset (le_ih) )  {
-	*cut_size = -(IH_SIZE + le16_to_cpu (le_ih->ih_item_len));
+	*cut_size = -(IH_SIZE + ih_item_len(le_ih));
 	return M_DELETE; /* Delete this item. */
     }
     /* Calculate first position and size for cutting from item. */
-    *cut_size = -(le16_to_cpu (le_ih->ih_item_len) -
+    *cut_size = -(ih_item_len(le_ih) -
 		      (pos_in_item (path) = new_file_length + 1 - le_ih_k_offset (le_ih)));
     return M_CUT; /* Cut from this item. */
 }
@@ -956,15 +958,15 @@
     if (le_ih_k_offset (le_ih) == DOT_OFFSET && 
 	new_file_length == max_reiserfs_offset (inode)) {
 	RFALSE( ih_entry_count (le_ih) != 2,
-		"PAP-5220: incorrect empty directory item (%h)", le_ih);
-	*cut_size = -(IH_SIZE + le16_to_cpu (le_ih->ih_item_len));
+	        "PAP-5220: incorrect empty directory item (%h)", le_ih);
+	*cut_size = -(IH_SIZE + ih_item_len(le_ih));
 	return M_DELETE; /* Delete the directory item containing "." and ".." entry. */
     }
     
     if ( ih_entry_count (le_ih) == 1 )  {
 	/* Delete the directory item such as there is one record only
 	   in this item*/
-	*cut_size = -(IH_SIZE + le16_to_cpu (le_ih->ih_item_len));
+	*cut_size = -(IH_SIZE + ih_item_len(le_ih));
 	return M_DELETE;
     }
     
@@ -1003,7 +1005,7 @@
 	RFALSE( n_new_file_length != max_reiserfs_offset (inode),
 		"PAP-5210: mode must be M_DELETE");
 
-	*p_n_cut_size = -(IH_SIZE + le16_to_cpu (p_le_ih->ih_item_len));
+	*p_n_cut_size = -(IH_SIZE + ih_item_len(p_le_ih));
 	return M_DELETE;
     }
 
@@ -1051,13 +1053,13 @@
 	    /* Calculate balance mode and position in the item to remove unformatted nodes. */
 	    if ( n_new_file_length == max_reiserfs_offset (inode) ) {/* Case of delete. */
 		pos_in_item (p_s_path) = 0;
-		*p_n_cut_size = -(IH_SIZE + le16_to_cpu (s_ih.ih_item_len));
+		*p_n_cut_size = -(IH_SIZE + ih_item_len(&s_ih));
 		c_mode = M_DELETE;
 	    }
 	    else  { /* Case of truncate. */
 		if ( n_new_file_length < le_ih_k_offset (&s_ih) )  {
 		    pos_in_item (p_s_path) = 0;
-		    *p_n_cut_size = -(IH_SIZE + le16_to_cpu (s_ih.ih_item_len));
+		    *p_n_cut_size = -(IH_SIZE + ih_item_len(&s_ih));
 		    c_mode = M_DELETE; /* Delete this item. */
 		}
 		else  {
@@ -1074,7 +1076,7 @@
 			return M_CONVERT; /* Maybe convert last unformatted node to the direct item. */
 		    }
 		    /* Calculate size to cut. */
-		    *p_n_cut_size = -(s_ih.ih_item_len - pos_in_item (p_s_path) * UNFM_P_SIZE);
+		    *p_n_cut_size = -(ih_item_len(&s_ih) - pos_in_item(p_s_path) * UNFM_P_SIZE);
 
 		    c_mode = M_CUT;     /* Cut from this indirect item. */
 		}
@@ -1111,29 +1113,29 @@
 			p_n_unfm_pointer > (__u32 *)B_I_PITEM(p_s_bh, &s_ih) + I_UNFM_NUM(&s_ih) - 1,
 			"vs-5265: pointer out of range");
 
-		if ( ! *p_n_unfm_pointer )  { /* Hole, nothing to remove. */
+		if ( ! get_block_num(p_n_unfm_pointer,0) )  { /* Hole, nothing to remove. */
 		    if ( ! n_retry )
 			(*p_n_removed)++;
 		    continue;
 		}
 		/* Search for the buffer in cache. */
-		p_s_un_bh = get_hash_table(p_s_sb->s_dev, *p_n_unfm_pointer, n_blk_size);
+		p_s_un_bh = get_hash_table(p_s_sb->s_dev, get_block_num(p_n_unfm_pointer,0), n_blk_size);
 
 		if (p_s_un_bh) {
 		    mark_buffer_clean(p_s_un_bh) ;
 		    if (buffer_locked(p_s_un_bh)) {
-		        __wait_on_buffer(p_s_un_bh) ;
+		  __wait_on_buffer(p_s_un_bh) ;
 		    }
 		    /* even if the item moves, the block number of the
 		    ** unformatted node we want to cut won't.  So, it was
 		    ** safe to clean the buffer here, this block _will_
 		    ** get freed during this call to prepare_for_delete_or_cut
 		    */
-		    if ( item_moved (&s_ih, p_s_path) )  {
-		        need_research = 1;
-		        brelse(p_s_un_bh) ;
-		        break ;
-		    }
+		  if ( item_moved (&s_ih, p_s_path) )  {
+		      need_research = 1;
+		      brelse(p_s_un_bh) ;
+		      break ;
+		  }
 		}
 		if ( p_s_un_bh && block_in_use (p_s_un_bh)) {
 		    /* Block is locked or held more than by one holder and by
@@ -1157,15 +1159,15 @@
 		if ( ! n_retry )
 		    (*p_n_removed)++;
       
-		RFALSE( p_s_un_bh && 
-			(*p_n_unfm_pointer != p_s_un_bh->b_blocknr ),
+		RFALSE( p_s_un_bh &&
+                     get_block_num(p_n_unfm_pointer, 0) != p_s_un_bh->b_blocknr,
 		    // note: minix_truncate allows that. As truncate is
 		    // protected by down (inode->i_sem), two truncates can not
 		    // co-exist
-			"PAP-5280: blocks numbers are different");	
+		    "PAP-5280: blocks numbers are different");	
 
-		tmp = *p_n_unfm_pointer;
-		*p_n_unfm_pointer = 0;
+		tmp = get_block_num(p_n_unfm_pointer,0);
+		put_block_num(p_n_unfm_pointer, 0, 0);
 		journal_mark_dirty (th, p_s_sb, p_s_bh);
 		bforget (p_s_un_bh);
 		inode->i_blocks -= p_s_sb->s_blocksize / 512;
@@ -1173,7 +1175,7 @@
 		if ( item_moved (&s_ih, p_s_path) )  {
 		    need_research = 1;
 		    break ;
-		}
+		    }
 	    }
 
 	    /* a trick.  If the buffer has been logged, this
@@ -1237,9 +1239,9 @@
 	// we can't use EMPTY_DIR_SIZE, as old format dirs have a different
 	// empty size.  ick. FIXME, is this right?
 	//
-        return le16_to_cpu(p_le_ih->ih_item_len) ;
+	return ih_item_len(p_le_ih);
     }
-    n_del_size = ( c_mode == M_DELETE ) ? le16_to_cpu (p_le_ih->ih_item_len) : -p_s_tb->insert_size[0];
+    n_del_size = ( c_mode == M_DELETE ) ? ih_item_len(p_le_ih) : -p_s_tb->insert_size[0];
 
     if ( is_indirect_le_ih (p_le_ih) )
 	n_del_size = (n_del_size/UNFM_P_SIZE)*
@@ -1416,7 +1418,7 @@
 	}
 	if (!tb_init) {
 	    tb_init = 1 ;
-	    item_len = le16_to_cpu (PATH_PITEM_HEAD (&path)->ih_item_len);
+	    item_len = ih_item_len( PATH_PITEM_HEAD(&path) );
 	    init_tb_struct (th, &tb, th->t_super, &path, - (IH_SIZE + item_len));
 	}
 
@@ -1523,14 +1525,14 @@
 	/* look for the last byte of the tail */
 	if (search_for_position_by_key (inode->i_sb, &tail_key, path) == POSITION_NOT_FOUND)
 	    reiserfs_panic (inode->i_sb, "vs-5615: indirect_to_direct_roll_back: found invalid item");
-	RFALSE( path->pos_in_item != PATH_PITEM_HEAD (path)->ih_item_len - 1,
-		"vs-5616: appended bytes found");
+	RFALSE( path->pos_in_item != ih_item_len(PATH_PITEM_HEAD (path)) - 1,
+	        "vs-5616: appended bytes found");
 	PATH_LAST_POSITION (path) --;
 	
 	removed = reiserfs_delete_item (th, path, &tail_key, inode, 0/*unbh not needed*/);
 	RFALSE( removed <= 0 || removed > tail_len,
-		"vs-5617: there was tail %d bytes, removed item length %d bytes",
-		tail_len, removed);
+	        "vs-5617: there was tail %d bytes, removed item length %d bytes",
+                tail_len, removed);
 	tail_len -= removed;
 	set_cpu_key_k_offset (&tail_key, cpu_key_k_offset (&tail_key) - removed);
     }
@@ -1672,7 +1674,7 @@
 	    reiserfs_panic (p_s_sb, "vs-5652: reiserfs_cut_from_item: "
 			    "item must be indirect %h", le_ih);
 
-	if (c_mode == M_DELETE && le16_to_cpu (le_ih->ih_item_len) != UNFM_P_SIZE)
+	if (c_mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE)
 	    reiserfs_panic (p_s_sb, "vs-5653: reiserfs_cut_from_item: "
 			    "completing indirect2direct conversion indirect item %h"
 			    "being deleted must be of 4 byte long", le_ih);
@@ -1825,6 +1827,7 @@
 
 	  journal_end(th, p_s_inode->i_sb, orig_len_alloc) ;
 	  journal_begin(th, p_s_inode->i_sb, orig_len_alloc) ;
+	  reiserfs_update_inode_transaction(p_s_inode) ;
 	}
     } while ( n_file_size > ROUND_UP (n_new_file_size) &&
 	      search_for_position_by_key(p_s_inode->i_sb, &s_item_key, &s_search_path) == POSITION_FOUND )  ;
@@ -1923,11 +1926,11 @@
     struct tree_balance s_ins_balance;
     int                 retval;
 
-    init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path, IH_SIZE + p_s_ih->ih_item_len);
+    init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path, IH_SIZE + ih_item_len(p_s_ih));
 
     /*
     if (p_c_body == 0)
-      n_zeros_num = p_s_ih->ih_item_len;
+      n_zeros_num = ih_item_len(p_s_ih);
     */
     //    le_key2cpu_key (&key, &(p_s_ih->ih_key));
 
diff -urN linux-2.4.13-pre1/fs/reiserfs/super.c linux/fs/reiserfs/super.c
--- linux-2.4.13-pre1/fs/reiserfs/super.c	Sat Sep  8 12:05:32 2001
+++ linux/fs/reiserfs/super.c	Mon Dec  3 23:17:33 2001
@@ -79,9 +79,6 @@
 // at the ext2 code and comparing. It's subfunctions contain no code
 // used as a template unless they are so labeled.
 //
-/* there should be no suspected recipients already. True and cautious
-   bitmaps should not differ. We only have to free preserve list and
-   write both bitmaps */
 void reiserfs_put_super (struct super_block * s)
 {
   int i;
@@ -91,7 +88,7 @@
   if (!(s->s_flags & MS_RDONLY)) {
     journal_begin(&th, s, 10) ;
     reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
-    s->u.reiserfs_sb.s_rs->s_state = le16_to_cpu (s->u.reiserfs_sb.s_mount_state);
+    set_sb_state( SB_DISK_SUPER_BLOCK(s), s->u.reiserfs_sb.s_mount_state );
     journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
   }
 
@@ -250,26 +247,26 @@
   
   if (*flags & MS_RDONLY) {
     /* try to remount file system with read-only permissions */
-    if (le16_to_cpu (rs->s_state) == REISERFS_VALID_FS || s->u.reiserfs_sb.s_mount_state != REISERFS_VALID_FS) {
+    if (sb_state(rs) == REISERFS_VALID_FS || s->u.reiserfs_sb.s_mount_state != REISERFS_VALID_FS) {
       return 0;
     }
 
     journal_begin(&th, s, 10) ;
     /* Mounting a rw partition read-only. */
     reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
-    rs->s_state = cpu_to_le16 (s->u.reiserfs_sb.s_mount_state);
+    set_sb_state( rs, s->u.reiserfs_sb.s_mount_state );
     journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
     s->s_dirt = 0;
   } else {
-    s->u.reiserfs_sb.s_mount_state = le16_to_cpu(rs->s_state) ;
+    s->u.reiserfs_sb.s_mount_state = sb_state(rs) ;
     s->s_flags &= ~MS_RDONLY ; /* now it is safe to call journal_begin */
     journal_begin(&th, s, 10) ;
 
     /* Mount a partition which is read-only, read-write */
     reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
-    s->u.reiserfs_sb.s_mount_state = le16_to_cpu (rs->s_state);
+    s->u.reiserfs_sb.s_mount_state = sb_state(rs);
     s->s_flags &= ~MS_RDONLY;
-    rs->s_state = cpu_to_le16 (REISERFS_ERROR_FS);
+    set_sb_state( rs, REISERFS_ERROR_FS );
     /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
     journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
     s->s_dirt = 0;
@@ -287,10 +284,10 @@
     int i, bmp, dl ;
     struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK(s);
 
-    SB_AP_BITMAP (s) = reiserfs_kmalloc (sizeof (struct buffer_head *) * le16_to_cpu (rs->s_bmap_nr), GFP_NOFS, s);
+    SB_AP_BITMAP (s) = reiserfs_kmalloc (sizeof (struct buffer_head *) * sb_bmap_nr(rs), GFP_NOFS, s);
     if (SB_AP_BITMAP (s) == 0)
 	return 1;
-    memset (SB_AP_BITMAP (s), 0, sizeof (struct buffer_head *) * le16_to_cpu (rs->s_bmap_nr));
+    memset (SB_AP_BITMAP (s), 0, sizeof (struct buffer_head *) * sb_bmap_nr(rs));
 
     /* reiserfs leaves the first 64k unused so that any partition
        labeling scheme currently used will have enough space. Then we
@@ -299,7 +296,7 @@
     SB_AP_BITMAP (s)[0] = reiserfs_bread (s->s_dev, bmp, s->s_blocksize);
     if(!SB_AP_BITMAP(s)[0])
 	return 1;
-    for (i = 1, bmp = dl = rs->s_blocksize * 8; i < le16_to_cpu (rs->s_bmap_nr); i ++) {
+    for (i = 1, bmp = dl = s->s_blocksize * 8; i < sb_bmap_nr(rs); i ++) {
 	SB_AP_BITMAP (s)[i] = reiserfs_bread (s->s_dev, bmp, s->s_blocksize);
 	if (!SB_AP_BITMAP (s)[i])
 	    return 1;
@@ -316,13 +313,13 @@
   int bmp1 = (REISERFS_OLD_DISK_OFFSET_IN_BYTES / s->s_blocksize) + 1;  /* first of bitmap blocks */
 
   /* read true bitmap */
-  SB_AP_BITMAP (s) = reiserfs_kmalloc (sizeof (struct buffer_head *) * le16_to_cpu (rs->s_bmap_nr), GFP_NOFS, s);
+  SB_AP_BITMAP (s) = reiserfs_kmalloc (sizeof (struct buffer_head *) * sb_bmap_nr(rs), GFP_NOFS, s);
   if (SB_AP_BITMAP (s) == 0)
     return 1;
 
-  memset (SB_AP_BITMAP (s), 0, sizeof (struct buffer_head *) * le16_to_cpu (rs->s_bmap_nr));
+  memset (SB_AP_BITMAP (s), 0, sizeof (struct buffer_head *) * sb_bmap_nr(rs));
 
-  for (i = 0; i < le16_to_cpu (rs->s_bmap_nr); i ++) {
+  for (i = 0; i < sb_bmap_nr(rs); i ++) {
     SB_AP_BITMAP (s)[i] = reiserfs_bread (s->s_dev, bmp1 + i, s->s_blocksize);
     if (!SB_AP_BITMAP (s)[i])
       return 1;
@@ -349,35 +346,33 @@
 		      free, SB_FREE_BLOCKS (s));
 }
 
-
-
 static int read_super_block (struct super_block * s, int size, int offset)
 {
     struct buffer_head * bh;
     struct reiserfs_super_block * rs;
-
+ 
 
     bh = bread (s->s_dev, offset / size, size);
     if (!bh) {
-	printk ("read_super_block: "
-		"bread failed (dev %s, block %d, size %d)\n", 
-		kdevname (s->s_dev), offset / size, size);
-	return 1;
+      printk ("read_super_block: "
+              "bread failed (dev %s, block %d, size %d)\n",
+              kdevname (s->s_dev), offset / size, size);
+      return 1;
     }
-
+ 
     rs = (struct reiserfs_super_block *)bh->b_data;
     if (!is_reiserfs_magic_string (rs)) {
-	printk ("read_super_block: "
-		"can't find a reiserfs filesystem on (dev %s, block %lu, size %d)\n",
-		kdevname(s->s_dev), bh->b_blocknr, size);
-	brelse (bh);
-	return 1;
+      printk ("read_super_block: "
+              "can't find a reiserfs filesystem on (dev %s, block %lu, size %d)\n",
+              kdevname(s->s_dev), bh->b_blocknr, size);
+      brelse (bh);
+      return 1;
     }
-
+ 
     //
     // ok, reiserfs signature (old or new) found in at the given offset
-    //
-    s->s_blocksize = le16_to_cpu (rs->s_blocksize);
+    //    
+    s->s_blocksize = sb_blocksize(rs);
     s->s_blocksize_bits = 0;
     while ((1 << s->s_blocksize_bits) != s->s_blocksize)
 	s->s_blocksize_bits ++;
@@ -387,21 +382,22 @@
     if (s->s_blocksize != size)
 	set_blocksize (s->s_dev, s->s_blocksize);
 
-    bh = bread (s->s_dev, offset / s->s_blocksize, s->s_blocksize);
+    bh = reiserfs_bread (s->s_dev, offset / s->s_blocksize, s->s_blocksize);
     if (!bh) {
-	printk ("read_super_block: "
-		"bread failed (dev %s, block %d, size %d)\n", 
-		kdevname (s->s_dev), offset / size, size);
+	printk("read_super_block: "
+                "bread failed (dev %s, block %d, size %d)\n",
+                kdevname (s->s_dev), offset / size, size);
 	return 1;
     }
     
     rs = (struct reiserfs_super_block *)bh->b_data;
     if (!is_reiserfs_magic_string (rs) ||
-	le16_to_cpu (rs->s_blocksize) != s->s_blocksize) {
+	sb_blocksize(rs) != s->s_blocksize) {
 	printk ("read_super_block: "
 		"can't find a reiserfs filesystem on (dev %s, block %lu, size %d)\n",
 		kdevname(s->s_dev), bh->b_blocknr, size);
 	brelse (bh);
+	printk ("read_super_block: can't find a reiserfs filesystem on dev %s.\n", kdevname(s->s_dev));
 	return 1;
     }
     /* must check to be sure we haven't pulled an old format super out
@@ -409,8 +405,8 @@
     ** will work.  If block we've just read in is inside the
     ** journal for that super, it can't be valid.  
     */
-    if (bh->b_blocknr >= le32_to_cpu(rs->s_journal_block) && 
-	bh->b_blocknr < (le32_to_cpu(rs->s_journal_block) + JOURNAL_BLOCK_COUNT)) {
+    if (bh->b_blocknr >= sb_journal_block(rs) && 
+	bh->b_blocknr < (sb_journal_block(rs) + JOURNAL_BLOCK_COUNT)) {
 	brelse(bh) ;
 	printk("super-459: read_super_block: "
 	       "super found at block %lu is within its own log. "
@@ -483,7 +479,7 @@
 	if (retval == NAME_NOT_FOUND)
 	    de.de_entry_num --;
 	set_de_name_and_namelen (&de);
-	if (le32_to_cpu (de.de_deh[de.de_entry_num].deh_offset) == DOT_DOT_OFFSET) {
+	if (deh_offset( &(de.de_deh[de.de_entry_num]) ) == DOT_DOT_OFFSET) {
 	    /* allow override in this case */
 	    if (reiserfs_rupasov_hash(s)) {
 		hash = YURA_HASH ;
@@ -499,7 +495,7 @@
 	    hash = UNSET_HASH ;
 	    break;
 	}
-	if (GET_HASH_VALUE(le32_to_cpu(de.de_deh[de.de_entry_num].deh_offset))==
+	if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) ==
 	    GET_HASH_VALUE (yura_hash (de.de_name, de.de_namelen)))
 	    hash = YURA_HASH;
 	else
@@ -516,7 +512,7 @@
 {
     __u32 code;
 
-    code = le32_to_cpu (s->u.reiserfs_sb.s_rs->s_hash_function_code);
+    code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
 
     /* reiserfs_hash_detect() == true if any of the hash mount options
     ** were used.  We must check them to make sure the user isn't
@@ -558,8 +554,8 @@
     */
     if (code != UNSET_HASH && 
 	!(s->s_flags & MS_RDONLY) && 
-        code != le32_to_cpu (s->u.reiserfs_sb.s_rs->s_hash_function_code)) {
-        s->u.reiserfs_sb.s_rs->s_hash_function_code = cpu_to_le32(code) ;
+        code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
+        set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
     }
     return code;
 }
@@ -646,7 +642,7 @@
 	    old_format = 1;
     }
 
-    s->u.reiserfs_sb.s_mount_state = le16_to_cpu (SB_DISK_SUPER_BLOCK (s)->s_state); /* journal victim */
+    s->u.reiserfs_sb.s_mount_state = SB_REISERFS_STATE(s);
     s->u.reiserfs_sb.s_mount_state = REISERFS_VALID_FS ;
 
     if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) { 
@@ -702,10 +698,10 @@
 
     if (!(s->s_flags & MS_RDONLY)) {
 	struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s);
-	int old_magic;
+        int old_magic;
 
-	old_magic = strncmp (rs->s_magic,  REISER2FS_SUPER_MAGIC_STRING, 
-			     strlen ( REISER2FS_SUPER_MAGIC_STRING));
+      old_magic = strncmp (rs->s_magic,  REISER2FS_SUPER_MAGIC_STRING,
+                           strlen ( REISER2FS_SUPER_MAGIC_STRING));
 	if( old_magic && le16_to_cpu(rs->s_version) != 0 ) {
 	  dput(s->s_root) ;
 	  s->s_root = NULL ;
@@ -716,7 +712,7 @@
 	journal_begin(&th, s, 1) ;
 	reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
 
-	rs->s_state = cpu_to_le16 (REISERFS_ERROR_FS);
+        set_sb_state( rs, REISERFS_ERROR_FS );
 
         if ( old_magic ) {
 	    // filesystem created under 3.5.x found
@@ -736,7 +732,7 @@
 	}
 
 	// mark hash in super block: it could be unset. overwrite should be ok
-	rs->s_hash_function_code = cpu_to_le32 (function2code (s->u.reiserfs_sb.s_hash_function));
+        set_sb_hash_function_code( rs, function2code(s->u.reiserfs_sb.s_hash_function ) );
 
 	journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
 	journal_end(&th, s, 1) ;
@@ -785,13 +781,13 @@
   struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s);
   
 				/* changed to accomodate gcc folks.*/
-  buf->f_type =  REISERFS_SUPER_MAGIC;
-  buf->f_bsize = le32_to_cpu (s->s_blocksize);
-  buf->f_blocks = le32_to_cpu (rs->s_block_count) - le16_to_cpu (rs->s_bmap_nr) - 1;
-  buf->f_bfree = le32_to_cpu (rs->s_free_blocks);
-  buf->f_bavail = buf->f_bfree;
-  buf->f_files = -1;
-  buf->f_ffree = -1;
+  buf->f_type    =  REISERFS_SUPER_MAGIC;
+  buf->f_bsize   = s->s_blocksize;
+  buf->f_blocks  = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
+  buf->f_bfree   = sb_free_blocks(rs);
+  buf->f_bavail  = buf->f_bfree;
+  buf->f_files   = -1;
+  buf->f_ffree   = -1;
   buf->f_namelen = (REISERFS_MAX_NAME_LEN (s->s_blocksize));
   return 0;
 }
@@ -806,6 +802,9 @@
         return register_filesystem(&reiserfs_fs_type);
 }
 
+MODULE_DESCRIPTION("ReiserFS journaled filesystem");
+MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
+MODULE_LICENSE("GPL");
 EXPORT_NO_SYMBOLS;
 
 //
diff -urN linux-2.4.13-pre1/fs/reiserfs/tail_conversion.c linux/fs/reiserfs/tail_conversion.c
--- linux-2.4.13-pre1/fs/reiserfs/tail_conversion.c	Mon Oct  8 11:52:58 2001
+++ linux/fs/reiserfs/tail_conversion.c	Mon Dec  3 23:17:33 2001
@@ -61,7 +61,7 @@
     if ( is_statdata_le_ih (p_le_ih) )  {
 	/* Insert new indirect item. */
 	set_ih_free_space (&ind_ih, 0); /* delete at nearest future */
-	ind_ih.ih_item_len = cpu_to_le16 (UNFM_P_SIZE);
+        put_ih_item_len( &ind_ih, UNFM_P_SIZE );
 	PATH_LAST_POSITION (path)++;
 	n_retval = reiserfs_insert_item (th, path, &end_key, &ind_ih, 
 					 (char *)&unfm_ptr);
@@ -93,10 +93,10 @@
 			    "direct item (%k) not found", &end_key);
 	p_le_ih = PATH_PITEM_HEAD (path);
 	RFALSE( !is_direct_le_ih (p_le_ih),
-		"vs-14055: direct item expected(%k), found %h", 
-		&end_key, p_le_ih);
-	tail_size = (le_ih_k_offset (p_le_ih) & (n_blk_size - 1))
-	    + ih_item_len(p_le_ih) - 1;
+	        "vs-14055: direct item expected(%k), found %h",
+                &end_key, p_le_ih);
+        tail_size = (le_ih_k_offset (p_le_ih) & (n_blk_size - 1))
+            + ih_item_len(p_le_ih) - 1;
 
 	/* we only send the unbh pointer if the buffer is not up to date.
 	** this avoids overwriting good data from writepage() with old data
@@ -214,7 +214,7 @@
     else
 	round_tail_len = tail_len;
 
-    pos = le_ih_k_offset (&s_ih) - 1 + (le16_to_cpu (s_ih.ih_item_len) / UNFM_P_SIZE - 1) * p_s_sb->s_blocksize;
+    pos = le_ih_k_offset (&s_ih) - 1 + (ih_item_len(&s_ih) / UNFM_P_SIZE - 1) * p_s_sb->s_blocksize;
     pos1 = pos;
 
     // we are protected by i_sem. The tail can not disapper, not
@@ -231,7 +231,7 @@
 	copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
 #ifdef CONFIG_REISERFS_CHECK
 	pos = le_ih_k_offset (&s_ih) - 1 + 
-	    (le16_to_cpu (s_ih.ih_item_len) / UNFM_P_SIZE - 1) * p_s_sb->s_blocksize;
+	    (ih_item_len(&s_ih) / UNFM_P_SIZE - 1) * p_s_sb->s_blocksize;
 	if (pos != pos1)
 	    reiserfs_panic (p_s_sb, "vs-5530: indirect2direct: "
 			    "tail position changed while we were reading it");
diff -urN linux-2.4.13-pre1/fs/udf/inode.c linux/fs/udf/inode.c
--- linux-2.4.13-pre1/fs/udf/inode.c	Mon Dec  3 23:17:24 2001
+++ linux/fs/udf/inode.c	Mon Dec  3 23:17:33 2001
@@ -37,10 +37,15 @@
 #include <linux/locks.h>
 #include <linux/mm.h>
 #include <linux/smp_lock.h>
+#include <linux/module.h>
 
 #include "udf_i.h"
 #include "udf_sb.h"
 
+MODULE_AUTHOR("Ben Fennema");
+MODULE_DESCRIPTION("Universal Disk Format Filesystem");
+MODULE_LICENSE("GPL");
+
 #define EXTENT_MERGE_SIZE 5
 
 static mode_t udf_convert_permissions(struct FileEntry *);
@@ -621,8 +626,17 @@
 
 		if (offset)
 		{
-			laarr[curr].extLength = type |
-				(offset << inode->i_sb->s_blocksize_bits);
+			if ((type >> 30) == EXTENT_NOT_RECORDED_ALLOCATED)
+			{
+				udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset);
+				laarr[curr].extLength = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30) |
+					(offset << inode->i_sb->s_blocksize_bits);
+				laarr[curr].extLocation.logicalBlockNum = 0;
+				laarr[curr].extLocation.partitionReferenceNum = 0;
+			}
+			else
+				laarr[curr].extLength = type |
+					(offset << inode->i_sb->s_blocksize_bits);
 			curr ++;
 			(*c) ++;
 			(*endnum) ++;
diff -urN linux-2.4.13-pre1/fs/vfat/namei.c linux/fs/vfat/namei.c
--- linux-2.4.13-pre1/fs/vfat/namei.c	Fri Apr  6 10:51:19 2001
+++ linux/fs/vfat/namei.c	Mon Dec  3 23:17:33 2001
@@ -9,13 +9,12 @@
  *    what file operation caused you trouble and if you can duplicate
  *    the problem, send a script that demonstrates it.
  *
- *  Short name translation 1999 by Wolfram Pienkoss <wp@bszh.de>
+ *  Short name translation 1999, 2001 by Wolfram Pienkoss <wp@bszh.de>
  *
  *  Support Multibyte character and cleanup by
  *  				OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
  */
 
-#define __NO_VERSION__
 #include <linux/module.h>
 
 #include <linux/sched.h>
@@ -29,8 +28,6 @@
 #include <linux/mm.h>
 #include <linux/slab.h>
 
-#include "../fat/msbuffer.h"
-
 #define DEBUG_LEVEL 0
 #if (DEBUG_LEVEL >= 1)
 #  define PRINTK1(x) printk x
@@ -48,12 +45,6 @@
 #  define PRINTK3(x)
 #endif
 
-#ifndef DEBUG
-# define CHECK_STACK
-#else
-# define CHECK_STACK check_stack(__FILE__, __LINE__)
-#endif
-
 static int vfat_hashi(struct dentry *parent, struct qstr *qstr);
 static int vfat_hash(struct dentry *parent, struct qstr *qstr);
 static int vfat_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b);
@@ -117,6 +108,13 @@
 	opts->unicode_xlate = opts->posixfs = 0;
 	opts->numtail = 1;
 	opts->utf8 = 0;
+	opts->shortname = VFAT_SFN_DISPLAY_LOWER | VFAT_SFN_CREATE_WIN95;
+	/* for backward compatible */
+	if (opts->nocase) {
+		opts->nocase = 0;
+		opts->shortname = VFAT_SFN_DISPLAY_WIN95
+		  		| VFAT_SFN_CREATE_WIN95;
+	}
 
 	if (!options) return 1;
 	save = 0;
@@ -142,6 +140,21 @@
 			if (ret) {
 				opts->numtail = !val;
 			}
+		} else if (!strcmp(this_char, "shortname")) {
+			if (!strcmp(value, "lower"))
+				opts->shortname = VFAT_SFN_DISPLAY_LOWER
+						| VFAT_SFN_CREATE_WIN95;
+			else if (!strcmp(value, "win95"))
+				opts->shortname = VFAT_SFN_DISPLAY_WIN95
+						| VFAT_SFN_CREATE_WIN95;
+			else if (!strcmp(value, "winnt"))
+				opts->shortname = VFAT_SFN_DISPLAY_WINNT
+						| VFAT_SFN_CREATE_WINNT;
+			else if (!strcmp(value, "mixed"))
+				opts->shortname = VFAT_SFN_DISPLAY_WINNT
+						| VFAT_SFN_CREATE_WIN95;
+			else
+				ret = 0;
 		}
 		if (this_char != options)
 			*(this_char-1) = ',';
@@ -157,167 +170,7 @@
 	}
 	return 1;
 }
-#if 0 /* not used functions */
-static inline unsigned char
-vfat_getlower(struct nls_table *t, unsigned char c)
-{
-	return t->charset2lower[c];
-}
-
-static inline unsigned char
-vfat_getupper(struct nls_table *t, unsigned char c)
-{
-	return t->charset2upper[c];
-}
-
-static inline int
-vfat_uni2short(struct nls_table *t, wchar_t uc, unsigned char *op, int bound)
-{
-	int charlen;
-
-	if ( (charlen = t->uni2char(uc, op, bound)) < 0)
-		charlen = 0;
-
-	return charlen;
-}
-
-static int vfat_valid_shortname(struct nls_table *nls, wchar_t *name, int len)
-{
-	wchar_t *walk;
-	unsigned char c, charbuf[NLS_MAX_CHARSET_SIZE];
-	int chl, chi;
-	int space;
-
-	if (vfat_uni2upper_short(nls, *name, charbuf, NLS_MAX_CHARSET_SIZE) == 0)
-		return -EINVAL;
-
-	if (IS_FREE(charbuf))
-		return -EINVAL;
-
-	chl = 0;
-	c = 0;
-	space = 1; /* disallow names starting with a dot */
-	for (walk = name; len && walk-name < 8;) {
-		len--;
-		chl = nls->uni2char(*walk++, charbuf, NLS_MAX_CHARSET_SIZE);
-		if (chl < 0)
-			return -EINVAL;
-
-		for (chi = 0; chi < chl; chi++) {
-			c = vfat_getupper(nls, charbuf[chi]);
-			if (!c) return -EINVAL;
-			if (charbuf[chi] != vfat_tolower(nls, c)) return -EINVAL;
-			if (strchr(replace_chars,c)) return -EINVAL;
-			if (c < ' '|| c==':') return -EINVAL;
-			if (c == '.') goto dot;
-			space = c == ' ';
-		}
-	}
-dot:;
-	if (space) return -EINVAL;
-	if (len && c != '.') {
-		len--;
-		if (vfat_uni2upper_short(nls, *walk++, charbuf, NLS_MAX_CHARSET_SIZE) == 1) {
-			if (charbuf[0] != '.') return -EINVAL;
-		} else
-			return -EINVAL;
-		c = '.';
-	}
-	if (c == '.') {
-		if (len >= 4) return -EINVAL;
-		while (len > 0) {
-			len--;
-			chl = nls->uni2char(*walk++, charbuf, NLS_MAX_CHARSET_SIZE);
-			if (chl < 0)
-				return -EINVAL;
-			for (chi = 0; chi < chl; chi++) {
-				c = vfat_getupper(nls, charbuf[chi]);
-				if (!c) return -EINVAL;
-				if (charbuf[chi] != vfat_tolower(nls, c)) return -EINVAL;
-				if (strchr(replace_chars,c))
-					return -EINVAL;
-				if (c < ' ' || c == '.'|| c==':')
-					return -EINVAL;
-				space = c == ' ';
-			}
-		}
-		if (space) return -EINVAL;
-	}
-
-	return 0;
-}
 
-static int vfat_format_name(struct nls_table *nls, wchar_t *name,
-				int len, char *res)
-{
-	char *walk;
-	unsigned char charbuf[NLS_MAX_CHARSET_SIZE];
-	int chi, chl;
-	int space;
-
-	if (vfat_uni2upper_short(nls, *name, charbuf, NLS_MAX_CHARSET_SIZE) == 0)
-		return -EINVAL;
-
-	if (IS_FREE(charbuf))
-		return -EINVAL;
-
-	space = 1; /* disallow names starting with a dot */
-	for (walk = res; len--; ) {
-		chl = vfat_uni2upper_short(nls, *name++, charbuf, NLS_MAX_CHARSET_SIZE);
-		if (chl == 0)
-			return -EINVAL;
-		for (chi = 0; chi < chl; chi++){
-			if (charbuf[chi] == '.') goto dot;
-			if (!charbuf[chi]) return -EINVAL;
-			if (walk-res == 8) return -EINVAL;
-			if (strchr(replace_chars,charbuf[chi])) return -EINVAL;
-			if (charbuf[chi] < ' '|| charbuf[chi]==':') return -EINVAL;
-			space = charbuf[chi] == ' ';
-			*walk = charbuf[chi];
-			walk++;
-		}
-	}
-dot:;
-	if (space) return -EINVAL;
-	if (len >= 0) {
-		while (walk-res < 8) *walk++ = ' ';
-		while (len > 0 && walk-res < MSDOS_NAME) {
-			chl = vfat_uni2upper_short(nls, *name++, charbuf, NLS_MAX_CHARSET_SIZE);
-			if (len < chl)
-				chl = len;
-			len -= chl;
-			for (chi = 0; chi < chl; chi++){
-				if (!charbuf[chi]) return -EINVAL;
-				if (strchr(replace_chars,charbuf[chi]))
-					return -EINVAL;
-				if (charbuf[chi] < ' ' || charbuf[chi] == '.'|| charbuf[chi]==':')
-					return -EINVAL;
-				space = charbuf[chi] == ' ';
-				*walk++ = charbuf[chi];
-			}
-		}
-		if (space) return -EINVAL;
-		if (len) return -EINVAL;
-	}
-	while (walk-res < MSDOS_NAME) *walk++ = ' ';
-
-	return 0;
-}
-
-static inline int
-vfat_uni2upper_short(struct nls_table *t, wchar_t uc, char *op, int bound)
-{
-	int chl;
-
-	if ( (chl = t->uni2char(uc, op, bound)) < 0)
-		chl = 0;
-
-	if (chl == 1)
-		op[0] = vfat_toupper(t, op[0]);
-
-	return chl;
-}
-#endif
 static inline unsigned char
 vfat_tolower(struct nls_table *t, unsigned char c)
 {
@@ -437,33 +290,6 @@
 
 #ifdef DEBUG
 
-static void
-check_stack(const char *fname, int lineno)
-{
-	int stack_level;
-	char *pg_dir;
-
-	stack_level = (long)(&pg_dir)-current->kernel_stack_page;
-	if (stack_level < 0)
-	        printk("*-*-*-* vfat kstack overflow in %s line %d: SL=%d\n",
-		       fname, lineno, stack_level);
-	else if (stack_level < 500)
-	        printk("*-*-*-* vfat kstack low in %s line %d: SL=%d\n",
-		       fname, lineno, stack_level);
-#if 0
-	else
-		printk("------- vfat kstack ok in %s line %d: SL=%d\n",
-		       fname, lineno, stack_level);
-#endif
-#if 0
-	if (*(unsigned long *) current->kernel_stack_page != STACK_MAGIC) {
-		printk("******* vfat stack corruption detected in %s at line %d\n",
-		       fname, lineno);
-	}
-#endif
-}
-
-static int debug = 0;
 static void dump_fat(struct super_block *sb,int start)
 {
 	printk("[");
@@ -510,8 +336,10 @@
 /* Characters that are undesirable in an MS-DOS file name */
 
 static wchar_t bad_chars[] = {
-	/*  `*'     `?'     `<'    `>'      `|'     `"'     `:'     `/'     `\' */
-	0x002A, 0x003F, 0x003C, 0x003E, 0x007C, 0x0022, 0x003A, 0x002F, 0x005C, 0,
+	/*  `*'     `?'     `<'    `>'      `|'     `"'     `:'     `/' */
+	0x002A, 0x003F, 0x003C, 0x003E, 0x007C, 0x0022, 0x003A, 0x002F,
+	/*  `\' */
+	0x005C, 0,
 };
 #define IS_BADCHAR(uni)	(vfat_unistrchr(bad_chars, (uni)) != NULL)
 
@@ -521,6 +349,13 @@
 };
 #define IS_REPLACECHAR(uni)	(vfat_unistrchr(replace_chars, (uni)) != NULL)
 
+static wchar_t skip_chars[] = {
+	/*  `.'     ` ' */
+	0x002E, 0x0020, 0,
+};
+#define IS_SKIPCHAR(uni) \
+	((wchar_t)(uni) == skip_chars[0] || (wchar_t)(uni) == skip_chars[1])
+
 static inline wchar_t *vfat_unistrchr(const wchar_t *s, const wchar_t c)
 {
 	for(; *s != c; ++s)
@@ -582,47 +417,119 @@
 	return 0;
 }
 
-static wchar_t skip_chars[] = {
-	/*  `.'     ` ' */
-	0x002E, 0x0020, 0,
+/* 
+ * 1) Valid characters for the 8.3 format alias are any combination of
+ * letters, uppercase alphabets, digits, any of the
+ * following special characters:
+ *     $ % ' ` - @ { } ~ ! # ( ) & _ ^
+ * In this case Longfilename is not stored in disk.
+ *
+ * WinNT's Extension:
+ * File name and extension name is contain uppercase/lowercase
+ * only. And it is expressed by CASE_LOWER_BASE and CASE_LOWER_EXT.
+ *     
+ * 2) File name is 8.3 format, but it contain the uppercase and
+ * lowercase char, muliti bytes char, etc. In this case numtail is not
+ * added, but Longfilename is stored.
+ * 
+ * 3) When the one except for the above, or the following special
+ * character are contained:
+ *        .   [ ] ; , + =
+ * numtail is added, and Longfilename must be stored in disk .
+ */
+struct shortname_info {
+	unsigned char lower:1,
+		      upper:1,
+		      valid:1;
 };
-#define IS_SKIPCHAR(uni) \
-	((wchar_t)(uni) == skip_chars[0] || (wchar_t)(uni) == skip_chars[1])
+#define INIT_SHORTNAME_INFO(x)	do {		\
+	(x)->lower = 1;				\
+	(x)->upper = 1;				\
+	(x)->valid = 1;				\
+} while (0);
 
-/* Given a valid longname, create a unique shortname.  Make sure the
+static inline unsigned char
+shortname_info_to_lcase(struct shortname_info *base,
+			struct shortname_info *ext)
+{
+	unsigned char lcase = 0;
+
+	if (base->valid && ext->valid) {
+		if (!base->upper && base->lower && (ext->lower || ext->upper))
+			lcase |= CASE_LOWER_BASE;
+		if (!ext->upper && ext->lower && (base->lower || base->upper))
+			lcase |= CASE_LOWER_EXT;
+	}
+
+	return lcase;
+}
+
+static inline int to_shortname_char(struct nls_table *nls,
+				    char *buf, int buf_size, wchar_t *src,
+				    struct shortname_info *info)
+{
+	int len;
+
+	if (IS_SKIPCHAR(*src)) {
+		info->valid = 0;
+		return 0;
+	}
+	if (IS_REPLACECHAR(*src)) {
+		info->valid = 0;
+		buf[0] = '_';
+		return 1;
+	}
+	
+	len = nls->uni2char(*src, buf, buf_size);
+	if (len <= 0) {
+		info->valid = 0;
+		buf[0] = '_';
+		len = 1;
+	} else if (len == 1) {
+		unsigned char prev = buf[0];
+
+		if (buf[0] >= 0x7F) {
+			info->lower = 0;
+			info->upper = 0;
+		}
+
+		buf[0] = vfat_toupper(nls, buf[0]);
+		if (isalpha(buf[0])) {
+			if (buf[0] == prev)
+				info->lower = 0;
+			else
+				info->upper = 0;
+		}
+	} else {
+		info->lower = 0;
+		info->upper = 0;
+	}
+	
+	return len;
+}
+
+/*
+ * Given a valid longname, create a unique shortname.  Make sure the
  * shortname does not exist
  * Returns negative number on error, 0 for a normal
  * return, and 1 for valid shortname
  */
 static int vfat_create_shortname(struct inode *dir, struct nls_table *nls,
 				 wchar_t *uname, int ulen,
-				 char *name_res)
+				 char *name_res, unsigned char *lcase)
 {
 	wchar_t *ip, *ext_start, *end, *name_start;
 	unsigned char base[9], ext[4], buf[8], *p;
 	unsigned char charbuf[NLS_MAX_CHARSET_SIZE];
 	int chl, chi;
 	int sz = 0, extlen, baselen, i, numtail_baselen, numtail2_baselen;
-	int is_uppercase, is_shortname;
+	int is_shortname;
+	struct shortname_info base_info, ext_info;
+	unsigned short opt_shortname = MSDOS_SB(dir->i_sb)->options.shortname;
 
-	/* 
-	 * 1) Valid characters for the 8.3 format alias are any
-	 * combination of letters, uppercase alphabets, digits, any of
-	 * the following special characters:
-	 *     $ % ' ` - @ { } ~ ! # ( ) & _ ^
-	 * In this case Longfilename is not stored in disk.
-	 *     
-	 * 2) File name is 8.3 format, but it contain the lowercase
-	 * alphabet etc. In this case numtail is not added, but
-	 * Longfilename is stored.
-	 * 
-	 * 3) When the one except for the above, or the following special
-	 * character are contained:
-	 *        .   [ ] ; , + =
-	 * numtail is added, and Longfilename must be stored in disk .
-	 */
-	is_uppercase = 1;
 	is_shortname = 1;
+	INIT_SHORTNAME_INFO(&base_info);
+	INIT_SHORTNAME_INFO(&ext_info);
 
 	/* Now, we need to create a shortname from the long name */
 	ext_start = end = &uname[ulen];
@@ -662,31 +569,11 @@
 
 	numtail_baselen = 6;
 	numtail2_baselen = 2;
-	for (baselen = i = 0, p = base, ip = uname; i < sz; i++, ip++)
-	{
-		if (IS_SKIPCHAR(*ip)) {
-			is_shortname = 0;
+	for (baselen = i = 0, p = base, ip = uname; i < sz; i++, ip++) {
+		chl = to_shortname_char(nls, charbuf, sizeof(charbuf),
+					ip, &base_info);
+		if (chl == 0)
 			continue;
-		}
-		if (IS_REPLACECHAR(*ip)) {
-			is_shortname = 0;
-			charbuf[0] = '_';
-			chl = 1;
-		} else {
-			chl = nls->uni2char(*ip, charbuf, sizeof(charbuf));
-			if (chl <= 0) {
-				is_shortname = 0;
-				charbuf[0]  = '_';
-				chl = 1;
-			} else if (chl == 1) {
-				unsigned char c = charbuf[0];
-				charbuf[0] = vfat_toupper(nls, charbuf[0]);
-				if (c >= 0x7F || charbuf[0] != c)
-					is_uppercase = 0;
-			} else {
-				is_uppercase = 0;
-			}
-		}
 
 		if (baselen < 2 && (baselen + chl) > 2)
 			numtail2_baselen = baselen;
@@ -711,30 +598,11 @@
 	extlen = 0;
 	if (ext_start) {
 		for (p = ext, ip = ext_start; extlen < 3 && ip < end; ip++) {
-			if (IS_SKIPCHAR(*ip)) {
-				is_shortname = 0;
+			chl = to_shortname_char(nls, charbuf, sizeof(charbuf),
+						ip, &ext_info);
+			if (chl == 0)
 				continue;
-			}
-			if (IS_REPLACECHAR(*ip)) {
-				is_shortname = 0;
-				charbuf[0] = '_';
-				chl = 1;
-			} else {
-				chl = nls->uni2char(*ip, charbuf, sizeof(charbuf));
-				if (chl <= 0) {
-					is_shortname = 0;
-					charbuf[0] = '_';
-					chl = 1;
-				} else if (chl == 1) {
-					unsigned char c = charbuf[0];
-					charbuf[0] = vfat_toupper(nls, charbuf[0]);
-					if (c >= 0x7F || charbuf[0] != c)
-						is_uppercase = 0;
-				} else {
-					is_uppercase = 0;
-				}
-			}
-				
+
 			if ((extlen + chl) > 3) {
 				is_shortname = 0;
 				break;
@@ -763,14 +631,26 @@
 	 */
 
 	memset(name_res, ' ', MSDOS_NAME);
-	memcpy(name_res,base,baselen);
-	memcpy(name_res+8,ext,extlen);
-
-	if (is_shortname) {
-		if (vfat_find_form(dir, name_res) < 0)
-			return is_uppercase;
-		else
+	memcpy(name_res, base, baselen);
+	memcpy(name_res + 8, ext, extlen);
+	*lcase = 0;
+	if (is_shortname && base_info.valid && ext_info.valid) {
+		if (vfat_find_form(dir, name_res) == 0)
 			return -EEXIST;
+
+		if (opt_shortname & VFAT_SFN_CREATE_WIN95) {
+			return (base_info.upper && ext_info.upper);
+		} else if (opt_shortname & VFAT_SFN_CREATE_WINNT) {
+			if ((base_info.upper || base_info.lower)
+			    && (ext_info.upper || ext_info.lower)) {
+				*lcase = shortname_info_to_lcase(&base_info,
+								 &ext_info);
+				return 1;
+			}
+			return 0;
+		} else {
+			BUG();
+		}
 	}
 	
 	if (MSDOS_SB(dir->i_sb)->options.numtail == 0)
@@ -866,7 +746,6 @@
 				} else {
 					if ((charlen = nls->char2uni(ip, len-i, (wchar_t *)op)) < 0)
 						return -EINVAL;
-
 					ip += charlen;
 					i += charlen;
 					op += 2;
@@ -904,31 +783,31 @@
 
 static int
 vfat_fill_slots(struct inode *dir, struct msdos_dir_slot *ds, const char *name,
-		int len, int *slots, int uni_xlate)
+		int len, int *slots, int is_dir, int uni_xlate)
 {
 	struct nls_table *nls_io, *nls_disk;
 	wchar_t *uname;
 	struct msdos_dir_slot *ps;
 	struct msdos_dir_entry *de;
 	unsigned long page;
-	unsigned char cksum;
-	const char *ip;
+	unsigned char cksum, lcase;
 	char *uniname, msdos_name[MSDOS_NAME];
 	int res, utf8, slot, ulen, unilen, i;
 	loff_t offset;
 
-	de = (struct msdos_dir_entry *) ds;
+	*slots = 0;
 	utf8 = MSDOS_SB(dir->i_sb)->options.utf8;
 	nls_io = MSDOS_SB(dir->i_sb)->nls_io;
 	nls_disk = MSDOS_SB(dir->i_sb)->nls_disk;
 
-	if (name[len-1] == '.') len--;
+	if (name[len-1] == '.')
+		len--;
 	if(!(page = __get_free_page(GFP_KERNEL)))
 		return -ENOMEM;
-	uniname = (char *) page;
 
+	uniname = (char *) page;
 	res = xlate_to_uni(name, len, uniname, &ulen, &unilen, uni_xlate,
-								utf8, nls_io);
+			   utf8, nls_io);
 	if (res < 0)
 		goto out_free;
 
@@ -937,15 +816,17 @@
 	if (res < 0)
 		goto out_free;
 
-	res = vfat_create_shortname(dir, nls_disk, uname, ulen, msdos_name);
+	res = vfat_create_shortname(dir, nls_disk, uname, ulen,
+				    msdos_name, &lcase);
 	if (res < 0)
 		goto out_free;
 	else if (res == 1) {
-		strncpy(de->name, msdos_name, MSDOS_NAME);
+		de = (struct msdos_dir_entry *)ds;
 		res = 0;
-		goto out_free;
+		goto shortname;
 	}
 
+	/* build the entry of long file name */
 	*slots = unilen / 13;
 	for (cksum = i = 0; i < 11; i++) {
 		cksum = (((cksum&1)<<7)|((cksum&0xfe)>>1)) + msdos_name[i];
@@ -958,18 +839,26 @@
 		ps->reserved = 0;
 		ps->alias_checksum = cksum;
 		ps->start = 0;
-		offset = (slot - 1) * 26;
-		ip = &uniname[offset];
-		memcpy(ps->name0_4, ip, 10);
-		memcpy(ps->name5_10, ip+10, 12);
-		memcpy(ps->name11_12, ip+22, 4);
+		offset = (slot - 1) * 13;
+		fatwchar_to16(ps->name0_4, uname + offset, 5);
+		fatwchar_to16(ps->name5_10, uname + offset + 5, 6);
+		fatwchar_to16(ps->name11_12, uname + offset + 11, 2);
 	}
 	ds[0].id |= 0x40;
-
 	de = (struct msdos_dir_entry *) ps;
+
+shortname:
 	PRINTK3(("vfat_fill_slots 9\n"));
-	strncpy(de->name, msdos_name, MSDOS_NAME);
+	/* build the entry of 8.3 alias name */
 	(*slots)++;
+	strncpy(de->name, msdos_name, MSDOS_NAME);
+	de->attr = is_dir ? ATTR_DIR : ATTR_ARCH;
+	de->lcase = lcase;
+	de->adate = de->cdate = de->date = 0;
+	de->ctime_ms = de->ctime = de->time = 0;
+	de->start = 0;
+	de->starthi = 0;
+	de->size = 0;
 
 out_free:
 	free_page(page);
@@ -978,96 +867,92 @@
 
 /* We can't get "." or ".." here - VFS takes care of those cases */
 
-static int vfat_build_slots(struct inode *dir,const char *name,int len,
-     struct msdos_dir_slot *ds, int *slots)
+static int vfat_build_slots(struct inode *dir, const char *name, int len,
+			    struct msdos_dir_slot *ds, int *slots, int is_dir)
 {
 	int res, xlate;
 
 	xlate = MSDOS_SB(dir->i_sb)->options.unicode_xlate;
-	*slots = 1;
 	res = vfat_valid_longname(name, len, xlate);
 	if (res < 0)
 		return res;
-	return vfat_fill_slots(dir, ds, name, len, slots, xlate);
+
+	return vfat_fill_slots(dir, ds, name, len, slots, is_dir, xlate);
 }
 
 static int vfat_add_entry(struct inode *dir,struct qstr* qname,
-	int is_dir,struct vfat_slot_info *sinfo_out,
-	struct buffer_head **bh, struct msdos_dir_entry **de)
+			  int is_dir, struct vfat_slot_info *sinfo_out,
+			  struct buffer_head **bh, struct msdos_dir_entry **de)
 {
 	struct super_block *sb = dir->i_sb;
-	struct msdos_dir_slot *ps;
+	struct msdos_dir_slot *dir_slots;
 	loff_t offset;
-	struct msdos_dir_slot *ds;
 	int slots, slot;
-	int res;
-	struct msdos_dir_entry *de1;
-	struct buffer_head *bh1;
-	int ino;
-	int len;
+	int res, len;
+	struct msdos_dir_entry *dummy_de;
+	struct buffer_head *dummy_bh;
+	int dummy_ino;
 	loff_t dummy;
 
-	ds = (struct msdos_dir_slot *)
-	    kmalloc(sizeof(struct msdos_dir_slot)*MSDOS_SLOTS, GFP_KERNEL);
-	if (ds == NULL) return -ENOMEM;
+	dir_slots = (struct msdos_dir_slot *)
+	       kmalloc(sizeof(struct msdos_dir_slot) * MSDOS_SLOTS, GFP_KERNEL);
+	if (dir_slots == NULL)
+		return -ENOMEM;
 
 	len = qname->len;
 	while (len && qname->name[len-1] == '.')
 		len--;
 	res = fat_search_long(dir, qname->name, len,
-			(MSDOS_SB(sb)->options.name_check != 's') ||
-			!MSDOS_SB(sb)->options.posixfs,
-			&dummy, &dummy);
+			      (MSDOS_SB(sb)->options.name_check != 's')
+			      || !MSDOS_SB(sb)->options.posixfs,
+			      &dummy, &dummy);
 	if (res > 0) /* found */
 		res = -EEXIST;
 	if (res)
 		goto cleanup;
 
-	res = vfat_build_slots(dir, qname->name, len, ds, &slots);
+	res = vfat_build_slots(dir, qname->name, len,
+			       dir_slots, &slots, is_dir);
 	if (res < 0)
 		goto cleanup;
 
-	offset = fat_add_entries(dir, slots, &bh1, &de1, &ino);
+	/* build the empty directory entry of number of slots */
+	offset = fat_add_entries(dir, slots, &dummy_bh, &dummy_de, &dummy_ino);
 	if (offset < 0) {
 		res = offset;
 		goto cleanup;
 	}
-	fat_brelse(sb, bh1);
+	fat_brelse(sb, dummy_bh);
 
 	/* Now create the new entry */
 	*bh = NULL;
-	for (slot = 0, ps = ds; slot < slots; slot++, ps++) {
-		if (fat_get_entry(dir,&offset,bh,de, &sinfo_out->ino) < 0) {
+	for (slot = 0; slot < slots; slot++) {
+		if (fat_get_entry(dir, &offset, bh, de, &sinfo_out->ino) < 0) {
 			res = -EIO;
 			goto cleanup;
 		}
-		memcpy(*de, ps, sizeof(struct msdos_dir_slot));
+		memcpy(*de, dir_slots + slot, sizeof(struct msdos_dir_slot));
 		fat_mark_buffer_dirty(sb, *bh);
 	}
 
+	res = 0;
+	/* update timestamp */
 	dir->i_ctime = dir->i_mtime = dir->i_atime = CURRENT_TIME;
 	mark_inode_dirty(dir);
 
-	fat_date_unix2dos(dir->i_mtime,&(*de)->time,&(*de)->date);
-	(*de)->ctime_ms = 0;
+	fat_date_unix2dos(dir->i_mtime, &(*de)->time, &(*de)->date);
 	(*de)->ctime = (*de)->time;
 	(*de)->adate = (*de)->cdate = (*de)->date;
-	(*de)->start = 0;
-	(*de)->starthi = 0;
-	(*de)->size = 0;
-	(*de)->attr = is_dir ? ATTR_DIR : ATTR_ARCH;
-	(*de)->lcase = CASE_LOWER_BASE | CASE_LOWER_EXT;
-
 
 	fat_mark_buffer_dirty(sb, *bh);
 
 	/* slots can't be less than 1 */
 	sinfo_out->long_slots = slots - 1;
-	sinfo_out->longname_offset = offset - sizeof(struct msdos_dir_slot) * slots;
-	res = 0;
+	sinfo_out->longname_offset =
+		offset - sizeof(struct msdos_dir_slot) * slots;
 
 cleanup:
-	kfree(ds);
+	kfree(dir_slots);
 	return res;
 }
 
diff -urN linux-2.4.13-pre1/fs/vfat/vfatfs_syms.c linux/fs/vfat/vfatfs_syms.c
--- linux-2.4.13-pre1/fs/vfat/vfatfs_syms.c	Mon Mar 13 12:35:39 2000
+++ linux/fs/vfat/vfatfs_syms.c	Mon Dec  3 23:17:33 2001
@@ -5,8 +5,6 @@
  * These symbols are used by dmsdos.
  */
 
-#define ASC_LINUX_VERSION(V, P, S)	(((V) * 65536) + ((P) * 256) + (S))
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
 
diff -urN linux-2.4.13-pre1/include/asm-alpha/bitops.h linux/include/asm-alpha/bitops.h
--- linux-2.4.13-pre1/include/asm-alpha/bitops.h	Mon Jul  9 21:26:24 2001
+++ linux/include/asm-alpha/bitops.h	Mon Dec  3 23:17:33 2001
@@ -20,7 +20,7 @@
  * bit 0 is the LSB of addr; bit 64 is the LSB of (addr+1).
  */
 
-extern __inline__ void
+static inline void
 set_bit(unsigned long nr, volatile void * addr)
 {
 	unsigned long temp;
@@ -41,7 +41,7 @@
 /*
  * WARNING: non atomic version.
  */
-extern __inline__ void
+static inline void
 __set_bit(unsigned long nr, volatile void * addr)
 {
 	int *m = ((int *) addr) + (nr >> 5);
@@ -52,7 +52,7 @@
 #define smp_mb__before_clear_bit()	smp_mb()
 #define smp_mb__after_clear_bit()	smp_mb()
 
-extern __inline__ void
+static inline void
 clear_bit(unsigned long nr, volatile void * addr)
 {
 	unsigned long temp;
@@ -81,7 +81,7 @@
 	*m ^= 1 << (nr & 31);
 }
 
-extern __inline__ void
+static inline void
 change_bit(unsigned long nr, volatile void * addr)
 {
 	unsigned long temp;
@@ -99,7 +99,7 @@
 	:"Ir" (1UL << (nr & 31)), "m" (*m));
 }
 
-extern __inline__ int
+static inline int
 test_and_set_bit(unsigned long nr, volatile void *addr)
 {
 	unsigned long oldbit;
@@ -129,7 +129,7 @@
 /*
  * WARNING: non atomic version.
  */
-extern __inline__ int
+static inline int
 __test_and_set_bit(unsigned long nr, volatile void * addr)
 {
 	unsigned long mask = 1 << (nr & 0x1f);
@@ -140,7 +140,7 @@
 	return (old & mask) != 0;
 }
 
-extern __inline__ int
+static inline int
 test_and_clear_bit(unsigned long nr, volatile void * addr)
 {
 	unsigned long oldbit;
@@ -170,7 +170,7 @@
 /*
  * WARNING: non atomic version.
  */
-extern __inline__ int
+static inline int
 __test_and_clear_bit(unsigned long nr, volatile void * addr)
 {
 	unsigned long mask = 1 << (nr & 0x1f);
@@ -195,7 +195,7 @@
 	return (old & mask) != 0;
 }
 
-extern __inline__ int
+static inline int
 test_and_change_bit(unsigned long nr, volatile void * addr)
 {
 	unsigned long oldbit;
@@ -220,7 +220,7 @@
 	return oldbit != 0;
 }
 
-extern __inline__ int
+static inline int
 test_bit(int nr, volatile void * addr)
 {
 	return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL;
@@ -233,7 +233,7 @@
  * Do a binary search on the bits.  Due to the nature of large
  * constants on the alpha, it is worthwhile to split the search.
  */
-extern inline unsigned long ffz_b(unsigned long x)
+static inline unsigned long ffz_b(unsigned long x)
 {
 	unsigned long sum = 0;
 
@@ -245,7 +245,7 @@
 	return sum;
 }
 
-extern inline unsigned long ffz(unsigned long word)
+static inline unsigned long ffz(unsigned long word)
 {
 #if defined(__alpha_cix__) && defined(__alpha_fix__)
 	/* Whee.  EV67 can calculate it directly.  */
@@ -272,12 +272,32 @@
  * differs in spirit from the above ffz (man ffs).
  */
 
-extern inline int ffs(int word)
+static inline int ffs(int word)
 {
 	int result = ffz(~word);
 	return word ? result+1 : 0;
 }
 
+/* Compute powers of two for the given integer.  */
+static inline int floor_log2(unsigned long word)
+{
+	long bit;
+#if defined(__alpha_cix__) && defined(__alpha_fix__)
+	__asm__("ctlz %1,%0" : "=r"(bit) : "r"(word));
+	return 63 - bit;
+#else
+	for (bit = -1; word ; bit++)
+		word >>= 1;
+	return bit;
+#endif
+}
+
+static inline int ceil_log2(unsigned int word)
+{
+	long bit = floor_log2(word);
+	return bit + (word > (1UL << bit));
+}
+
 /*
  * hweightN: returns the hamming weight (i.e. the number
  * of bits set) of a N-bit word
@@ -285,7 +305,7 @@
 
 #if defined(__alpha_cix__) && defined(__alpha_fix__)
 /* Whee.  EV67 can calculate it directly.  */
-extern __inline__ unsigned long hweight64(unsigned long w)
+static inline unsigned long hweight64(unsigned long w)
 {
 	unsigned long result;
 	__asm__("ctpop %1,%0" : "=r"(result) : "r"(w));
@@ -306,7 +326,7 @@
 /*
  * Find next zero bit in a bitmap reasonably efficiently..
  */
-extern inline unsigned long
+static inline unsigned long
 find_next_zero_bit(void * addr, unsigned long size, unsigned long offset)
 {
 	unsigned long * p = ((unsigned long *) addr) + (offset >> 6);
diff -urN linux-2.4.13-pre1/include/asm-alpha/core_cia.h linux/include/asm-alpha/core_cia.h
--- linux-2.4.13-pre1/include/asm-alpha/core_cia.h	Thu Sep 13 15:21:32 2001
+++ linux/include/asm-alpha/core_cia.h	Mon Dec  3 23:17:33 2001
@@ -263,6 +263,9 @@
 #define PYXIS_IIC_CTRL			(IDENT_ADDR + 0x87A00002C0UL)
 #define PYXIS_RESET			(IDENT_ADDR + 0x8780000900UL)
 
+/* Offset between ram physical addresses and pci64 DAC bus addresses.  */
+#define PYXIS_DAC_OFFSET		(1UL << 40)
+
 /*
  * Data structure for handling CIA machine checks.
  */
diff -urN linux-2.4.13-pre1/include/asm-alpha/core_mcpcia.h linux/include/asm-alpha/core_mcpcia.h
--- linux-2.4.13-pre1/include/asm-alpha/core_mcpcia.h	Thu Sep 13 15:21:32 2001
+++ linux/include/asm-alpha/core_mcpcia.h	Mon Dec  3 23:17:33 2001
@@ -181,6 +181,8 @@
 #define MCPCIA_IO_BIAS		MCPCIA_IO(4)
 #define MCPCIA_MEM_BIAS		MCPCIA_DENSE(4)
 
+/* Offset between ram physical addresses and pci64 DAC bus addresses.  */
+#define MCPCIA_DAC_OFFSET	(1UL << 40)
 
 /*
  * Data structure for handling MCPCIA machine checks:
diff -urN linux-2.4.13-pre1/include/asm-alpha/core_titan.h linux/include/asm-alpha/core_titan.h
--- linux-2.4.13-pre1/include/asm-alpha/core_titan.h	Thu Sep 13 15:21:32 2001
+++ linux/include/asm-alpha/core_titan.h	Mon Dec  3 23:17:33 2001
@@ -308,14 +308,18 @@
  * devices can use their familiar numbers and have them map to bus 0.
  */
 
-#define TITAN_IO_BIAS          TITAN_IO(0)
-#define TITAN_MEM_BIAS         TITAN_MEM(0)
+#define TITAN_IO_BIAS		TITAN_IO(0)
+#define TITAN_MEM_BIAS		TITAN_MEM(0)
 
 /* The IO address space is larger than 0xffff */
 #define TITAN_IO_SPACE		(TITAN_CONF(0) - TITAN_IO(0))
 
 /* TIG Space */
 #define TITAN_TIG_SPACE		(TITAN_BASE + 0x100000000UL)
+
+/* Offset between ram physical addresses and pci64 DAC bus addresses.  */
+/* ??? Just a guess.  Ought to confirm it hasn't been moved.  */
+#define TITAN_DAC_OFFSET	(1UL << 40)
 
 /*
  * Data structure for handling TITAN machine checks:
diff -urN linux-2.4.13-pre1/include/asm-alpha/core_tsunami.h linux/include/asm-alpha/core_tsunami.h
--- linux-2.4.13-pre1/include/asm-alpha/core_tsunami.h	Thu Sep 13 15:21:32 2001
+++ linux/include/asm-alpha/core_tsunami.h	Mon Dec  3 23:17:33 2001
@@ -275,7 +275,7 @@
 /* The IO address space is larger than 0xffff */
 #define TSUNAMI_IO_SPACE	(TSUNAMI_CONF(0) - TSUNAMI_IO(0))
 
-/* Offset between ram physical addresses and pci64 DAC bus addresses */
+/* Offset between ram physical addresses and pci64 DAC bus addresses.  */
 #define TSUNAMI_DAC_OFFSET	(1UL << 40)
 
 /*
diff -urN linux-2.4.13-pre1/include/asm-alpha/machvec.h linux/include/asm-alpha/machvec.h
--- linux-2.4.13-pre1/include/asm-alpha/machvec.h	Thu Sep 13 15:21:32 2001
+++ linux/include/asm-alpha/machvec.h	Mon Dec  3 23:17:33 2001
@@ -39,6 +39,7 @@
 	unsigned long iack_sc;
 	unsigned long min_io_address;
 	unsigned long min_mem_address;
+	unsigned long pci_dac_offset;
 
 	void (*mv_pci_tbi)(struct pci_controller *hose,
 			   dma_addr_t start, dma_addr_t end);
diff -urN linux-2.4.13-pre1/include/asm-alpha/pci.h linux/include/asm-alpha/pci.h
--- linux-2.4.13-pre1/include/asm-alpha/pci.h	Mon May 21 13:38:41 2001
+++ linux/include/asm-alpha/pci.h	Mon Dec  3 23:17:33 2001
@@ -15,6 +15,7 @@
 struct pci_bus;
 struct resource;
 struct pci_iommu_arena;
+struct page;
 
 /* A controller.  Used to manage multiple PCI busses.  */
 
@@ -60,12 +61,17 @@
 
 /* IOMMU controls.  */
 
+/* The PCI address space does not equal the physical memory address space.
+   The networking and block device layers use this boolean for bounce buffer
+   decisions.  */
+#define PCI_DMA_BUS_IS_PHYS  0
+
 /* Allocate and map kernel buffer using consistant mode DMA for PCI
    device.  Returns non-NULL cpu-view pointer to the buffer if
    successful and sets *DMA_ADDRP to the pci side dma address as well,
    else DMA_ADDRP is undefined.  */
 
-extern void *pci_alloc_consistent(struct pci_dev *, long, dma_addr_t *);
+extern void *pci_alloc_consistent(struct pci_dev *, size_t, dma_addr_t *);
 
 /* Free and unmap a consistant DMA buffer.  CPU_ADDR and DMA_ADDR must
    be values that were returned from pci_alloc_consistant.  SIZE must
@@ -73,14 +79,18 @@
    References to the memory and mappings assosciated with CPU_ADDR or
    DMA_ADDR past this call are illegal.  */
 
-extern void pci_free_consistent(struct pci_dev *, long, void *, dma_addr_t);
+extern void pci_free_consistent(struct pci_dev *, size_t, void *, dma_addr_t);
 
 /* Map a single buffer of the indicate size for PCI DMA in streaming
    mode.  The 32-bit PCI bus mastering address to use is returned.
    Once the device is given the dma address, the device owns this memory
    until either pci_unmap_single or pci_dma_sync_single is performed.  */
 
-extern dma_addr_t pci_map_single(struct pci_dev *, void *, long, int);
+extern dma_addr_t pci_map_single(struct pci_dev *, void *, size_t, int);
+
+/* Likewise, but for a page instead of an address.  */
+extern dma_addr_t pci_map_page(struct pci_dev *, struct page *,
+			       unsigned long, size_t, int);
 
 /* Unmap a single streaming mode DMA translation.  The DMA_ADDR and
    SIZE must match what was provided for in a previous pci_map_single
@@ -88,7 +98,8 @@
    the cpu to the buffer are guarenteed to see whatever the device
    wrote there.  */
 
-extern void pci_unmap_single(struct pci_dev *, dma_addr_t, long, int);
+extern void pci_unmap_single(struct pci_dev *, dma_addr_t, size_t, int);
+extern void pci_unmap_page(struct pci_dev *, dma_addr_t, size_t, int);
 
 /* Map a set of buffers described by scatterlist in streaming mode for
    PCI DMA.  This is the scather-gather version of the above
@@ -121,7 +132,7 @@
    point you give the PCI dma address back to the card, the device
    again owns the buffer.  */
 
-extern inline void
+static inline void
 pci_dma_sync_single(struct pci_dev *dev, dma_addr_t dma_addr, long size,
 		    int direction)
 {
@@ -132,7 +143,7 @@
    translations after a transfer.  The same as pci_dma_sync_single but
    for a scatter-gather list, same rules and usage.  */
 
-extern inline void
+static inline void
 pci_dma_sync_sg(struct pci_dev *dev, struct scatterlist *sg, int nents,
 	        int direction)
 {
@@ -144,7 +155,22 @@
    only drive the low 24-bits during PCI bus mastering, then
    you would pass 0x00ffffff as the mask to this function.  */
 
-extern int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask);
+extern int pci_dma_supported(struct pci_dev *hwdev, u64 mask);
+
+/* True if the machine supports DAC addressing, and DEV can
+   make use of it given MASK.  */
+extern int pci_dac_dma_supported(struct pci_dev *hwdev, u64 mask);
+
+/* Convert to/from DAC dma address and struct page.  */
+extern dma64_addr_t pci_dac_page_to_dma(struct pci_dev *, struct page *, unsigned long, int);
+extern struct page *pci_dac_dma_to_page(struct pci_dev *, dma64_addr_t);
+extern unsigned long pci_dac_dma_to_offset(struct pci_dev *, dma64_addr_t);
+
+static __inline__ void
+pci_dac_dma_sync_single(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
+{
+	/* Nothing to do. */
+}
 
 /* Return the index of the PCI controller for device PDEV. */
 extern int pci_controller_num(struct pci_dev *pdev);
diff -urN linux-2.4.13-pre1/include/asm-alpha/scatterlist.h linux/include/asm-alpha/scatterlist.h
--- linux-2.4.13-pre1/include/asm-alpha/scatterlist.h	Mon Feb  7 20:09:05 2000
+++ linux/include/asm-alpha/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -1,19 +1,25 @@
 #ifndef _ALPHA_SCATTERLIST_H
 #define _ALPHA_SCATTERLIST_H
 
-#include <linux/types.h>
-
+#include <asm/page.h>
+  
 struct scatterlist {
-	char *address;			/* Source/target vaddr.  */
-	char *alt_address;		/* Location of actual if address is a
-					   dma indirect buffer, else NULL.  */
-	dma_addr_t dma_address;
+	/* This will disappear in 2.5.x */
+	char *address;
+
+	/* These two are only valid if ADDRESS member of this
+	   struct is NULL.  */
+	struct page *page;
+	unsigned int offset;
+
 	unsigned int length;
-	unsigned int dma_length;
+
+	dma_addr_t dma_address;
+	__u32 dma_length;
 };
 
-#define sg_dma_address(sg) ((sg)->dma_address)
-#define sg_dma_len(sg)     ((sg)->dma_length)
+#define sg_dma_address(sg)	((sg)->dma_address)
+#define sg_dma_len(sg)		((sg)->dma_length)
 
 #define ISA_DMA_THRESHOLD (~0UL)
 
diff -urN linux-2.4.13-pre1/include/asm-alpha/types.h linux/include/asm-alpha/types.h
--- linux-2.4.13-pre1/include/asm-alpha/types.h	Mon Feb  7 20:09:05 2000
+++ linux/include/asm-alpha/types.h	Mon Dec  3 23:17:33 2001
@@ -47,10 +47,8 @@
 
 #define BITS_PER_LONG 64
 
-/* PCI dma addresses are 32-bits wide.  Ignore PCI64 for now, since
-   we'll typically be sending it all through iommu tables anyway.  */
-
-typedef u32 dma_addr_t;
+typedef u64 dma_addr_t;
+typedef u64 dma64_addr_t;
 
 #endif /* __KERNEL__ */
 #endif /* _ALPHA_TYPES_H */
diff -urN linux-2.4.13-pre1/include/asm-arm/pci.h linux/include/asm-arm/pci.h
--- linux-2.4.13-pre1/include/asm-arm/pci.h	Mon Dec  3 23:17:24 2001
+++ linux/include/asm-arm/pci.h	Mon Dec  3 23:17:33 2001
@@ -160,7 +160,7 @@
  * only drive the low 24-bits during PCI bus mastering, then
  * you would pass 0x00ffffff as the mask to this function.
  */
-static inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
+static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
 {
 	return 1;
 }
diff -urN linux-2.4.13-pre1/include/asm-arm/scatterlist.h linux/include/asm-arm/scatterlist.h
--- linux-2.4.13-pre1/include/asm-arm/scatterlist.h	Sun Sep  3 11:19:11 2000
+++ linux/include/asm-arm/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -5,7 +5,6 @@
 
 struct scatterlist {
 	char		*address;	/* virtual address		 */
-	char		*alt_address;	/* indirect dma address, or NULL */
 	dma_addr_t	dma_address;	/* dma address			 */
 	unsigned int	length;		/* length			 */
 };
diff -urN linux-2.4.13-pre1/include/asm-i386/page.h linux/include/asm-i386/page.h
--- linux-2.4.13-pre1/include/asm-i386/page.h	Wed Oct 10 23:44:33 2001
+++ linux/include/asm-i386/page.h	Mon Dec  3 23:17:33 2001
@@ -15,7 +15,7 @@
 
 #include <asm/mmx.h>
 
-#define clear_page(page)	mmx_clear_page(page)
+#define clear_page(page)	mmx_clear_page((void *)(page))
 #define copy_page(to,from)	mmx_copy_page(to,from)
 
 #else
diff -urN linux-2.4.13-pre1/include/asm-i386/pci.h linux/include/asm-i386/pci.h
--- linux-2.4.13-pre1/include/asm-i386/pci.h	Wed Oct 10 23:45:20 2001
+++ linux/include/asm-i386/pci.h	Mon Dec  3 23:17:33 2001
@@ -34,6 +34,12 @@
 
 struct pci_dev;
 
+/* The PCI address space does equal the physical memory
+ * address space.  The networking and block device layers use
+ * this boolean for bounce buffer decisions.
+ */
+#define PCI_DMA_BUS_IS_PHYS	(1)
+
 /* Allocate and map kernel buffer using consistent mode DMA for a device.
  * hwdev should be valid struct pci_dev pointer for PCI devices,
  * NULL for PCI-like buses (ISA, EISA).
@@ -84,6 +90,27 @@
 	/* Nothing to do */
 }
 
+/*
+ * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
+ * to pci_map_single, but takes a struct page instead of a virtual address
+ */
+static inline dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
+				      unsigned long offset, size_t size, int direction)
+{
+	if (direction == PCI_DMA_NONE)
+		BUG();
+
+	return (page - mem_map) * PAGE_SIZE + offset;
+}
+
+static inline void pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
+				  size_t size, int direction)
+{
+	if (direction == PCI_DMA_NONE)
+		BUG();
+	/* Nothing to do */
+}
+
 /* Map a set of buffers described by scatterlist in streaming
  * mode for DMA.  This is the scather-gather version of the
  * above pci_map_single interface.  Here the scatter gather list
@@ -102,8 +129,26 @@
 static inline int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
 			     int nents, int direction)
 {
+	int i;
+
 	if (direction == PCI_DMA_NONE)
 		BUG();
+
+	/*
+	 * temporary 2.4 hack
+	 */
+	for (i = 0; i < nents; i++ ) {
+		if (sg[i].address && sg[i].page)
+			BUG();
+		else if (!sg[i].address && !sg[i].page)
+			BUG();
+
+		if (sg[i].address)
+			sg[i].dma_address = virt_to_bus(sg[i].address);
+		else
+			sg[i].dma_address = page_to_bus(sg[i].page) + sg[i].offset;
+	}
+
 	return nents;
 }
 
@@ -157,7 +202,7 @@
  * only drive the low 24-bits during PCI bus mastering, then
  * you would pass 0x00ffffff as the mask to this function.
  */
-static inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
+static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
 {
         /*
          * we fall back to GFP_DMA when the mask isn't all 1s,
@@ -170,13 +215,42 @@
 	return 1;
 }
 
+/* This is always fine. */
+#define pci_dac_dma_supported(pci_dev, mask)	(1)
+
+static __inline__ dma64_addr_t
+pci_dac_page_to_dma(struct pci_dev *pdev, struct page *page, unsigned long offset, int direction)
+{
+	return ((dma64_addr_t) page_to_bus(page) +
+		(dma64_addr_t) offset);
+}
+
+static __inline__ struct page *
+pci_dac_dma_to_page(struct pci_dev *pdev, dma64_addr_t dma_addr)
+{
+	unsigned long poff = (dma_addr >> PAGE_SHIFT);
+
+	return mem_map + poff;
+}
+
+static __inline__ unsigned long
+pci_dac_dma_to_offset(struct pci_dev *pdev, dma64_addr_t dma_addr)
+{
+	return (dma_addr & ~PAGE_MASK);
+}
+
+static __inline__ void
+pci_dac_dma_sync_single(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
+{
+	/* Nothing to do. */
+}
+
 /* These macros should be used after a pci_map_sg call has been done
  * to get bus addresses of each of the SG entries and their lengths.
  * You should only work with the number of sg entries pci_map_sg
- * returns, or alternatively stop on the first sg_dma_len(sg) which
- * is 0.
+ * returns.
  */
-#define sg_dma_address(sg)	(virt_to_bus((sg)->address))
+#define sg_dma_address(sg)	((sg)->dma_address)
 #define sg_dma_len(sg)		((sg)->length)
 
 /* Return the index of the PCI controller for device. */
diff -urN linux-2.4.13-pre1/include/asm-i386/scatterlist.h linux/include/asm-i386/scatterlist.h
--- linux-2.4.13-pre1/include/asm-i386/scatterlist.h	Mon Dec 30 03:01:10 1996
+++ linux/include/asm-i386/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -2,9 +2,12 @@
 #define _I386_SCATTERLIST_H
 
 struct scatterlist {
-    char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
+    char *  address;    /* Location data is to be transferred to, NULL for
+			 * highmem page */
+    struct page * page; /* Location for highmem page, if any */
+    unsigned int offset;/* for highmem, page offset */
+
+    dma_addr_t dma_address;
     unsigned int length;
 };
 
diff -urN linux-2.4.13-pre1/include/asm-i386/smp.h linux/include/asm-i386/smp.h
--- linux-2.4.13-pre1/include/asm-i386/smp.h	Thu Oct 11 00:50:24 2001
+++ linux/include/asm-i386/smp.h	Mon Dec  3 23:17:33 2001
@@ -109,7 +109,7 @@
 	return GET_APIC_ID(*(unsigned long *)(APIC_BASE+APIC_ID));
 }
 
-extern __inline int logical_smp_processor_id(void)
+static __inline int logical_smp_processor_id(void)
 {
 	/* we don't want to mark this access volatile - bad code generation */
 	return GET_APIC_LOGICAL_ID(*(unsigned long *)(APIC_BASE+APIC_LDR));
diff -urN linux-2.4.13-pre1/include/asm-i386/types.h linux/include/asm-i386/types.h
--- linux-2.4.13-pre1/include/asm-i386/types.h	Thu Jan 27 08:58:15 2000
+++ linux/include/asm-i386/types.h	Mon Dec  3 23:17:33 2001
@@ -27,6 +27,8 @@
  */
 #ifdef __KERNEL__
 
+#include <linux/config.h>
+
 typedef signed char s8;
 typedef unsigned char u8;
 
@@ -41,9 +43,14 @@
 
 #define BITS_PER_LONG 32
 
-/* Dma addresses are 32-bits wide.  */
+/* DMA addresses come in generic and 64-bit flavours.  */
 
+#ifdef CONFIG_HIGHMEM
+typedef u64 dma_addr_t;
+#else
 typedef u32 dma_addr_t;
+#endif
+typedef u64 dma64_addr_t;
 
 #endif /* __KERNEL__ */
 
diff -urN linux-2.4.13-pre1/include/asm-ia64/pci.h linux/include/asm-ia64/pci.h
--- linux-2.4.13-pre1/include/asm-ia64/pci.h	Wed May 16 10:31:27 2001
+++ linux/include/asm-ia64/pci.h	Mon Dec  3 23:17:33 2001
@@ -52,7 +52,7 @@
  * you would pass 0x00ffffff as the mask to this function.
  */
 static inline int
-pci_dma_supported (struct pci_dev *hwdev, dma_addr_t mask)
+pci_dma_supported (struct pci_dev *hwdev, u64 mask)
 {
 	return 1;
 }
diff -urN linux-2.4.13-pre1/include/asm-ia64/scatterlist.h linux/include/asm-ia64/scatterlist.h
--- linux-2.4.13-pre1/include/asm-ia64/scatterlist.h	Fri Aug 11 19:09:06 2000
+++ linux/include/asm-ia64/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -8,11 +8,6 @@
 
 struct scatterlist {
 	char *address;		/* location data is to be transferred to */
-	/*
-	 * Location of actual buffer if ADDRESS points to a DMA
-	 * indirection buffer, NULL otherwise:
-	 */
-	char *alt_address;
 	char *orig_address;	/* Save away the original buffer address (used by pci-dma.c) */
 	unsigned int length;	/* buffer length */
 };
diff -urN linux-2.4.13-pre1/include/asm-m68k/scatterlist.h linux/include/asm-m68k/scatterlist.h
--- linux-2.4.13-pre1/include/asm-m68k/scatterlist.h	Tue May 11 09:57:14 1999
+++ linux/include/asm-m68k/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -3,8 +3,6 @@
 
 struct scatterlist {
     char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
     unsigned int length;
     unsigned long dvma_address;
 };
diff -urN linux-2.4.13-pre1/include/asm-mips/pci.h linux/include/asm-mips/pci.h
--- linux-2.4.13-pre1/include/asm-mips/pci.h	Sun Sep  9 10:43:01 2001
+++ linux/include/asm-mips/pci.h	Mon Dec  3 23:17:33 2001
@@ -215,7 +215,7 @@
  * only drive the low 24-bits during PCI bus mastering, then
  * you would pass 0x00ffffff as the mask to this function.
  */
-extern inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
+extern inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
 {
 	/*
 	 * we fall back to GFP_DMA when the mask isn't all 1s,
diff -urN linux-2.4.13-pre1/include/asm-mips/scatterlist.h linux/include/asm-mips/scatterlist.h
--- linux-2.4.13-pre1/include/asm-mips/scatterlist.h	Tue Dec 16 12:46:12 1997
+++ linux/include/asm-mips/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -3,8 +3,6 @@
 
 struct scatterlist {
     char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
     unsigned int length;
     
     __u32 dvma_address;
diff -urN linux-2.4.13-pre1/include/asm-mips64/pci.h linux/include/asm-mips64/pci.h
--- linux-2.4.13-pre1/include/asm-mips64/pci.h	Sun Sep  9 10:43:02 2001
+++ linux/include/asm-mips64/pci.h	Mon Dec  3 23:17:33 2001
@@ -220,7 +220,7 @@
 }
 #endif /* CONFIG_MAPPED_PCI_IO  */
 
-static inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
+static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
 {
 	/*
 	 * we fall back to GFP_DMA when the mask isn't all 1s,
diff -urN linux-2.4.13-pre1/include/asm-mips64/scatterlist.h linux/include/asm-mips64/scatterlist.h
--- linux-2.4.13-pre1/include/asm-mips64/scatterlist.h	Thu Feb 24 22:53:35 2000
+++ linux/include/asm-mips64/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -3,8 +3,6 @@
 
 struct scatterlist {
     char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
     unsigned int length;
     
     __u32 dvma_address;
diff -urN linux-2.4.13-pre1/include/asm-parisc/pci.h linux/include/asm-parisc/pci.h
--- linux-2.4.13-pre1/include/asm-parisc/pci.h	Wed May 16 10:31:27 2001
+++ linux/include/asm-parisc/pci.h	Mon Dec  3 23:17:33 2001
@@ -113,7 +113,7 @@
 ** See Documentation/DMA-mapping.txt
 */
 struct pci_dma_ops {
-	int  (*dma_supported)(struct pci_dev *dev, dma_addr_t mask);
+	int  (*dma_supported)(struct pci_dev *dev, u64 mask);
 	void *(*alloc_consistent)(struct pci_dev *dev, size_t size, dma_addr_t *iova);
 	void (*free_consistent)(struct pci_dev *dev, size_t size, void *vaddr, dma_addr_t iova);
 	dma_addr_t (*map_single)(struct pci_dev *dev, void *addr, size_t size, int direction);
diff -urN linux-2.4.13-pre1/include/asm-parisc/scatterlist.h linux/include/asm-parisc/scatterlist.h
--- linux-2.4.13-pre1/include/asm-parisc/scatterlist.h	Tue Dec  5 12:29:39 2000
+++ linux/include/asm-parisc/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -3,8 +3,6 @@
 
 struct scatterlist {
 	char *  address;    /* Location data is to be transferred to */
-	char * alt_address; /* Location of actual if address is a 
-			     * dma indirect buffer.  NULL otherwise */
 	unsigned int length;
 
 	/* an IOVA can be 64-bits on some PA-Risc platforms. */
diff -urN linux-2.4.13-pre1/include/asm-ppc/pci.h linux/include/asm-ppc/pci.h
--- linux-2.4.13-pre1/include/asm-ppc/pci.h	Mon May 21 15:02:06 2001
+++ linux/include/asm-ppc/pci.h	Mon Dec  3 23:17:33 2001
@@ -108,7 +108,7 @@
  * only drive the low 24-bits during PCI bus mastering, then
  * you would pass 0x00ffffff as the mask to this function.
  */
-extern inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
+extern inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
 {
 	return 1;
 }
diff -urN linux-2.4.13-pre1/include/asm-ppc/scatterlist.h linux/include/asm-ppc/scatterlist.h
--- linux-2.4.13-pre1/include/asm-ppc/scatterlist.h	Mon May 21 15:02:06 2001
+++ linux/include/asm-ppc/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -9,8 +9,6 @@
 
 struct scatterlist {
     char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
     unsigned int length;
 };
 
diff -urN linux-2.4.13-pre1/include/asm-s390/scatterlist.h linux/include/asm-s390/scatterlist.h
--- linux-2.4.13-pre1/include/asm-s390/scatterlist.h	Tue Feb 13 14:13:44 2001
+++ linux/include/asm-s390/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -3,8 +3,6 @@
 
 struct scatterlist {
     char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
     unsigned int length;
 };
 
diff -urN linux-2.4.13-pre1/include/asm-s390x/scatterlist.h linux/include/asm-s390x/scatterlist.h
--- linux-2.4.13-pre1/include/asm-s390x/scatterlist.h	Tue Feb 13 14:13:44 2001
+++ linux/include/asm-s390x/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -3,8 +3,6 @@
 
 struct scatterlist {
     char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
     unsigned int length;
 };
 
diff -urN linux-2.4.13-pre1/include/asm-sh/pci.h linux/include/asm-sh/pci.h
--- linux-2.4.13-pre1/include/asm-sh/pci.h	Sat Sep  8 12:29:09 2001
+++ linux/include/asm-sh/pci.h	Mon Dec  3 23:17:33 2001
@@ -191,7 +191,7 @@
  * only drive the low 24-bits during PCI bus mastering, then
  * you would pass 0x00ffffff as the mask to this function.
  */
-static inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
+static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
 {
 	return 1;
 }
diff -urN linux-2.4.13-pre1/include/asm-sh/scatterlist.h linux/include/asm-sh/scatterlist.h
--- linux-2.4.13-pre1/include/asm-sh/scatterlist.h	Sun Mar  5 09:33:55 2000
+++ linux/include/asm-sh/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -3,8 +3,6 @@
 
 struct scatterlist {
     char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
     unsigned int length;
 };
 
diff -urN linux-2.4.13-pre1/include/asm-sparc/pci.h linux/include/asm-sparc/pci.h
--- linux-2.4.13-pre1/include/asm-sparc/pci.h	Wed May 16 10:31:27 2001
+++ linux/include/asm-sparc/pci.h	Mon Dec  3 23:17:33 2001
@@ -108,7 +108,7 @@
  * only drive the low 24-bits during PCI bus mastering, then
  * you would pass 0x00ffffff as the mask to this function.
  */
-extern inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
+extern inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
 {
 	return 1;
 }
diff -urN linux-2.4.13-pre1/include/asm-sparc/scatterlist.h linux/include/asm-sparc/scatterlist.h
--- linux-2.4.13-pre1/include/asm-sparc/scatterlist.h	Mon Jan 31 23:37:19 2000
+++ linux/include/asm-sparc/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: scatterlist.h,v 1.5 2000/01/29 16:27:07 jj Exp $ */
+/* $Id: scatterlist.h,v 1.6 2001/10/09 02:24:35 davem Exp $ */
 #ifndef _SPARC_SCATTERLIST_H
 #define _SPARC_SCATTERLIST_H
 
@@ -6,8 +6,6 @@
 
 struct scatterlist {
     char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
     unsigned int length;
 
     __u32 dvma_address; /* A place to hang host-specific addresses at. */
diff -urN linux-2.4.13-pre1/include/asm-sparc64/pci.h linux/include/asm-sparc64/pci.h
--- linux-2.4.13-pre1/include/asm-sparc64/pci.h	Wed May 16 10:31:27 2001
+++ linux/include/asm-sparc64/pci.h	Mon Dec  3 23:17:33 2001
@@ -28,6 +28,12 @@
 /* Dynamic DMA mapping stuff.
  */
 
+/* The PCI address space does not equal the physical memory
+ * address space.  The networking and block device layers use
+ * this boolean for bounce buffer decisions.
+ */
+#define PCI_DMA_BUS_IS_PHYS	(0)
+
 #include <asm/scatterlist.h>
 
 struct pci_dev;
@@ -64,6 +70,11 @@
  */
 extern void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction);
 
+/* No highmem on sparc64, plus we have an IOMMU, so mapping pages is easy. */
+#define pci_map_page(dev, page, off, size, dir) \
+	pci_map_single(dev, (page_address(page) + (off)), size, dir)
+#define pci_unmap_page(dev,addr,sz,dir) pci_unmap_single(dev,addr,sz,dir)
+
 /* Map a set of buffers described by scatterlist in streaming
  * mode for DMA.  This is the scather-gather version of the
  * above pci_map_single interface.  Here the scatter gather list
@@ -79,13 +90,15 @@
  * Device ownership issues as mentioned above for pci_map_single are
  * the same here.
  */
-extern int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction);
+extern int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+		      int nents, int direction);
 
 /* Unmap a set of streaming mode DMA translations.
  * Again, cpu read rules concerning calls here are the same as for
  * pci_unmap_single() above.
  */
-extern void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nhwents, int direction);
+extern void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+			 int nhwents, int direction);
 
 /* Make physical memory consistent for a single
  * streaming mode DMA translation after a transfer.
@@ -96,7 +109,8 @@
  * next point you give the PCI dma address back to the card, the
  * device again owns the buffer.
  */
-extern void pci_dma_sync_single(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction);
+extern void pci_dma_sync_single(struct pci_dev *hwdev, dma_addr_t dma_handle,
+				size_t size, int direction);
 
 /* Make physical memory consistent for a set of streaming
  * mode DMA translations after a transfer.
@@ -111,7 +125,51 @@
  * only drive the low 24-bits during PCI bus mastering, then
  * you would pass 0x00ffffff as the mask to this function.
  */
-extern int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask);
+extern int pci_dma_supported(struct pci_dev *hwdev, u64 mask);
+
+/* PCI IOMMU mapping bypass support. */
+
+/* PCI 64-bit addressing works for all slots on all controller
+ * types on sparc64.  However, it requires that the device
+ * can drive enough of the 64 bits.
+ */
+#define PCI64_REQUIRED_MASK	(~(dma64_addr_t)0)
+#define PCI64_ADDR_BASE		0xfffc000000000000
+
+/* Usage of the pci_dac_foo interfaces is only valid if this
+ * test passes.
+ */
+#define pci_dac_dma_supported(pci_dev, mask) \
+	((((mask) & PCI64_REQUIRED_MASK) == PCI64_REQUIRED_MASK) ? 1 : 0)
+
+static __inline__ dma64_addr_t
+pci_dac_page_to_dma(struct pci_dev *pdev, struct page *page, unsigned long offset, int direction)
+{
+	return (PCI64_ADDR_BASE +
+		__pa(page_address(page)) + offset);
+}
+
+static __inline__ struct page *
+pci_dac_dma_to_page(struct pci_dev *pdev, dma64_addr_t dma_addr)
+{
+	unsigned long paddr = (dma_addr & PAGE_MASK) - PCI64_ADDR_BASE;
+
+	return virt_to_page(__va(paddr));
+}
+
+static __inline__ unsigned long
+pci_dac_dma_to_offset(struct pci_dev *pdev, dma64_addr_t dma_addr)
+{
+	return (dma_addr & ~PAGE_MASK);
+}
+
+static __inline__ void
+pci_dac_dma_sync_single(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
+{
+	/* DAC cycle addressing does not make use of the
+	 * PCI controller's streaming cache, so nothing to do.
+	 */
+}
 
 /* Return the index of the PCI controller for device PDEV. */
 
diff -urN linux-2.4.13-pre1/include/asm-sparc64/scatterlist.h linux/include/asm-sparc64/scatterlist.h
--- linux-2.4.13-pre1/include/asm-sparc64/scatterlist.h	Mon Dec 20 22:05:52 1999
+++ linux/include/asm-sparc64/scatterlist.h	Mon Dec  3 23:17:33 2001
@@ -1,21 +1,27 @@
-/* $Id: scatterlist.h,v 1.9 1999/12/17 12:32:15 jj Exp $ */
+/* $Id: scatterlist.h,v 1.10 2001/10/09 02:24:35 davem Exp $ */
 #ifndef _SPARC64_SCATTERLIST_H
 #define _SPARC64_SCATTERLIST_H
 
 #include <asm/page.h>
 
 struct scatterlist {
-    char *  address;    /* Location data is to be transferred to */
-    char * alt_address; /* Location of actual if address is a 
-			 * dma indirect buffer.  NULL otherwise */
-    unsigned int length;
+	/* This will disappear in 2.5.x */
+	char *address;
 
-    __u32 dvma_address; /* A place to hang host-specific addresses at. */
-    __u32 dvma_length;
+	/* These two are only valid if ADDRESS member of this
+	 * struct is NULL.
+	 */
+	struct page *page;
+	unsigned int offset;
+
+	unsigned int length;
+
+	dma_addr_t dma_address;
+	__u32 dma_length;
 };
 
-#define sg_dma_address(sg) ((sg)->dvma_address)
-#define sg_dma_len(sg)     ((sg)->dvma_length)
+#define sg_dma_address(sg)	((sg)->dma_address)
+#define sg_dma_len(sg)     	((sg)->dma_length)
 
 #define ISA_DMA_THRESHOLD	(~0UL)
 
diff -urN linux-2.4.13-pre1/include/asm-sparc64/types.h linux/include/asm-sparc64/types.h
--- linux-2.4.13-pre1/include/asm-sparc64/types.h	Mon Jan 31 23:37:19 2000
+++ linux/include/asm-sparc64/types.h	Mon Dec  3 23:17:33 2001
@@ -1,4 +1,4 @@
-/* $Id: types.h,v 1.3 2000/01/28 13:43:15 jj Exp $ */
+/* $Id: types.h,v 1.4 2001/10/09 02:24:35 davem Exp $ */
 #ifndef _SPARC64_TYPES_H
 #define _SPARC64_TYPES_H
 
@@ -45,9 +45,10 @@
 
 #define BITS_PER_LONG 64
 
-/* Dma addresses are 32-bits wide for now.  */
+/* Dma addresses come in generic and 64-bit flavours.  */
 
 typedef u32 dma_addr_t;
+typedef u64 dma64_addr_t;
 
 #endif /* __KERNEL__ */
 
diff -urN linux-2.4.13-pre1/include/linux/msdos_fs.h linux/include/linux/msdos_fs.h
--- linux-2.4.13-pre1/include/linux/msdos_fs.h	Thu May 24 15:36:34 2001
+++ linux/include/linux/msdos_fs.h	Mon Dec  3 23:17:33 2001
@@ -92,6 +92,15 @@
 #define	VFAT_IOCTL_READDIR_BOTH		_IOR('r', 1, struct dirent [2])
 #define	VFAT_IOCTL_READDIR_SHORT	_IOR('r', 2, struct dirent [2])
 
+/* 
+ * vfat shortname flags
+ */
+#define VFAT_SFN_DISPLAY_LOWER	0x0001 /* convert to lowercase for display */
+#define VFAT_SFN_DISPLAY_WIN95	0x0002 /* emulate win95 rule for display */
+#define VFAT_SFN_DISPLAY_WINNT	0x0004 /* emulate winnt rule for display */
+#define VFAT_SFN_CREATE_WIN95	0x0100 /* emulate win95 rule for create */
+#define VFAT_SFN_CREATE_WINNT	0x0200 /* emulate winnt rule for create */
+
 /*
  * Conversion from and to little-endian byte order. (no-op on i386/i486)
  *
@@ -132,7 +141,7 @@
 };
 
 struct fat_boot_fsinfo {
-	__u32   signature1;	/* 0x61417272L */
+	__u32   signature1;	/* 0x41615252L */
 	__u32   reserved1[120];	/* Nothing as far as I can tell */
 	__u32   signature2;	/* 0x61417272L */
 	__u32   free_clusters;	/* Free cluster count.  -1 if unknown */
@@ -188,6 +197,8 @@
 
 #ifdef __KERNEL__
 
+#include <linux/nls.h>
+
 struct fat_cache {
 	kdev_t device; /* device number. 0 means unused. */
 	int start_cluster; /* first cluster of the chain. */
@@ -196,21 +207,111 @@
 	struct fat_cache *next; /* next cache entry */
 };
 
-/* misc.c */
-extern int fat_is_binary(char conversion,char *extension);
+static inline void fat16_towchar(wchar_t *dst, const __u8 *src, size_t len)
+{
+#ifdef __BIG_ENDIAN
+	while (len--) {
+		*dst++ = src[0] | (src[1] << 8);
+		src += 2;
+	}
+#else
+	memcpy(dst, src, len * 2);
+#endif
+}
+
+static inline void fatwchar_to16(__u8 *dst, const wchar_t *src, size_t len)
+{
+#ifdef __BIG_ENDIAN
+	while (len--) {
+		dst[0] = *src & 0x00FF;
+		dst[1] = (*src & 0xFF00) >> 8;
+		dst += 2;
+		src++;
+	}
+#else
+	memcpy(dst, src, len * 2);
+#endif
+}
+
+/* fat/buffer.c */
+extern struct buffer_head *fat_bread(struct super_block *sb, int block);
+extern struct buffer_head *fat_getblk(struct super_block *sb, int block);
+extern void fat_brelse(struct super_block *sb, struct buffer_head *bh);
+extern void fat_mark_buffer_dirty(struct super_block *sb, struct buffer_head *bh);
+extern void fat_set_uptodate(struct super_block *sb, struct buffer_head *bh,
+			     int val);
+extern int fat_is_uptodate(struct super_block *sb, struct buffer_head *bh);
+extern void fat_ll_rw_block(struct super_block *sb, int opr, int nbreq,
+			    struct buffer_head *bh[32]);
+
+/* fat/cache.c */
+extern int fat_access(struct super_block *sb, int nr, int new_value);
+extern int fat_bmap(struct inode *inode, int sector);
+extern void fat_cache_init(void);
+extern void fat_cache_lookup(struct inode *inode, int cluster, int *f_clu,
+			     int *d_clu);
+extern void fat_cache_add(struct inode *inode, int f_clu, int d_clu);
+extern void fat_cache_inval_inode(struct inode *inode);
+extern void fat_cache_inval_dev(kdev_t device);
+extern int fat_get_cluster(struct inode *inode, int cluster);
+extern int fat_free(struct inode *inode, int skip);
+
+/* fat/dir.c */
+extern struct file_operations fat_dir_operations;
+extern int fat_search_long(struct inode *inode, const char *name, int name_len,
+			   int anycase, loff_t *spos, loff_t *lpos);
+extern int fat_readdir(struct file *filp, void *dirent, filldir_t filldir);
+extern int fat_dir_ioctl(struct inode * inode, struct file * filp,
+			 unsigned int cmd, unsigned long arg);
+extern int fat_dir_empty(struct inode *dir);
+extern int fat_add_entries(struct inode *dir, int slots, struct buffer_head **bh,
+			   struct msdos_dir_entry **de, int *ino);
+extern int fat_new_dir(struct inode *dir, struct inode *parent, int is_vfat);
+
+/* fat/file.c */
+extern struct file_operations fat_file_operations;
+extern struct inode_operations fat_file_inode_operations;
+extern ssize_t fat_file_read(struct file *filp, char *buf, size_t count,
+			     loff_t *ppos);
+extern int fat_get_block(struct inode *inode, long iblock,
+			 struct buffer_head *bh_result, int create);
+extern ssize_t fat_file_write(struct file *filp, const char *buf, size_t count,
+			      loff_t *ppos);
+extern void fat_truncate(struct inode *inode);
+
+/* fat/inode.c */
+extern void fat_hash_init(void);
+extern void fat_attach(struct inode *inode, int i_pos);
+extern void fat_detach(struct inode *inode);
+extern struct inode *fat_iget(struct super_block *sb, int i_pos);
+extern struct inode *fat_build_inode(struct super_block *sb,
+				     struct msdos_dir_entry *de, int ino, int *res);
+extern void fat_delete_inode(struct inode *inode);
+extern void fat_clear_inode(struct inode *inode);
+extern void fat_put_super(struct super_block *sb);
+extern struct super_block *
+fat_read_super(struct super_block *sb, void *data, int silent,
+	       struct inode_operations *fs_dir_inode_ops);
+extern int fat_statfs(struct super_block *sb, struct statfs *buf);
+extern void fat_write_inode(struct inode *inode, int wait);
+extern int fat_notify_change(struct dentry * dentry, struct iattr * attr);
+
+/* fat/misc.c */
+extern void fat_fs_panic(struct super_block *s, const char *msg);
+extern int fat_is_binary(char conversion, char *extension);
 extern void lock_fat(struct super_block *sb);
 extern void unlock_fat(struct super_block *sb);
+extern void fat_clusters_flush(struct super_block *sb);
 extern int fat_add_cluster(struct inode *inode);
 extern struct buffer_head *fat_extend_dir(struct inode *inode);
-extern int date_dos2unix(__u16 time, __u16 date);
-extern void fat_fs_panic(struct super_block *s,const char *msg);
-extern void fat_lock_creation(void);
-extern void fat_unlock_creation(void);
-extern void fat_date_unix2dos(int unix_date,__u16 *time, __u16 *date);
-extern int fat__get_entry(struct inode *dir,loff_t *pos,struct buffer_head **bh,
-			 struct msdos_dir_entry **de,int *ino);
-static __inline__ int fat_get_entry(struct inode *dir,loff_t *pos,
-		struct buffer_head **bh,struct msdos_dir_entry **de,int *ino)
+extern int date_dos2unix(unsigned short time, unsigned short date);
+extern void fat_date_unix2dos(int unix_date, unsigned short *time,
+			      unsigned short *date);
+extern int fat__get_entry(struct inode *dir, loff_t *pos, struct buffer_head **bh,
+			  struct msdos_dir_entry **de, int *ino);
+static __inline__ int fat_get_entry(struct inode *dir, loff_t *pos,
+				    struct buffer_head **bh,
+				    struct msdos_dir_entry **de, int *ino)
 {
 	/* Fast stuff first */
 	if (*bh && *de &&
@@ -222,103 +323,33 @@
 	}
 	return fat__get_entry(dir,pos,bh,de,ino);
 }
-extern int fat_scan(struct inode *dir,const char *name,struct buffer_head **res_bh,
-		    struct msdos_dir_entry **res_de,int *ino);
-extern int fat_parent_ino(struct inode *dir,int locked);
 extern int fat_subdirs(struct inode *dir);
-void fat_clusters_flush(struct super_block *sb);
-
-/* fat.c */
-extern int fat_access(struct super_block *sb,int nr,int new_value);
-extern int fat_free(struct inode *inode,int skip);
-void fat_cache_inval_inode(struct inode *inode);
-void fat_cache_inval_dev(kdev_t device);
-extern void fat_cache_init(void);
-void fat_cache_lookup(struct inode *inode,int cluster,int *f_clu,int *d_clu);
-void fat_cache_add(struct inode *inode,int f_clu,int d_clu);
-int fat_get_cluster(struct inode *inode,int cluster);
+extern int fat_scan(struct inode *dir, const char *name,
+		    struct buffer_head **res_bh,
+		    struct msdos_dir_entry **res_de, int *ino);
 
-/* inode.c */
-extern void fat_hash_init(void);
-extern int fat_bmap(struct inode *inode,int block);
-extern int fat_get_block(struct inode *, long, struct buffer_head *, int);
-extern int fat_notify_change(struct dentry *, struct iattr *);
-extern void fat_clear_inode(struct inode *inode);
-extern void fat_delete_inode(struct inode *inode);
-extern void fat_put_super(struct super_block *sb);
-extern void fat_attach(struct inode *inode, int ino);
-extern void fat_detach(struct inode *inode);
-extern struct inode *fat_iget(struct super_block*,int);
-extern struct inode *fat_build_inode(struct super_block*,struct msdos_dir_entry*,int,int*);
-extern struct super_block *fat_read_super(struct super_block *s, void *data, int silent, struct inode_operations *dir_ops);
+/* msdos/namei.c  - these are for Umsdos */
 extern void msdos_put_super(struct super_block *sb);
-extern int fat_statfs(struct super_block *sb,struct statfs *buf);
-extern void fat_write_inode(struct inode *inode, int);
-
-/* dir.c */
-extern struct file_operations fat_dir_operations;
-extern int fat_search_long(struct inode *dir, const char *name, int len,
-			   int anycase, loff_t *spos, loff_t *lpos);
-extern int fat_readdir(struct file *filp,
-		       void *dirent, filldir_t);
-extern int fat_dir_ioctl(struct inode * inode, struct file * filp,
-			 unsigned int cmd, unsigned long arg);
-int fat_add_entries(struct inode *dir,int slots, struct buffer_head **bh,
-		  struct msdos_dir_entry **de, int *ino);
-int fat_dir_empty(struct inode *dir);
-int fat_new_dir(struct inode *inode, struct inode *parent, int is_vfat);
-
-/* file.c */
-extern struct inode_operations fat_file_inode_operations;
-extern struct inode_operations fat_file_inode_operations_1024;
-extern struct inode_operations fat_file_inode_operations_readpage;
-extern struct file_operations fat_file_operations;
-extern ssize_t fat_file_read(struct file *, char *, size_t, loff_t *);
-extern ssize_t fat_file_write(struct file *, const char *, size_t, loff_t *);
-extern void fat_truncate(struct inode *inode);
-
-/* msdos.c */
-extern struct super_block *msdos_read_super(struct super_block *sb,void *data, int silent);
-
-/* msdos.c - these are for Umsdos */
-extern void msdos_read_inode(struct inode *inode);
-extern struct dentry *msdos_lookup(struct inode *dir,struct dentry *);
-extern int msdos_create(struct inode *dir,struct dentry *dentry,int mode);
-extern int msdos_rmdir(struct inode *dir,struct dentry *dentry);
-extern int msdos_mkdir(struct inode *dir,struct dentry *dentry,int mode);
-extern int msdos_unlink(struct inode *dir,struct dentry *dentry);
-extern int msdos_rename(struct inode *old_dir,struct dentry *old_dentry,
-			struct inode *new_dir,struct dentry *new_dentry);
-
-/* nls.c */
-extern struct fat_nls_table *fat_load_nls(int codepage);
-
-/* tables.c */
-extern unsigned char fat_uni2esc[];
-extern unsigned char fat_esc2uni[];
-
-/* fatfs_syms.c */
-extern void cleanup_fat_fs(void);
-
-/* nls.c */
-extern int fat_register_nls(struct fat_nls_table * fmt);
-extern int fat_unregister_nls(struct fat_nls_table * fmt);
-extern struct fat_nls_table *fat_find_nls(int codepage);
-extern struct fat_nls_table *fat_load_nls(int codepage);
-extern void fat_unload_nls(int codepage);
-extern int init_fat_nls(void);
+extern struct dentry *msdos_lookup(struct inode *dir, struct dentry *);
+extern int msdos_create(struct inode *dir, struct dentry *dentry, int mode);
+extern int msdos_rmdir(struct inode *dir, struct dentry *dentry);
+extern int msdos_mkdir(struct inode *dir, struct dentry *dentry, int mode);
+extern int msdos_unlink(struct inode *dir, struct dentry *dentry);
+extern int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
+			struct inode *new_dir, struct dentry *new_dentry);
+extern struct super_block *msdos_read_super(struct super_block *sb,
+					    void *data, int silent);
 
 /* vfat/namei.c - these are for dmsdos */
-extern int vfat_create(struct inode *dir,struct dentry *dentry,int mode);
-extern int vfat_unlink(struct inode *dir,struct dentry *dentry);
-extern int vfat_mkdir(struct inode *dir,struct dentry *dentry,int mode);
-extern int vfat_rmdir(struct inode *dir,struct dentry *dentry);
-extern int vfat_rename(struct inode *old_dir,struct dentry *old_dentry,
-		       struct inode *new_dir,struct dentry *new_dentry);
-extern struct super_block *vfat_read_super(struct super_block *sb,void *data,
+extern struct dentry *vfat_lookup(struct inode *dir, struct dentry *);
+extern int vfat_create(struct inode *dir, struct dentry *dentry, int mode);
+extern int vfat_rmdir(struct inode *dir, struct dentry *dentry);
+extern int vfat_unlink(struct inode *dir, struct dentry *dentry);
+extern int vfat_mkdir(struct inode *dir, struct dentry *dentry, int mode);
+extern int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
+		       struct inode *new_dir, struct dentry *new_dentry);
+extern struct super_block *vfat_read_super(struct super_block *sb, void *data,
 					   int silent);
-extern void vfat_read_inode(struct inode *inode);
-extern struct dentry *vfat_lookup(struct inode *dir,struct dentry *);
 
 /* vfat/vfatfs_syms.c */
 extern struct file_system_type vfat_fs_type;
diff -urN linux-2.4.13-pre1/include/linux/msdos_fs_sb.h linux/include/linux/msdos_fs_sb.h
--- linux-2.4.13-pre1/include/linux/msdos_fs_sb.h	Thu May 24 15:36:34 2001
+++ linux/include/linux/msdos_fs_sb.h	Mon Dec  3 23:17:33 2001
@@ -12,6 +12,7 @@
 	unsigned short fs_umask;
 	unsigned short codepage;  /* Codepage for shortname conversions */
 	char *iocharset;          /* Charset used for filename input/display */
+	unsigned short shortname; /* flags for shortname display/create rule */
 	unsigned char name_check; /* r = relaxed, n = normal, s = strict */
 	unsigned char conversion; /* b = binary, t = text, a = auto */
 	unsigned quiet:1,         /* set = fake successful chmods and chowns */
@@ -28,11 +29,6 @@
 		 nocase:1;	  /* Does this need case conversion? 0=need case conversion*/
 };
 
-struct vfat_unicode {
-	unsigned char uni1;
-	unsigned char uni2;
-};
-
 struct msdos_sb_info {
 	unsigned short cluster_size; /* sectors/cluster */
 	unsigned short cluster_bits; /* sectors/cluster */
@@ -45,7 +41,6 @@
 	unsigned long clusters;      /* number of clusters */
 	unsigned long root_cluster;  /* first cluster of the root directory */
 	unsigned long fsinfo_sector; /* FAT32 fsinfo offset from start of disk */
-	wait_queue_head_t fat_wait;
 	struct semaphore fat_lock;
 	int prev_free;               /* previously returned free cluster number */
 	int free_clusters;           /* -1 if undefined */
diff -urN linux-2.4.13-pre1/include/linux/pci.h linux/include/linux/pci.h
--- linux-2.4.13-pre1/include/linux/pci.h	Wed Oct 10 23:45:20 2001
+++ linux/include/linux/pci.h	Mon Dec  3 23:17:33 2001
@@ -353,7 +353,7 @@
 
 	struct pci_driver *driver;	/* which driver has allocated this device */
 	void		*driver_data;	/* data private to the driver */
-	dma_addr_t	dma_mask;	/* Mask of the bits of bus address this
+	u64		dma_mask;	/* Mask of the bits of bus address this
 					   device implements.  Normally this is
 					   0xffffffff.  You only need to change
 					   this if your device has broken DMA
@@ -559,7 +559,8 @@
 int pci_enable_device(struct pci_dev *dev);
 void pci_disable_device(struct pci_dev *dev);
 void pci_set_master(struct pci_dev *dev);
-int pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask);
+int pci_set_dma_mask(struct pci_dev *dev, u64 mask);
+int pci_dac_set_dma_mask(struct pci_dev *dev, u64 mask);
 int pci_assign_resource(struct pci_dev *dev, int i);
 
 /* Power management related routines */
@@ -641,7 +642,8 @@
 static inline int pci_enable_device(struct pci_dev *dev) { return -EIO; }
 static inline void pci_disable_device(struct pci_dev *dev) { }
 static inline int pci_module_init(struct pci_driver *drv) { return -ENODEV; }
-static inline int pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask) { return -EIO; }
+static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask) { return -EIO; }
+static inline int pci_dac_set_dma_mask(struct pci_dev *dev, u64 mask) { return -EIO; }
 static inline int pci_assign_resource(struct pci_dev *dev, int i) { return -EBUSY;}
 static inline int pci_register_driver(struct pci_driver *drv) { return 0;}
 static inline void pci_unregister_driver(struct pci_driver *drv) { }
diff -urN linux-2.4.13-pre1/include/linux/reiserfs_fs.h linux/include/linux/reiserfs_fs.h
--- linux-2.4.13-pre1/include/linux/reiserfs_fs.h	Mon Oct  8 11:52:58 2001
+++ linux/include/linux/reiserfs_fs.h	Mon Dec  3 23:17:33 2001
@@ -12,11 +12,12 @@
 #ifndef _LINUX_REISER_FS_H
 #define _LINUX_REISER_FS_H
 
-
 #include <linux/types.h>
 #ifdef __KERNEL__
 #include <linux/slab.h>
 #include <linux/tqueue.h>
+#include <asm/unaligned.h>
+#include <linux/bitops.h>
 #include <asm/hardirq.h>
 #endif
 
@@ -293,11 +294,57 @@
 } __attribute__ ((__packed__));
 
 struct offset_v2 {
-    __u64 k_offset:60;
-    __u64 k_type: 4;
+#ifdef __LITTLE_ENDIAN
+	    /* little endian version */
+	    __u64 k_offset:60;
+	    __u64 k_type: 4;
+#else
+	    /* big endian version */
+	    __u64 k_type: 4;
+	    __u64 k_offset:60;
+#endif
 } __attribute__ ((__packed__));
 
+#ifndef __LITTLE_ENDIAN
+typedef union {
+    struct offset_v2 offset_v2;
+    __u64 linear;
+} __attribute__ ((__packed__)) offset_v2_esafe_overlay;
+
+static inline __u16 offset_v2_k_type( struct offset_v2 *v2 )
+{
+    offset_v2_esafe_overlay tmp = *(offset_v2_esafe_overlay *)v2;
+    tmp.linear = le64_to_cpu( tmp.linear );
+    return tmp.offset_v2.k_type;
+}
+ 
+static inline void set_offset_v2_k_type( struct offset_v2 *v2, int type )
+{
+    offset_v2_esafe_overlay *tmp = (offset_v2_esafe_overlay *)v2;
+    tmp->linear = le64_to_cpu(tmp->linear);
+    tmp->offset_v2.k_type = type;
+    tmp->linear = le64_to_cpu(tmp->linear);
+}
+ 
+static inline loff_t offset_v2_k_offset( struct offset_v2 *v2 )
+{
+    offset_v2_esafe_overlay tmp = *(offset_v2_esafe_overlay *)v2;
+    tmp.linear = le64_to_cpu( tmp.linear );
+    return tmp.offset_v2.k_offset;
+}
 
+static inline void set_offset_v2_k_offset( struct offset_v2 *v2, loff_t offset ){
+    offset_v2_esafe_overlay *tmp = (offset_v2_esafe_overlay *)v2;
+    tmp->linear = le64_to_cpu(tmp->linear);
+    tmp->offset_v2.k_offset = offset;
+    tmp->linear = le64_to_cpu(tmp->linear);
+}
+#else
+# define offset_v2_k_type(v2)           ((v2)->k_type)
+# define set_offset_v2_k_type(v2,val)   (offset_v2_k_type(v2) = (val))
+# define offset_v2_k_offset(v2)         ((v2)->k_offset)
+# define set_offset_v2_k_offset(v2,val) (offset_v2_k_offset(v2) = (val))
+#endif
 
 /* Key of an item determines its location in the S+tree, and
    is composed of 4 components */
@@ -387,8 +434,8 @@
     __u16 ih_entry_count; /* Iff this is a directory item, this field equals the number of directory
 				      entries in the directory item. */
   } __attribute__ ((__packed__)) u;
-  __u16 ih_item_len;           /* total size of the item body                  */
-  __u16 ih_item_location;      /* an offset to the item body within the block  */
+  __u16 ih_item_len;           /* total size of the item body */
+  __u16 ih_item_location;      /* an offset to the item body within the block */
 				/* I thought we were going to use this
                                    for having lots of item types? Why
                                    don't you use this for item type
@@ -423,11 +470,19 @@
 
 
 // FIXME: now would that work for other than i386 archs
-#define unreachable_item(ih) (ih->ih_version & (1 << 15))
+#define unreachable_item(ih) (ih_version(ih) & (1 << 15))
 
 #define get_ih_free_space(ih) (ih_version (ih) == ITEM_VERSION_2 ? 0 : ih_free_space (ih))
 #define set_ih_free_space(ih,val) put_ih_free_space((ih), ((ih_version(ih) == ITEM_VERSION_2) ? 0 : (val)))
 
+/* these operate on indirect items, where you've got an array of ints
+** at a possibly unaligned location.  These are a noop on ia32
+** 
+** p is the array of __u32, i is the index into the array, v is the value
+** to store there.
+*/
+#define get_block_num(p, i) le32_to_cpu(get_unaligned((p) + (i)))
+#define put_block_num(p, i, v) put_unaligned(cpu_to_le32(v), (p) + (i))
 
 //
 // there are 5 item types currently
@@ -490,8 +545,9 @@
 //
 static inline loff_t le_key_k_offset (int version, struct key * key)
 {
-    return (version == ITEM_VERSION_1) ? key->u.k_offset_v1.k_offset :
-	le64_to_cpu (key->u.k_offset_v2.k_offset);
+    return (version == ITEM_VERSION_1) ?
+        le32_to_cpu( key->u.k_offset_v1.k_offset ) :
+	offset_v2_k_offset( &(key->u.k_offset_v2) );
 }
 static inline loff_t le_ih_k_offset (struct item_head * ih)
 {
@@ -501,8 +557,9 @@
 
 static inline loff_t le_key_k_type (int version, struct key * key)
 {
-    return (version == ITEM_VERSION_1) ? uniqueness2type (key->u.k_offset_v1.k_uniqueness) :
-	le16_to_cpu (key->u.k_offset_v2.k_type);
+    return (version == ITEM_VERSION_1) ?
+        uniqueness2type( le32_to_cpu( key->u.k_offset_v1.k_uniqueness)) :
+	offset_v2_k_type( &(key->u.k_offset_v2) );
 }
 static inline loff_t le_ih_k_type (struct item_head * ih)
 {
@@ -512,8 +569,9 @@
 
 static inline void set_le_key_k_offset (int version, struct key * key, loff_t offset)
 {
-    (version == ITEM_VERSION_1) ? (key->u.k_offset_v1.k_offset = offset) :
-	(key->u.k_offset_v2.k_offset = cpu_to_le64 (offset));
+    (version == ITEM_VERSION_1) ?
+        (key->u.k_offset_v1.k_offset = cpu_to_le32 (offset)) : /* jdm check */
+	(set_offset_v2_k_offset( &(key->u.k_offset_v2), offset ));
 }
 static inline void set_le_ih_k_offset (struct item_head * ih, loff_t offset)
 {
@@ -524,8 +582,9 @@
 
 static inline void set_le_key_k_type (int version, struct key * key, int type)
 {
-    (version == ITEM_VERSION_1) ? (key->u.k_offset_v1.k_uniqueness = type2uniqueness (type)) :
-	(key->u.k_offset_v2.k_type = cpu_to_le16 (type));
+    (version == ITEM_VERSION_1) ?
+        (key->u.k_offset_v1.k_uniqueness = cpu_to_le32(type2uniqueness(type))):
+	(set_offset_v2_k_type( &(key->u.k_offset_v2), type ));
 }
 static inline void set_le_ih_k_type (struct item_head * ih, int type)
 {
@@ -553,26 +612,30 @@
 //
 static inline loff_t cpu_key_k_offset (struct cpu_key * key)
 {
-    return (key->version == ITEM_VERSION_1) ? key->on_disk_key.u.k_offset_v1.k_offset :
+    return (key->version == ITEM_VERSION_1) ?
+        key->on_disk_key.u.k_offset_v1.k_offset :
 	key->on_disk_key.u.k_offset_v2.k_offset;
 }
 
 static inline loff_t cpu_key_k_type (struct cpu_key * key)
 {
-    return (key->version == ITEM_VERSION_1) ? uniqueness2type (key->on_disk_key.u.k_offset_v1.k_uniqueness) :
+    return (key->version == ITEM_VERSION_1) ?
+        uniqueness2type (key->on_disk_key.u.k_offset_v1.k_uniqueness) :
 	key->on_disk_key.u.k_offset_v2.k_type;
 }
 
 static inline void set_cpu_key_k_offset (struct cpu_key * key, loff_t offset)
 {
-    (key->version == ITEM_VERSION_1) ? (key->on_disk_key.u.k_offset_v1.k_offset = offset) :
+    (key->version == ITEM_VERSION_1) ?
+        (key->on_disk_key.u.k_offset_v1.k_offset = offset) :
 	(key->on_disk_key.u.k_offset_v2.k_offset = offset);
 }
 
 
 static inline void set_cpu_key_k_type (struct cpu_key * key, int type)
 {
-    (key->version == ITEM_VERSION_1) ? (key->on_disk_key.u.k_offset_v1.k_uniqueness = type2uniqueness (type)) :
+    (key->version == ITEM_VERSION_1) ?
+        (key->on_disk_key.u.k_offset_v1.k_uniqueness = type2uniqueness (type)):
 	(key->on_disk_key.u.k_offset_v2.k_type = type);
 }
 
@@ -638,7 +701,17 @@
   struct key  blk_right_delim_key; /* kept only for compatibility */
 };
 
-#define BLKH_SIZE (sizeof(struct block_head))
+#define BLKH_SIZE                     (sizeof(struct block_head))
+#define blkh_level(p_blkh)            (le16_to_cpu((p_blkh)->blk_level))
+#define blkh_nr_item(p_blkh)          (le16_to_cpu((p_blkh)->blk_nr_item))
+#define blkh_free_space(p_blkh)       (le16_to_cpu((p_blkh)->blk_free_space))
+#define blkh_reserved(p_blkh)         (le16_to_cpu((p_blkh)->blk_reserved))
+#define set_blkh_level(p_blkh,val)    ((p_blkh)->blk_level = cpu_to_le16(val))
+#define set_blkh_nr_item(p_blkh,val)  ((p_blkh)->blk_nr_item = cpu_to_le16(val))
+#define set_blkh_free_space(p_blkh,val) ((p_blkh)->blk_free_space = cpu_to_le16(val))
+#define set_blkh_reserved(p_blkh,val) ((p_blkh)->blk_reserved = cpu_to_le16(val))
+#define blkh_right_delim_key(p_blkh)  ((p_blkh)->blk_right_delim_key)
+#define set_blkh_right_delim_key(p_blkh,val)  ((p_blkh)->blk_right_delim_key = val)
 
 /*
  * values for blk_level field of the struct block_head
@@ -652,25 +725,26 @@
 #define DISK_LEAF_NODE_LEVEL  1 /* Leaf node level.*/
 
 /* Given the buffer head of a formatted node, resolve to the block head of that node. */
-#define B_BLK_HEAD(p_s_bh)  ((struct block_head *)((p_s_bh)->b_data))
+#define B_BLK_HEAD(p_s_bh)            ((struct block_head *)((p_s_bh)->b_data))
 /* Number of items that are in buffer. */
-#define B_NR_ITEMS(p_s_bh)	  	(le16_to_cpu ( B_BLK_HEAD(p_s_bh)->blk_nr_item ))
-#define B_LEVEL(bh)			(le16_to_cpu ( B_BLK_HEAD(bh)->blk_level ))
-#define B_FREE_SPACE(bh)		(le16_to_cpu ( B_BLK_HEAD(bh)->blk_free_space ))
-
-#define PUT_B_NR_ITEMS(p_s_bh)	  	do { B_BLK_HEAD(p_s_bh)->blk_nr_item = cpu_to_le16(val); } while (0)
-#define PUT_B_LEVEL(bh, val)		do { B_BLK_HEAD(bh)->blk_level = cpu_to_le16(val); } while (0)
-#define PUT_B_FREE_SPACE(bh)		do { B_BLK_HEAD(bh)->blk_free_space = cpu_to_le16(val); } while (0)
+#define B_NR_ITEMS(p_s_bh)            (blkh_nr_item(B_BLK_HEAD(p_s_bh)))
+#define B_LEVEL(p_s_bh)               (blkh_level(B_BLK_HEAD(p_s_bh)))
+#define B_FREE_SPACE(p_s_bh)          (blkh_free_space(B_BLK_HEAD(p_s_bh)))
+
+#define PUT_B_NR_ITEMS(p_s_bh,val)    do { set_blkh_nr_item(B_BLK_HEAD(p_s_bh),val); } while (0)
+#define PUT_B_LEVEL(p_s_bh,val)       do { set_blkh_level(B_BLK_HEAD(p_s_bh),val); } while (0)
+#define PUT_B_FREE_SPACE(p_s_bh,val)  do { set_blkh_free_space(B_BLK_HEAD(p_s_bh),val); } while (0)
+
 
-/* Get right delimiting key. */
-#define B_PRIGHT_DELIM_KEY(p_s_bh)	( &(B_BLK_HEAD(p_s_bh)->blk_right_delim_key) )
+/* Get right delimiting key. -- little endian */
+#define B_PRIGHT_DELIM_KEY(p_s_bh)   (&(blk_right_delim_key(B_BLK_HEAD(p_s_bh))
 
 /* Does the buffer contain a disk leaf. */
-#define B_IS_ITEMS_LEVEL(p_s_bh)   	( B_BLK_HEAD(p_s_bh)->blk_level == DISK_LEAF_NODE_LEVEL )
+#define B_IS_ITEMS_LEVEL(p_s_bh)     (B_LEVEL(p_s_bh) == DISK_LEAF_NODE_LEVEL)
 
 /* Does the buffer contain a disk internal node */
-#define B_IS_KEYS_LEVEL(p_s_bh) 	( B_BLK_HEAD(p_s_bh)->blk_level > DISK_LEAF_NODE_LEVEL &&\
-					  B_BLK_HEAD(p_s_bh)->blk_level <= MAX_HEIGHT )
+#define B_IS_KEYS_LEVEL(p_s_bh)      (B_LEVEL(p_s_bh) > DISK_LEAF_NODE_LEVEL \
+                                            && B_LEVEL(p_s_bh) <= MAX_HEIGHT)
 
 
 
@@ -709,8 +783,32 @@
 				   policy.  Someday.  -Hans */
 } __attribute__ ((__packed__));
 
-#define SD_V1_SIZE (sizeof(struct stat_data_v1))
-
+#define SD_V1_SIZE              (sizeof(struct stat_data_v1))
+#define stat_data_v1(ih)        (ih_version (ih) == ITEM_VERSION_1)
+#define sd_v1_mode(sdp)         (le16_to_cpu((sdp)->sd_mode))
+#define set_sd_v1_mode(sdp,v)   ((sdp)->sd_mode = cpu_to_le16(v))
+#define sd_v1_nlink(sdp)        (le16_to_cpu((sdp)->sd_nlink))
+#define set_sd_v1_nlink(sdp,v)  ((sdp)->sd_nlink = cpu_to_le16(v))
+#define sd_v1_uid(sdp)          (le16_to_cpu((sdp)->sd_uid))
+#define set_sd_v1_uid(sdp,v)    ((sdp)->sd_uid = cpu_to_le16(v))
+#define sd_v1_gid(sdp)          (le16_to_cpu((sdp)->sd_gid))
+#define set_sd_v1_gid(sdp,v)    ((sdp)->sd_gid = cpu_to_le16(v))
+#define sd_v1_size(sdp)         (le32_to_cpu((sdp)->sd_size))
+#define set_sd_v1_size(sdp,v)   ((sdp)->sd_size = cpu_to_le32(v))
+#define sd_v1_atime(sdp)        (le32_to_cpu((sdp)->sd_atime))
+#define set_sd_v1_atime(sdp,v)  ((sdp)->sd_atime = cpu_to_le32(v))
+#define sd_v1_mtime(sdp)        (le32_to_cpu((sdp)->sd_mtime))
+#define set_sd_v1_mtime(sdp,v)  ((sdp)->sd_mtime = cpu_to_le32(v))
+#define sd_v1_ctime(sdp)        (le32_to_cpu((sdp)->sd_ctime))
+#define set_sd_v1_ctime(sdp,v)  ((sdp)->sd_ctime = cpu_to_le32(v))
+#define sd_v1_rdev(sdp)         (le32_to_cpu((sdp)->u.sd_rdev))
+#define set_sd_v1_rdev(sdp,v)   ((sdp)->u.sd_rdev = cpu_to_le32(v))
+#define sd_v1_blocks(sdp)       (le32_to_cpu((sdp)->u.sd_blocks))
+#define set_sd_v1_blocks(sdp,v) ((sdp)->u.sd_blocks = cpu_to_le32(v))
+#define sd_v1_first_direct_byte(sdp) \
+                                (le32_to_cpu((sdp)->sd_first_direct_byte))
+#define set_sd_v1_first_direct_byte(sdp,v) \
+                                ((sdp)->sd_first_direct_byte = cpu_to_le32(v))
 
 /* Stat Data on disk (reiserfs version of UFS disk inode minus the
    address blocks) */
@@ -743,8 +841,32 @@
 // this is 40 bytes long
 //
 #define SD_SIZE (sizeof(struct stat_data))
-
-#define stat_data_v1(ih) (ih_version (ih) == ITEM_VERSION_1)
+#define SD_V2_SIZE              SD_SIZE
+#define stat_data_v2(ih)        (ih_version (ih) == ITEM_VERSION_2)
+#define sd_v2_mode(sdp)         (le16_to_cpu((sdp)->sd_mode))
+#define set_sd_v2_mode(sdp,v)   ((sdp)->sd_mode = cpu_to_le16(v))
+/* sd_reserved */
+/* set_sd_reserved */
+#define sd_v2_nlink(sdp)        (le32_to_cpu((sdp)->sd_nlink))
+#define set_sd_v2_nlink(sdp,v)  ((sdp)->sd_nlink = cpu_to_le32(v))
+#define sd_v2_size(sdp)         (le64_to_cpu((sdp)->sd_size))
+#define set_sd_v2_size(sdp,v)   ((sdp)->sd_size = cpu_to_le64(v))
+#define sd_v2_uid(sdp)          (le32_to_cpu((sdp)->sd_uid))
+#define set_sd_v2_uid(sdp,v)    ((sdp)->sd_uid = cpu_to_le32(v))
+#define sd_v2_gid(sdp)          (le32_to_cpu((sdp)->sd_gid))
+#define set_sd_v2_gid(sdp,v)    ((sdp)->sd_gid = cpu_to_le32(v))
+#define sd_v2_atime(sdp)        (le32_to_cpu((sdp)->sd_atime))
+#define set_sd_v2_atime(sdp,v)  ((sdp)->sd_atime = cpu_to_le32(v))
+#define sd_v2_mtime(sdp)        (le32_to_cpu((sdp)->sd_mtime))
+#define set_sd_v2_mtime(sdp,v)  ((sdp)->sd_mtime = cpu_to_le32(v))
+#define sd_v2_ctime(sdp)        (le32_to_cpu((sdp)->sd_ctime))
+#define set_sd_v2_ctime(sdp,v)  ((sdp)->sd_ctime = cpu_to_le32(v))
+#define sd_v2_blocks(sdp)       (le32_to_cpu((sdp)->sd_blocks))
+#define set_sd_v2_blocks(sdp,v) ((sdp)->sd_blocks = cpu_to_le32(v))
+#define sd_v2_rdev(sdp)         (le32_to_cpu((sdp)->u.sd_rdev))
+#define set_sd_v2_rdev(sdp,v)   ((sdp)->u.sd_rdev = cpu_to_le32(v))
+#define sd_v2_generation(sdp)   (le32_to_cpu((sdp)->u.sd_generation))
+#define set_sd_v2_generation(sdp,v) ((sdp)->u.sd_generation = cpu_to_le32(v))
 
 
 /***************************************************************************/
@@ -793,7 +915,18 @@
   __u16 deh_state;		/* whether 1) entry contains stat data (for future), and 2) whether
 					   entry is hidden (unlinked) */
 } __attribute__ ((__packed__));
-#define DEH_SIZE sizeof(struct reiserfs_de_head)
+#define DEH_SIZE                  sizeof(struct reiserfs_de_head)
+#define deh_offset(p_deh)         (le32_to_cpu((p_deh)->deh_offset))
+#define deh_dir_id(p_deh)         (le32_to_cpu((p_deh)->deh_dir_id))
+#define deh_objectid(p_deh)       (le32_to_cpu((p_deh)->deh_objectid))
+#define deh_location(p_deh)       (le16_to_cpu((p_deh)->deh_location))
+#define deh_state(p_deh)          (le16_to_cpu((p_deh)->deh_state))
+
+#define put_deh_offset(p_deh,v)   ((p_deh)->deh_offset = cpu_to_le32((v)))
+#define put_deh_dir_id(p_deh,v)   ((p_deh)->deh_dir_id = cpu_to_le32((v)))
+#define put_deh_objectid(p_deh,v) ((p_deh)->deh_objectid = cpu_to_le32((v)))
+#define put_deh_location(p_deh,v) ((p_deh)->deh_location = cpu_to_le16((v)))
+#define put_deh_state(p_deh,v)    ((p_deh)->deh_state = cpu_to_le16((v)))
 
 /* empty directory contains two entries "." and ".." and their headers */
 #define EMPTY_DIR_SIZE \
@@ -805,34 +938,31 @@
 #define DEH_Statdata 0			/* not used now */
 #define DEH_Visible 2
 
-/* bitops which deals with unaligned addrs; 
-   needed for alpha port. --zam */
-#ifdef __alpha__
-#   define ADDR_UNALIGNED_BITS  (5)
+/* 64 bit systems (and the S/390) need to be aligned explicitly -jdm */
+#if BITS_PER_LONG == 64 || defined(__s390__) || defined(__hppa__)
+#   define ADDR_UNALIGNED_BITS  (3)
 #endif
 
+/* These are only used to manipulate deh_state.
+ * Because of this, we'll use the ext2_ bit routines,
+ * since they are little endian */
 #ifdef ADDR_UNALIGNED_BITS
 
 #   define aligned_address(addr)           ((void *)((long)(addr) & ~((1UL << ADDR_UNALIGNED_BITS) - 1)))
 #   define unaligned_offset(addr)          (((int)((long)(addr) & ((1 << ADDR_UNALIGNED_BITS) - 1))) << 3)
 
-#   define set_bit_unaligned(nr, addr)     set_bit((nr) + unaligned_offset(addr), aligned_address(addr))
-#   define clear_bit_unaligned(nr, addr)   clear_bit((nr) + unaligned_offset(addr), aligned_address(addr))
-#   define test_bit_unaligned(nr, addr)    test_bit((nr) + unaligned_offset(addr), aligned_address(addr))
+#   define set_bit_unaligned(nr, addr)     ext2_set_bit((nr) + unaligned_offset(addr), aligned_address(addr))
+#   define clear_bit_unaligned(nr, addr)   ext2_clear_bit((nr) + unaligned_offset(addr), aligned_address(addr))
+#   define test_bit_unaligned(nr, addr)    ext2_test_bit((nr) + unaligned_offset(addr), aligned_address(addr))
 
 #else
 
-#   define set_bit_unaligned(nr, addr)     set_bit(nr, addr)
-#   define clear_bit_unaligned(nr, addr)   clear_bit(nr, addr)
-#   define test_bit_unaligned(nr, addr)    test_bit(nr, addr)
+#   define set_bit_unaligned(nr, addr)     ext2_set_bit(nr, addr)
+#   define clear_bit_unaligned(nr, addr)   ext2_clear_bit(nr, addr)
+#   define test_bit_unaligned(nr, addr)    ext2_test_bit(nr, addr)
 
 #endif
 
-#define deh_dir_id(deh) (__le32_to_cpu ((deh)->deh_dir_id))
-#define deh_objectid(deh) (__le32_to_cpu ((deh)->deh_objectid))
-#define deh_offset(deh) (__le32_to_cpu ((deh)->deh_offset))
-
-
 #define mark_de_with_sd(deh)        set_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
 #define mark_de_without_sd(deh)     clear_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
 #define mark_de_visible(deh)	    set_bit_unaligned (DEH_Visible, &((deh)->deh_state))
@@ -844,7 +974,9 @@
 
 /* compose directory item containing "." and ".." entries (entries are
    not aligned to 4 byte boundary) */
-static inline void make_empty_dir_item_v1 (char * body, __u32 dirid, __u32 objid,
+/* the last four params are LE */
+static inline void make_empty_dir_item_v1 (char * body,
+                                           __u32 dirid, __u32 objid,
 					   __u32 par_dirid, __u32 par_objid)
 {
     struct reiserfs_de_head * deh;
@@ -853,29 +985,32 @@
     deh = (struct reiserfs_de_head *)body;
     
     /* direntry header of "." */
-    deh[0].deh_offset = cpu_to_le32 (DOT_OFFSET);
-    deh[0].deh_dir_id = cpu_to_le32 (dirid);
-    deh[0].deh_objectid = cpu_to_le32 (objid);
-    deh[0].deh_location = cpu_to_le16 (EMPTY_DIR_SIZE_V1 - strlen ("."));
-    deh[0].deh_state = 0;
+    put_deh_offset( &(deh[0]), DOT_OFFSET );
+    /* these two are from make_le_item_head, and are are LE */
+    deh[0].deh_dir_id = dirid;
+    deh[0].deh_objectid = objid;
+    deh[0].deh_state = 0; /* Endian safe if 0 */
+    put_deh_location( &(deh[0]), EMPTY_DIR_SIZE_V1 - strlen( "." ));
     mark_de_visible(&(deh[0]));
   
     /* direntry header of ".." */
-    deh[1].deh_offset = cpu_to_le32 (DOT_DOT_OFFSET);
+    put_deh_offset( &(deh[1]), DOT_DOT_OFFSET);
     /* key of ".." for the root directory */
-    deh[1].deh_dir_id = cpu_to_le32 (par_dirid);
-    deh[1].deh_objectid = cpu_to_le32 (par_objid);
-    deh[1].deh_location = cpu_to_le16 (le16_to_cpu (deh[0].deh_location) - strlen (".."));
-    deh[1].deh_state = 0;
+    /* these two are from the inode, and are are LE */
+    deh[1].deh_dir_id = par_dirid;
+    deh[1].deh_objectid = par_objid;
+    deh[1].deh_state = 0; /* Endian safe if 0 */
+    put_deh_location( &(deh[1]), deh_location( &(deh[0]) ) - strlen( ".." ) );
     mark_de_visible(&(deh[1]));
 
     /* copy ".." and "." */
-    memcpy (body + deh[0].deh_location, ".", 1);
-    memcpy (body + deh[1].deh_location, "..", 2);
+    memcpy (body + deh_location( &(deh[0]) ), ".", 1);
+    memcpy (body + deh_location( &(deh[1]) ), "..", 2);
 }
 
 /* compose directory item containing "." and ".." entries */
-static inline void make_empty_dir_item (char * body, __u32 dirid, __u32 objid,
+static inline void make_empty_dir_item (char * body,
+                                        __u32 dirid, __u32 objid,
 					__u32 par_dirid, __u32 par_objid)
 {
     struct reiserfs_de_head * deh;
@@ -884,31 +1019,33 @@
     deh = (struct reiserfs_de_head *)body;
     
     /* direntry header of "." */
-    deh[0].deh_offset = cpu_to_le32 (DOT_OFFSET);
-    deh[0].deh_dir_id = cpu_to_le32 (dirid);
-    deh[0].deh_objectid = cpu_to_le32 (objid);
-    deh[0].deh_location = cpu_to_le16 (EMPTY_DIR_SIZE - ROUND_UP (strlen (".")));
-    deh[0].deh_state = 0;
+    put_deh_offset( &(deh[0]), DOT_OFFSET );
+    /* these two are from make_le_item_head, and are are LE */
+    deh[0].deh_dir_id = dirid;
+    deh[0].deh_objectid = objid;
+    deh[0].deh_state = 0; /* Endian safe if 0 */
+    put_deh_location( &(deh[0]), EMPTY_DIR_SIZE - ROUND_UP( strlen( "." ) ) );
     mark_de_visible(&(deh[0]));
   
     /* direntry header of ".." */
-    deh[1].deh_offset = cpu_to_le32 (DOT_DOT_OFFSET);
+    put_deh_offset( &(deh[1]), DOT_DOT_OFFSET );
     /* key of ".." for the root directory */
-    deh[1].deh_dir_id = cpu_to_le32 (par_dirid);
-    deh[1].deh_objectid = cpu_to_le32 (par_objid);
-    deh[1].deh_location = cpu_to_le16 (le16_to_cpu (deh[0].deh_location) - ROUND_UP (strlen ("..")));
-    deh[1].deh_state = 0;
+    /* these two are from the inode, and are are LE */
+    deh[1].deh_dir_id = par_dirid;
+    deh[1].deh_objectid = par_objid;
+    deh[1].deh_state = 0; /* Endian safe if 0 */
+    put_deh_location( &(deh[1]), deh_location( &(deh[0])) - ROUND_UP( strlen( ".." ) ) );
     mark_de_visible(&(deh[1]));
 
     /* copy ".." and "." */
-    memcpy (body + deh[0].deh_location, ".", 1);
-    memcpy (body + deh[1].deh_location, "..", 2);
+    memcpy (body + deh_location( &(deh[0]) ), ".", 1);
+    memcpy (body + deh_location( &(deh[1]) ), "..", 2);
 }
 
 
 /* array of the entry headers */
  /* get item body */
-#define B_I_PITEM(bh,ih) ( (bh)->b_data + (ih)->ih_item_location )
+#define B_I_PITEM(bh,ih) ( (bh)->b_data + ih_location(ih) )
 #define B_I_DEH(bh,ih) ((struct reiserfs_de_head *)(B_I_PITEM(bh,ih)))
 
 /* length of the directory entry in directory item. This define
@@ -919,7 +1056,7 @@
    See picture above.*/
 /*
 #define I_DEH_N_ENTRY_LENGTH(ih,deh,i) \
-((i) ? (((deh)-1)->deh_location - (deh)->deh_location) : ((ih)->ih_item_len) - (deh)->deh_location)
+((i) ? (deh_location((deh)-1) - deh_location((deh))) : (ih_item_len((ih)) - deh_location((deh))))
 */
 static inline int entry_length (struct buffer_head * bh, struct item_head * ih,
 				int pos_in_item)
@@ -928,18 +1065,19 @@
 
     deh = B_I_DEH (bh, ih) + pos_in_item;
     if (pos_in_item)
-	return (le16_to_cpu ((deh - 1)->deh_location) - le16_to_cpu (deh->deh_location));
-    return (le16_to_cpu (ih->ih_item_len) - le16_to_cpu (deh->deh_location));
+	return deh_location(deh-1) - deh_location(deh);
+
+    return ih_item_len(ih) - deh_location(deh);
 }
 
 
 
 /* number of entries in the directory item, depends on ENTRY_COUNT being at the start of directory dynamic data. */
-#define I_ENTRY_COUNT(ih) ((ih)->u.ih_entry_count)
+#define I_ENTRY_COUNT(ih) (ih_entry_count((ih)))
 
 
 /* name by bh, ih and entry_num */
-#define B_I_E_NAME(bh,ih,entry_num) ((char *)(bh->b_data + ih->ih_item_location + (B_I_DEH(bh,ih)+(entry_num))->deh_location))
+#define B_I_E_NAME(bh,ih,entry_num) ((char *)(bh->b_data + ih_location(ih) + deh_location(B_I_DEH(bh,ih)+(entry_num))))
 
 // two entries per block (at least)
 //#define REISERFS_MAX_NAME_LEN(block_size) 
@@ -976,7 +1114,7 @@
 /* these defines are useful when a particular member of a reiserfs_dir_entry is needed */
 
 /* pointer to file name, stored in entry */
-#define B_I_DEH_ENTRY_FILE_NAME(bh,ih,deh) (B_I_PITEM (bh, ih) + (deh)->deh_location)
+#define B_I_DEH_ENTRY_FILE_NAME(bh,ih,deh) (B_I_PITEM (bh, ih) + deh_location(deh))
 
 /* length of name */
 #define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \
@@ -1014,14 +1152,18 @@
 };
 
 #define DC_SIZE (sizeof(struct disk_child))
+#define dc_block_number(dc_p)	(le32_to_cpu((dc_p)->dc_block_number))
+#define dc_size(dc_p)		(le16_to_cpu((dc_p)->dc_size))
+#define put_dc_block_number(dc_p, val)   do { (dc_p)->dc_block_number = cpu_to_le32(val); } while(0)
+#define put_dc_size(dc_p, val)   do { (dc_p)->dc_size = cpu_to_le16(val); } while(0)
 
 /* Get disk child by buffer header and position in the tree node. */
 #define B_N_CHILD(p_s_bh,n_pos)  ((struct disk_child *)\
 ((p_s_bh)->b_data+BLKH_SIZE+B_NR_ITEMS(p_s_bh)*KEY_SIZE+DC_SIZE*(n_pos)))
 
 /* Get disk child number by buffer header and position in the tree node. */
-#define B_N_CHILD_NUM(p_s_bh,n_pos) (le32_to_cpu (B_N_CHILD(p_s_bh,n_pos)->dc_block_number))
-#define PUT_B_N_CHILD_NUM(p_s_bh,n_pos, val) do { B_N_CHILD(p_s_bh,n_pos)->dc_block_number = cpu_to_le32(val); } while (0)
+#define B_N_CHILD_NUM(p_s_bh,n_pos) (dc_block_number(B_N_CHILD(p_s_bh,n_pos)))
+#define PUT_B_N_CHILD_NUM(p_s_bh,n_pos, val) (put_dc_block_number(B_N_CHILD(p_s_bh,n_pos), val ))
 
  /* maximal value of field child_size in structure disk_child */ 
  /* child size is the combined size of all items and their headers */
@@ -1459,10 +1601,10 @@
 
 
 /* number of blocks pointed to by the indirect item */
-#define I_UNFM_NUM(p_s_ih)	( (p_s_ih)->ih_item_len / UNFM_P_SIZE )
+#define I_UNFM_NUM(p_s_ih)	( ih_item_len(p_s_ih) / UNFM_P_SIZE )
 
 /* the used space within the unformatted node corresponding to pos within the item pointed to by ih */
-#define I_POS_UNFM_SIZE(ih,pos,size) (((pos) == I_UNFM_NUM(ih) - 1 ) ? (size) - (ih)->u.ih_free_space : (size))
+#define I_POS_UNFM_SIZE(ih,pos,size) (((pos) == I_UNFM_NUM(ih) - 1 ) ? (size) - ih_free_space(ih) : (size))
 
 /* number of bytes contained by the direct item or the unformatted nodes the indirect item points to */
 
@@ -1477,16 +1619,16 @@
 #define B_N_PKEY(bh,item_num) ( &(B_N_PITEM_HEAD(bh,item_num)->ih_key) )
 
 /* get item body */
-#define B_N_PITEM(bh,item_num) ( (bh)->b_data + B_N_PITEM_HEAD((bh),(item_num))->ih_item_location)
+#define B_N_PITEM(bh,item_num) ( (bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(item_num))))
 
 /* get the stat data by the buffer header and the item order */
 #define B_N_STAT_DATA(bh,nr) \
-( (struct stat_data *)((bh)->b_data+B_N_PITEM_HEAD((bh),(nr))->ih_item_location ) )
+( (struct stat_data *)((bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(nr))) ) )
 
-                 /* following defines use reiserfs buffer header and item header */
+    /* following defines use reiserfs buffer header and item header */
 
 /* get stat-data */
-#define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )((bh)->b_data + (ih)->ih_item_location) )
+#define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )((bh)->b_data + ih_location(ih)) )
 
 // this is 3976 for size==4096
 #define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_SIZE - UNFM_P_SIZE)
@@ -1494,7 +1636,7 @@
 /* indirect items consist of entries which contain blocknrs, pos
    indicates which entry, and B_I_POS_UNFM_POINTER resolves to the
    blocknr contained by the entry pos points to */
-#define B_I_POS_UNFM_POINTER(bh,ih,pos) (*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)))
+#define B_I_POS_UNFM_POINTER(bh,ih,pos) le32_to_cpu(*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)))
 #define PUT_B_I_POS_UNFM_POINTER(bh,ih,pos, val) do {*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)) = cpu_to_le32(val); } while (0)
 
 /* Reiserfs buffer cache statistics. */
@@ -1596,6 +1738,8 @@
 */
 #define JOURNAL_BUFFER(j,n) ((j)->j_ap_blocks[((j)->j_start + (n)) % JOURNAL_BLOCK_COUNT])
 
+void reiserfs_commit_for_inode(struct inode *) ;
+void reiserfs_update_inode_transaction(struct inode *) ;
 void reiserfs_wait_on_write_block(struct super_block *s) ;
 void reiserfs_block_writes(struct reiserfs_transaction_handle *th) ;
 void reiserfs_allow_writes(struct super_block *s) ;
@@ -1692,7 +1836,7 @@
 {
     int type;
     
-    type = le16_to_cpu (key->u.k_offset_v2.k_type);
+    type = offset_v2_k_type( &(key->u.k_offset_v2));
     if (type != TYPE_DIRECT && type != TYPE_INDIRECT && type != TYPE_DIRENTRY)
 	return ITEM_VERSION_1;
 
@@ -1943,9 +2087,9 @@
 #endif
 
 /* hashes.c */
-__u32 keyed_hash (const char *msg, int len);
-__u32 yura_hash (const char *msg, int len);
-__u32 r5_hash (const char *msg, int len);
+__u32 keyed_hash (const signed char *msg, int len);
+__u32 yura_hash (const signed char *msg, int len);
+__u32 r5_hash (const signed char *msg, int len);
 
 /* version.c */
 char *reiserfs_get_version_string(void) ;
diff -urN linux-2.4.13-pre1/include/linux/reiserfs_fs_i.h linux/include/linux/reiserfs_fs_i.h
--- linux-2.4.13-pre1/include/linux/reiserfs_fs_i.h	Wed Oct 10 23:44:34 2001
+++ linux/include/linux/reiserfs_fs_i.h	Mon Dec  3 23:17:33 2001
@@ -40,6 +40,12 @@
                                    is a comment you should make.... -Hans */
   //nopack-attribute
   int nopack;
+  
+  /* we use these for fsync or O_SYNC to decide which transaction needs
+  ** to be committed in order for this inode to be properly flushed
+  */
+  unsigned long i_trans_id ;
+  unsigned long i_trans_index ;
 };
 
 
diff -urN linux-2.4.13-pre1/include/linux/reiserfs_fs_sb.h linux/include/linux/reiserfs_fs_sb.h
--- linux-2.4.13-pre1/include/linux/reiserfs_fs_sb.h	Wed Oct 10 23:44:34 2001
+++ linux/include/linux/reiserfs_fs_sb.h	Mon Dec  3 23:17:33 2001
@@ -65,6 +65,57 @@
 } __attribute__ ((__packed__));
 
 #define SB_SIZE (sizeof(struct reiserfs_super_block))
+/* struct reiserfs_super_block accessors/mutators
+ * since this is a disk structure, it will always be in 
+ * little endian format. */
+#define sb_block_count(sbp)           (le32_to_cpu((sbp)->s_block_count))
+#define set_sb_block_count(sbp,v)     ((sbp)->s_block_count = cpu_to_le32(v))
+#define sb_free_blocks(sbp)           (le32_to_cpu((sbp)->s_free_blocks))
+#define set_sb_free_blocks(sbp,v)     ((sbp)->s_free_blocks = cpu_to_le32(v))
+#define sb_root_block(sbp)            (le32_to_cpu((sbp)->s_root_block))
+#define set_sb_root_block(sbp,v)      ((sbp)->s_root_block = cpu_to_le32(v))
+#define sb_journal_block(sbp)         (le32_to_cpu((sbp)->s_journal_block))
+#define set_sb_journal_block(sbp,v)   ((sbp)->s_journal_block = cpu_to_le32(v))
+#define sb_journal_dev(sbp)           (le32_to_cpu((sbp)->s_journal_dev))
+#define set_sb_journal_dev(sbp,v)     ((sbp)->s_journal_dev = cpu_to_le32(v))
+#define sb_orig_journal_size(sbp)   (le32_to_cpu((sbp)->s_orig_journal_size))
+#define set_sb_orig_journal_size(sbp,v) \
+                            ((sbp)->s_orig_journal_size = cpu_to_le32(v))
+#define sb_journal_trans_max(sbp)     (le32_to_cpu((sbp)->s_journal_trans_max))
+#define set_journal_trans_max(sbp,v) \
+                            ((sbp)->s_journal_trans_max = cpu_to_le32(v))
+#define sb_journal_block_count(sbp)  (le32_to_cpu((sbp)->journal_block_count))
+#define sb_set_journal_block_count(sbp,v) \
+                            ((sbp)->s_journal_block_count = cpu_to_le32(v))
+#define sb_journal_max_batch(sbp)     (le32_to_cpu((sbp)->s_journal_max_batch))
+#define set_sb_journal_max_batch(sbp,v) \
+                            ((sbp)->s_journal_max_batch = cpu_to_le32(v))
+#define sb_jourmal_max_commit_age(sbp) \
+                            (le32_to_cpu((sbp)->s_journal_max_commit_age))
+#define set_sb_journal_max_commit_age(sbp,v) \
+                            ((sbp)->s_journal_max_commit_age = cpu_to_le32(v))
+#define sb_jourmal_max_trans_age(sbp) \
+                            (le32_to_cpu((sbp)->s_journal_max_trans_age))
+#define set_sb_journal_max_trans_age(sbp,v) \
+                            ((sbp)->s_journal_max_trans_age = cpu_to_le32(v))
+#define sb_blocksize(sbp)             (le16_to_cpu((sbp)->s_blocksize))
+#define set_sb_blocksize(sbp,v)       ((sbp)->s_blocksize = cpu_to_le16(v))
+#define sb_oid_maxsize(sbp)           (le16_to_cpu((sbp)->s_oid_maxsize))
+#define set_sb_oid_maxsize(sbp,v)     ((sbp)->s_oid_maxsize = cpu_to_le16(v))
+#define sb_oid_cursize(sbp)           (le16_to_cpu((sbp)->s_oid_cursize))
+#define set_sb_oid_cursize(sbp,v)     ((sbp)->s_oid_cursize = cpu_to_le16(v))
+#define sb_state(sbp)                 (le16_to_cpu((sbp)->s_state))
+#define set_sb_state(sbp,v)           ((sbp)->s_state = cpu_to_le16(v))
+#define sb_hash_function_code(sbp) \
+                            (le32_to_cpu((sbp)->s_hash_function_code))
+#define set_sb_hash_function_code(sbp,v) \
+                            ((sbp)->s_hash_function_code = cpu_to_le32(v))
+#define sb_tree_height(sbp)           (le16_to_cpu((sbp)->s_tree_height))
+#define set_sb_tree_height(sbp,v)     ((sbp)->s_tree_height = cpu_to_le16(v))
+#define sb_bmap_nr(sbp)               (le16_to_cpu((sbp)->s_bmap_nr))
+#define set_sb_bmap_nr(sbp,v)         ((sbp)->s_bmap_nr = cpu_to_le16(v))
+#define sb_version(sbp)               (le16_to_cpu((sbp)->s_version))
+#define set_sb_version(sbp,v)         ((sbp)->s_version = cpu_to_le16(v))
 
 /* this is the super from 3.5.X, where X >= 10 */
 struct reiserfs_super_block_v1
@@ -180,7 +231,6 @@
   unsigned long t_trans_id ;    /* sanity check, equals the current trans id */
   struct super_block *t_super ; /* super for this FS when journal_begin was 
                                    called. saves calls to reiserfs_get_super */
-
 } ;
 
 /*
@@ -262,7 +312,7 @@
 #define JOURNAL_DESC_MAGIC "ReIsErLB" /* ick.  magic string to find desc blocks in the journal */
 
 
-typedef __u32 (*hashf_t) (const char *, int);
+typedef __u32 (*hashf_t) (const signed char *, int);
 
 /* reiserfs union of in-core super block data */
 struct reiserfs_sb_info
@@ -377,25 +427,22 @@
 
 
 // on-disk super block fields converted to cpu form
-#define SB_DISK_SUPER_BLOCK(s) ((s)->u.reiserfs_sb.s_rs)
-#define SB_BLOCK_COUNT(s) le32_to_cpu ((SB_DISK_SUPER_BLOCK(s)->s_block_count))
-#define SB_FREE_BLOCKS(s) le32_to_cpu ((SB_DISK_SUPER_BLOCK(s)->s_free_blocks))
-#define SB_REISERFS_MAGIC(s) (SB_DISK_SUPER_BLOCK(s)->s_magic)
-#define SB_ROOT_BLOCK(s) le32_to_cpu ((SB_DISK_SUPER_BLOCK(s)->s_root_block))
-#define SB_TREE_HEIGHT(s) le16_to_cpu ((SB_DISK_SUPER_BLOCK(s)->s_tree_height))
-#define SB_REISERFS_STATE(s) le16_to_cpu ((SB_DISK_SUPER_BLOCK(s)->s_state))
-#define SB_VERSION(s) le16_to_cpu ((SB_DISK_SUPER_BLOCK(s)->s_version))
-#define SB_BMAP_NR(s) le16_to_cpu ((SB_DISK_SUPER_BLOCK(s)->s_bmap_nr))
-
-#define PUT_SB_BLOCK_COUNT(s, val)    do { SB_DISK_SUPER_BLOCK(s)->s_block_count = cpu_to_le32(val); } while (0)
-#define PUT_SB_FREE_BLOCKS(s, val)    do { SB_DISK_SUPER_BLOCK(s)->s_free_blocks = cpu_to_le32(val); } while (0)
-#define PUT_SB_ROOT_BLOCK(s, val)     do { SB_DISK_SUPER_BLOCK(s)->s_root_block = cpu_to_le32(val); } while (0)
-#define PUT_SB_TREE_HEIGHT(s, val)    do { SB_DISK_SUPER_BLOCK(s)->s_tree_height = cpu_to_le16(val); } while (0)
-#define PUT_SB_REISERFS_STATE(s, val) do { SB_DISK_SUPER_BLOCK(s)->s_state = cpu_to_le16(val); } while (0) 
-#define PUT_SB_VERSION(s, val)        do { SB_DISK_SUPER_BLOCK(s)->s_version = cpu_to_le16(val); } while (0)
-#define PUT_SB_BMAP_NR(s, val)           do { SB_DISK_SUPER_BLOCK(s)->s_bmap_nr = cpu_to_le16 (val); } while (0)
+#define SB_DISK_SUPER_BLOCK(s)        ((s)->u.reiserfs_sb.s_rs)
+#define SB_BLOCK_COUNT(s)             sb_block_count (SB_DISK_SUPER_BLOCK(s))
+#define SB_FREE_BLOCKS(s)             sb_free_blocks (SB_DISK_SUPER_BLOCK(s))
+#define SB_REISERFS_MAGIC(s)          (SB_DISK_SUPER_BLOCK(s)->s_magic)
+#define SB_ROOT_BLOCK(s)              sb_root_block (SB_DISK_SUPER_BLOCK(s))
+#define SB_TREE_HEIGHT(s)             sb_tree_height (SB_DISK_SUPER_BLOCK(s))
+#define SB_REISERFS_STATE(s)          sb_state (SB_DISK_SUPER_BLOCK(s))
+#define SB_VERSION(s)                 sb_version (SB_DISK_SUPER_BLOCK(s))
+#define SB_BMAP_NR(s)                 sb_bmap_nr(SB_DISK_SUPER_BLOCK(s))
+
+#define PUT_SB_BLOCK_COUNT(s, val)    do { set_sb_block_count( SB_DISK_SUPER_BLOCK(s), val); } while (0)
+#define PUT_SB_FREE_BLOCKS(s, val)    do { set_sb_free_blocks( SB_DISK_SUPER_BLOCK(s), val); } while (0)
+#define PUT_SB_ROOT_BLOCK(s, val)     do { set_sb_root_block( SB_DISK_SUPER_BLOCK(s), val); } while (0)
+#define PUT_SB_TREE_HEIGHT(s, val)    do { set_sb_tree_height( SB_DISK_SUPER_BLOCK(s), val); } while (0)
+#define PUT_SB_REISERFS_STATE(s, val) do { set_sb_state( SB_DISK_SUPER_BLOCK(s), val); } while (0) 
+#define PUT_SB_VERSION(s, val)        do { set_sb_version( SB_DISK_SUPER_BLOCK(s), val); } while (0)
+#define PUT_SB_BMAP_NR(s, val)        do { set_sb_bmap_nr( SB_DISK_SUPER_BLOCK(s), val); } while (0)
 
 #endif	/* _LINUX_REISER_FS_SB */
-
-
-
diff -urN linux-2.4.13-pre1/include/linux/wireless.h linux/include/linux/wireless.h
--- linux-2.4.13-pre1/include/linux/wireless.h	Wed Oct 10 23:44:46 2001
+++ linux/include/linux/wireless.h	Mon Dec  3 23:17:33 2001
@@ -1,7 +1,7 @@
 /*
  * This file define a set of standard wireless extensions
  *
- * Version :	11	28.3.01
+ * Version :	12	5.10.01
  *
  * Authors :	Jean Tourrilhes - HPL - <jt@hpl.hp.com>
  */
@@ -63,7 +63,7 @@
  * (there is some stuff that will be added in the future...)
  * I just plan to increment with each new version.
  */
-#define WIRELESS_EXT	11
+#define WIRELESS_EXT	12
 
 /*
  * Changes :
@@ -116,6 +116,13 @@
  * ----------
  *	- Add WE version in range (help backward/forward compatibility)
  *	- Add retry ioctls (work like PM)
+ *
+ * V11 to V12
+ * ----------
+ *	- Add SIOCSIWSTATS to get /proc/net/wireless programatically
+ *	- Add DEV PRIVATE IOCTL to avoid collisions in SIOCDEVPRIVATE space
+ *	- Add new statistics (frag, retry, beacon)
+ *	- Add average quality (for user space calibration)
  */
 
 /* -------------------------- IOCTL LIST -------------------------- */
@@ -137,6 +144,8 @@
 #define SIOCGIWRANGE	0x8B0B		/* Get range of parameters */
 #define SIOCSIWPRIV	0x8B0C		/* Unused */
 #define SIOCGIWPRIV	0x8B0D		/* get private ioctl interface info */
+#define SIOCSIWSTATS	0x8B0E		/* Unused */
+#define SIOCGIWSTATS	0x8B0F		/* Get /proc/net/wireless stats */
 
 /* Mobile IP support */
 #define SIOCSIWSPY	0x8B10		/* set spy addresses */
@@ -177,11 +186,33 @@
 #define SIOCSIWPOWER	0x8B2C		/* set Power Management settings */
 #define SIOCGIWPOWER	0x8B2D		/* get Power Management settings */
 
+/* -------------------- DEV PRIVATE IOCTL LIST -------------------- */
+
+/* These 16 ioctl are wireless device private.
+ * Each driver is free to use them for whatever purpose it chooses,
+ * however the driver *must* export the description of those ioctls
+ * with SIOCGIWPRIV and *must* use arguments as defined below.
+ * If you don't follow those rules, DaveM is going to hate you (reason :
+ * it make mixed 32/64bit operation impossible).
+ */
+#define SIOCIWFIRSTPRIV	0x8BE0
+#define SIOCIWLASTPRIV	0x8BFF
+/* Previously, we were using SIOCDEVPRIVATE, but we now have our
+ * separate range because of collisions with other tools such as
+ * 'mii-tool'.
+ * We now have 32 commands, so a bit more space ;-).
+ * Also, all 'odd' commands are only usable by root and don't return the
+ * content of ifr/iwr to user (but you are not obliged to use the set/get
+ * convention, just use every other two command).
+ * And I repeat : you are not obliged to use them with iwspy, but you
+ * must be compliant with it.
+ */
+
 /* ------------------------- IOCTL STUFF ------------------------- */
 
 /* The first and the last (range) */
 #define SIOCIWFIRST	0x8B00
-#define SIOCIWLAST	0x8B30
+#define SIOCIWLAST	SIOCIWLASTPRIV		/* 0x8BFF */
 
 /* Even : get (world access), odd : set (root access) */
 #define IW_IS_SET(cmd)	(!((cmd) & 0x1))
@@ -191,7 +222,7 @@
 /*
  * The following is used with SIOCGIWPRIV. It allow a driver to define
  * the interface (name, type of data) for its private ioctl.
- * Privates ioctl are SIOCDEVPRIVATE -> SIOCDEVPRIVATE + 0xF
+ * Privates ioctl are SIOCIWFIRSTPRIV -> SIOCIWLASTPRIV
  */
 
 #define IW_PRIV_TYPE_MASK	0x7000	/* Type of arguments */
@@ -334,23 +365,38 @@
  */
 struct	iw_quality
 {
-	__u8		qual;		/* link quality (%retries, SNR or better...) */
-	__u8		level;		/* signal level */
-	__u8		noise;		/* noise level */
+	__u8		qual;		/* link quality (%retries, SNR,
+					   %missed beacons or better...) */
+	__u8		level;		/* signal level (dBm) */
+	__u8		noise;		/* noise level (dBm) */
 	__u8		updated;	/* Flags to know if updated */
 };
 
 /*
  *	Packet discarded in the wireless adapter due to
  *	"wireless" specific problems...
+ *	Note : the list of counter and statistics in net_device_stats
+ *	is already pretty exhaustive, and you should use that first.
+ *	This is only additional stats...
  */
 struct	iw_discarded
 {
-	__u32		nwid;		/* Wrong nwid */
-	__u32		code;		/* Unable to code/decode */
+	__u32		nwid;		/* Rx : Wrong nwid/essid */
+	__u32		code;		/* Rx : Unable to code/decode (WEP) */
+	__u32		fragment;	/* Rx : Can't perform MAC reassembly */
+	__u32		retries;	/* Tx : Max MAC retries num reached */
 	__u32		misc;		/* Others cases */
 };
 
+/*
+ *	Packet/Time period missed in the wireless adapter due to
+ *	"wireless" specific problems...
+ */
+struct	iw_missed
+{
+	__u32		beacon;		/* Missed beacons/superframe */
+};
+
 /* ------------------------ WIRELESS STATS ------------------------ */
 /*
  * Wireless statistics (used for /proc/net/wireless)
@@ -363,6 +409,7 @@
 	struct iw_quality	qual;		/* Quality of the link
 						 * (instant/mean/max) */
 	struct iw_discarded	discard;	/* Packet discarded counts */
+	struct iw_missed	miss;		/* Packet missed counts */
 };
 
 /* ------------------------ IOCTL REQUEST ------------------------ */
@@ -493,6 +540,19 @@
 	__s32		max_retry;	/* Maximal number of retries */
 	__s32		min_r_time;	/* Minimal retry lifetime */
 	__s32		max_r_time;	/* Maximal retry lifetime */
+
+	/* Average quality of link & SNR */
+	struct iw_quality	avg_qual;	/* Quality of the link */
+	/* This should contain the average/typical values of the quality
+	 * indicator. This should be the threshold between a "good" and
+	 * a "bad" link (example : monitor going from green to orange).
+	 * Currently, user space apps like quality monitors don't have any
+	 * way to calibrate the measurement. With this, they can split
+	 * the range between 0 and max_qual in different quality level
+	 * (using a geometric subdivision centered on the average).
+	 * I expect that people doing the user space apps will feedback
+	 * us on which value we need to put in each driver...
+	 */
 };
 
 /*
diff -urN linux-2.4.13-pre1/init/main.c linux/init/main.c
--- linux-2.4.13-pre1/init/main.c	Sat Oct  6 08:49:16 2001
+++ linux/init/main.c	Mon Dec  3 23:17:33 2001
@@ -777,8 +777,12 @@
 		int i, pid;
 
 		pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
-		if (pid>0)
-			while (pid != wait(&i));
+		if (pid > 0) {
+			while (pid != wait(&i)) {
+				current->policy |= SCHED_YIELD;
+				schedule();
+			}
+		}
 		if (MAJOR(real_root_dev) != RAMDISK_MAJOR
 		     || MINOR(real_root_dev) != 0) {
 			error = change_root(real_root_dev,"/initrd");
diff -urN linux-2.4.13-pre1/net/ax25/ax25_ip.c linux/net/ax25/ax25_ip.c
--- linux-2.4.13-pre1/net/ax25/ax25_ip.c	Mon Jul  2 13:56:40 2001
+++ linux/net/ax25/ax25_ip.c	Mon Dec  3 23:17:33 2001
@@ -56,9 +56,14 @@
 
 int ax25_encapsulate(struct sk_buff *skb, struct net_device *dev, unsigned short type, void *daddr, void *saddr, unsigned len)
 {
-  	/* header is an AX.25 UI frame from us to them */
- 	unsigned char *buff = skb_push(skb, AX25_HEADER_LEN);
+	unsigned char *buff;
+
+	/* they sometimes come back to us... */
+	if (type == ETH_P_AX25)
+		return 0;
 
+  	/* header is an AX.25 UI frame from us to them */
+ 	buff = skb_push(skb, AX25_HEADER_LEN);
   	*buff++ = 0x00;	/* KISS DATA */
 
 	if (daddr != NULL)
@@ -90,7 +95,7 @@
   			*buff++ = AX25_P_ARP;
   			break;
   		default:
-  			printk(KERN_ERR "AX.25: ax25_encapsulate - wrong protocol type 0x%x2.2\n", type);
+  			printk(KERN_ERR "AX.25: ax25_encapsulate - wrong protocol type 0x%2.2x\n", type);
   			*buff++ = 0;
   			break;
  	}
diff -urN linux-2.4.13-pre1/net/core/dev.c linux/net/core/dev.c
--- linux-2.4.13-pre1/net/core/dev.c	Sat Oct  6 15:21:58 2001
+++ linux/net/core/dev.c	Mon Dec  3 23:17:33 2001
@@ -1804,7 +1804,7 @@
 
 	if (stats != (struct iw_statistics *) NULL) {
 		size = sprintf(buffer,
-			       "%6s: %04x  %3d%c  %3d%c  %3d%c  %6d %6d %6d\n",
+			       "%6s: %04x  %3d%c  %3d%c  %3d%c  %6d %6d %6d %6d %6d   %6d\n",
 			       dev->name,
 			       stats->status,
 			       stats->qual.qual,
@@ -1815,7 +1815,10 @@
 			       stats->qual.updated & 4 ? '.' : ' ',
 			       stats->discard.nwid,
 			       stats->discard.code,
-			       stats->discard.misc);
+			       stats->discard.fragment,
+			       stats->discard.retries,
+			       stats->discard.misc,
+			       stats->miss.beacon);
 		stats->qual.updated = 0;
 	}
 	else
@@ -1839,8 +1842,8 @@
 	struct net_device *	dev;
 
 	size = sprintf(buffer,
-		       "Inter-| sta-|   Quality        |   Discarded packets\n"
-		       " face | tus | link level noise |  nwid  crypt   misc\n"
+		       "Inter-| sta-|   Quality        |   Discarded packets               | Missed\n"
+		       " face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon\n"
 			);
 	
 	pos += size;
@@ -1871,6 +1874,33 @@
 	return len;
 }
 #endif	/* CONFIG_PROC_FS */
+
+/*
+ *	Allow programatic access to /proc/net/wireless even if /proc
+ *	doesn't exist... Also more efficient...
+ */
+static inline int dev_iwstats(struct net_device *dev, struct ifreq *ifr)
+{
+	/* Get stats from the driver */
+	struct iw_statistics *stats = (dev->get_wireless_stats ?
+				       dev->get_wireless_stats(dev) :
+				       (struct iw_statistics *) NULL);
+
+	if (stats != (struct iw_statistics *) NULL) {
+		struct iwreq *	wrq = (struct iwreq *)ifr;
+
+		/* Copy statistics to the user buffer */
+		if(copy_to_user(wrq->u.data.pointer, stats,
+				sizeof(struct iw_statistics)))
+			return -EFAULT;
+
+		/* Check if we need to clear the update flag */
+		if(wrq->u.data.flags != 0)
+			stats->qual.updated = 0;
+		return(0);
+	} else
+		return -EOPNOTSUPP;
+}
 #endif	/* WIRELESS_EXT */
 
 /**
@@ -2169,6 +2199,11 @@
 			dev->name[IFNAMSIZ-1] = 0;
 			notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev);
 			return 0;
+
+#ifdef WIRELESS_EXT
+		case SIOCGIWSTATS:
+			return dev_iwstats(dev, ifr);
+#endif	/* WIRELESS_EXT */
 
 		/*
 		 *	Unknown or private ioctl
diff -urN linux-2.4.13-pre1/net/ipv6/netfilter/ip6t_mac.c linux/net/ipv6/netfilter/ip6t_mac.c
--- linux-2.4.13-pre1/net/ipv6/netfilter/ip6t_mac.c	Tue Jun 20 14:32:27 2000
+++ linux/net/ipv6/netfilter/ip6t_mac.c	Mon Dec  3 23:17:33 2001
@@ -20,7 +20,7 @@
 
     /* Is mac pointer valid? */
     return (skb->mac.raw >= skb->head
-	    && skb->mac.raw < skb->head + skb->len - ETH_HLEN
+	    && (skb->mac.raw + ETH_HLEN) <= skb->data
 	    /* If so, compare... */
 	    && ((memcmp(skb->mac.ethernet->h_source, info->srcaddr, ETH_ALEN)
 		== 0) ^ info->invert));
