Skip to contentSkip to conversation

Btrfs: fix byte order issue in free space cache

PATCH New Li Zefan 1 participant 1 message Jun 16, 2011 Btrfs file system

lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 Btrfs: fix byte order issue in free space cache

We should convert the transaction id to little endian before saving it to disk.

---
 fs/btrfs/free-space-cache.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
fs/btrfs/free-space-cache.c +8 -7
index 9f985a4..740dbf4 100644
@@ -20,6 +20,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/math64.h>
+#include <asm/unaligned.h>
 #include "ctree.h"
 #include "free-space-cache.h"
 #include "transaction.h"
@@ -340,14 +341,15 @@ int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
 		addr = kmap(page);
 
 		if (index == 0) {
-			u64 *gen;
+			u64 gen;
 
 			memcpy(disk_crcs, addr, first_page_offset);
-			gen = addr + (sizeof(u32) * num_checksums);
-			if (*gen != BTRFS_I(inode)->generation) {
+			gen = get_unaligned_le64(
+				addr + sizeof(u32) * num_checksums);
+			if (gen != BTRFS_I(inode)->generation) {
 				printk(KERN_ERR "btrfs: space cache generation"
 				       " (%llu) does not match inode (%llu)\n",
-				       (unsigned long long)*gen,
+				       (unsigned long long)gen,
 				       (unsigned long long)
 				       BTRFS_I(inode)->generation);
 				kunmap(page);
@@ -814,14 +816,13 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
 	/* Write the checksums and trans id to the first page */
 	{
 		void *addr;
-		u64 *gen;
 
 		page = pages[0];
 
 		addr = kmap(page);
 		memcpy(addr, checksums, sizeof(u32) * num_pages);
-		gen = addr + (sizeof(u32) * num_pages);
-		*gen = trans->transid;
+		put_unaligned_le64(trans->transid,
+			addr + sizeof(u32) * num_pages);
 		kunmap(page);
 	}
 
Signature · 1 line
1.7.3.1