All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Big endian fixes for btrfs
@ 2012-03-25 13:36 Anton Blanchard
  2012-03-25 13:47 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2012-03-31 20:14 ` [PATCH] " Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 2 replies; 6+ messages in thread
From: Anton Blanchard @ 2012-03-25 13:36 UTC (permalink / raw)
  To: grub-devel

2012-03-25  Anton Blanchard  <anton@samba.org>

	* grub-core/fs/btrfs.c (read_sblock): Fix incorrect endian conversion.
	(key_cmp): Likewise.
	(lower_bound): Likewise.
	(grub_btrfs_read_logical): Likewise.
	(grub_btrfs_read_inode): Likewise.
	(grub_btrfs_extent_read): Likewise.
	(find_path): Likewise.
	(grub_btrfs_dir): Likewise.
	(grub_btrfs_open): Likewise.

Index: grub/grub-core/fs/btrfs.c
===================================================================
--- grub.orig/grub-core/fs/btrfs.c	2012-03-26 00:19:28.690769829 +1100
+++ grub/grub-core/fs/btrfs.c	2012-03-26 00:23:40.019447649 +1100
@@ -279,9 +279,9 @@ read_sblock (grub_disk_t disk, struct gr
 static int
 key_cmp (const struct grub_btrfs_key *a, const struct grub_btrfs_key *b)
 {
-  if (grub_cpu_to_le64 (a->object_id) < grub_cpu_to_le64 (b->object_id))
+  if (grub_le_to_cpu64 (a->object_id) < grub_le_to_cpu64 (b->object_id))
     return -1;
-  if (grub_cpu_to_le64 (a->object_id) > grub_cpu_to_le64 (b->object_id))
+  if (grub_le_to_cpu64 (a->object_id) > grub_le_to_cpu64 (b->object_id))
     return +1;
 
   if (a->type < b->type)
@@ -289,9 +289,9 @@ key_cmp (const struct grub_btrfs_key *a,
   if (a->type > b->type)
     return +1;
 
-  if (grub_cpu_to_le64 (a->offset) < grub_cpu_to_le64 (b->offset))
+  if (grub_le_to_cpu64 (a->offset) < grub_le_to_cpu64 (b->offset))
     return -1;
-  if (grub_cpu_to_le64 (a->offset) > grub_cpu_to_le64 (b->offset))
+  if (grub_le_to_cpu64 (a->offset) > grub_le_to_cpu64 (b->offset))
     return +1;
   return 0;
 }
@@ -400,7 +400,8 @@ lower_bound (struct grub_btrfs_data *dat
   grub_dprintf ("btrfs",
 		"retrieving %" PRIxGRUB_UINT64_T
 		" %x %" PRIxGRUB_UINT64_T "\n",
-		key_in->object_id, key_in->type, key_in->offset);
+		grub_le_to_cpu64 (key_in->object_id), key_in->type,
+		grub_le_to_cpu64 (key_in->offset));
 
   while (1)
     {
@@ -430,8 +431,9 @@ lower_bound (struct grub_btrfs_data *dat
 	      grub_dprintf ("btrfs",
 			    "internal node (depth %d) %" PRIxGRUB_UINT64_T
 			    " %x %" PRIxGRUB_UINT64_T "\n", depth,
-			    node.key.object_id, node.key.type,
-			    node.key.offset);
+			    grub_le_to_cpu64 (node.key.object_id),
+			    node.key.type,
+			    grub_le_to_cpu64 (node.key.offset));
 
 	      if (key_cmp (&node.key, key_in) == 0)
 		{
@@ -482,7 +484,8 @@ lower_bound (struct grub_btrfs_data *dat
 	    grub_dprintf ("btrfs",
 			  "leaf (depth %d) %" PRIxGRUB_UINT64_T
 			  " %x %" PRIxGRUB_UINT64_T "\n", depth,
-			  leaf.key.object_id, leaf.key.type, leaf.key.offset);
+			  grub_le_to_cpu64 (leaf.key.object_id), leaf.key.type,
+			  grub_le_to_cpu64 (leaf.key.offset));
 
 	    if (key_cmp (&leaf.key, key_in) == 0)
 	      {
@@ -642,9 +645,9 @@ grub_btrfs_read_logical (struct grub_btr
 	    * grub_le_to_cpu16 (chunk->nstripes);
 	}
 
-      key_in.object_id = GRUB_BTRFS_OBJECT_ID_CHUNK;
+      key_in.object_id = grub_cpu_to_le64 (GRUB_BTRFS_OBJECT_ID_CHUNK);
       key_in.type = GRUB_BTRFS_ITEM_TYPE_CHUNK;
-      key_in.offset = addr;
+      key_in.offset = grub_cpu_to_le64 (addr);
       err = lower_bound (data, &key_in, &key_out,
 			 grub_le_to_cpu64 (data->sblock.chunk_tree),
 			 &chaddr, &chsize, NULL);
@@ -776,7 +779,7 @@ grub_btrfs_read_logical (struct grub_btr
 		   With RAID5-like it will be more difficult.  */
 		stripe += stripen + i;
 
-		paddr = stripe->offset + stripe_offset;
+		paddr = grub_le_to_cpu64 (stripe->offset) + stripe_offset;
 
 		grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
 			      "+0x%" PRIxGRUB_UINT64_T
@@ -788,7 +791,7 @@ grub_btrfs_read_logical (struct grub_btr
 			      grub_le_to_cpu16 (chunk->nstripes),
 			      grub_le_to_cpu16 (chunk->nsubstripes),
 			      grub_le_to_cpu64 (chunk->stripe_length),
-			      stripen, stripe->offset);
+			      stripen, grub_le_to_cpu64 (stripe->offset));
 		grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T
 			      " for laddr 0x%" PRIxGRUB_UINT64_T "\n", paddr,
 			      addr);
@@ -883,14 +886,14 @@ grub_btrfs_read_inode (struct grub_btrfs
   grub_size_t elemsize;
   grub_err_t err;
 
-  key_in.object_id = num;
+  key_in.object_id = grub_cpu_to_le64 (num);
   key_in.type = GRUB_BTRFS_ITEM_TYPE_INODE_ITEM;
   key_in.offset = 0;
 
   err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, NULL);
   if (err)
     return err;
-  if (num != key_out.object_id
+  if (num != grub_le_to_cpu64 (key_out.object_id)
       || key_out.type != GRUB_BTRFS_ITEM_TYPE_INODE_ITEM)
     return grub_error (GRUB_ERR_BAD_FS, "inode not found");
 
@@ -990,14 +993,14 @@ grub_btrfs_extent_read (struct grub_btrf
 	  grub_size_t elemsize;
 
 	  grub_free (data->extent);
-	  key_in.object_id = ino;
+	  key_in.object_id = grub_cpu_to_le64 (ino);
 	  key_in.type = GRUB_BTRFS_ITEM_TYPE_EXTENT_ITEM;
 	  key_in.offset = grub_cpu_to_le64 (pos);
 	  err = lower_bound (data, &key_in, &key_out, tree,
 			     &elemaddr, &elemsize, NULL);
 	  if (err)
 	    return -1;
-	  if (key_out.object_id != ino
+	  if (grub_le_to_cpu64 (key_out.object_id) != ino
 	      || key_out.type != GRUB_BTRFS_ITEM_TYPE_EXTENT_ITEM)
 	    {
 	      grub_error (GRUB_ERR_BAD_FS, "extent not found");
@@ -1174,7 +1177,7 @@ find_path (struct grub_btrfs_data *data,
   unsigned symlinks_max = 32;
 
   *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
-  *tree = data->sblock.root_tree;
+  *tree = grub_le_to_cpu64 (data->sblock.root_tree);
   key->object_id = data->sblock.root_dir_objectid;
   key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
   key->offset = 0;
@@ -1292,7 +1295,8 @@ find_path (struct grub_btrfs_data *data,
 	    }
 
 	  err = grub_btrfs_read_inode (data, &inode,
-				       cdirel->key.object_id, *tree);
+				       grub_le_to_cpu64 (cdirel->key.object_id),
+				       *tree);
 	  if (err)
 	    {
 	      grub_free (direl);
@@ -1310,7 +1314,8 @@ find_path (struct grub_btrfs_data *data,
 	      return grub_errno;
 	    }
 
-	  if (grub_btrfs_extent_read (data, cdirel->key.object_id,
+	  if (grub_btrfs_extent_read (data,
+				      grub_le_to_cpu64 (cdirel->key.object_id),
 				      *tree, 0, tmp,
 				      grub_le_to_cpu64 (inode.size))
 	      != (grub_ssize_t) grub_le_to_cpu64 (inode.size))
@@ -1344,7 +1349,7 @@ find_path (struct grub_btrfs_data *data,
 	  {
 	    struct grub_btrfs_root_item ri;
 	    err = lower_bound (data, &cdirel->key, &key_out,
-			       data->sblock.root_tree,
+			       grub_le_to_cpu64 (data->sblock.root_tree),
 			       &elemaddr, &elemsize, NULL);
 	    if (err)
 	      {
@@ -1372,7 +1377,7 @@ find_path (struct grub_btrfs_data *data,
 	      }
 	    key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
 	    key->offset = 0;
-	    key->object_id = GRUB_BTRFS_OBJECT_ID_CHUNK;
+	    key->object_id = grub_cpu_to_le64 (GRUB_BTRFS_OBJECT_ID_CHUNK);
 	    *tree = grub_le_to_cpu64 (ri.tree);
 	    break;
 	  }
@@ -1487,14 +1492,15 @@ grub_btrfs_dir (grub_device_t device, co
 	  char c;
 	  struct grub_btrfs_inode inode;
 	  struct grub_dirhook_info info;
-	  err = grub_btrfs_read_inode (data, &inode, cdirel->key.object_id,
+	  err = grub_btrfs_read_inode (data, &inode,
+				       grub_le_to_cpu64 (cdirel->key.object_id),
 				       tree);
 	  grub_memset (&info, 0, sizeof (info));
 	  if (err)
 	    grub_errno = GRUB_ERR_NONE;
 	  else
 	    {
-	      info.mtime = inode.mtime.sec;
+	      info.mtime = grub_le_to_cpu64 (inode.mtime.sec);
 	      info.mtimeset = 1;
 	    }
 	  c = cdirel->name[grub_le_to_cpu16 (cdirel->n)];
@@ -1541,7 +1547,7 @@ grub_btrfs_open (struct grub_file *file,
       return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a regular file"));
     }
 
-  data->inode = key_in.object_id;
+  data->inode = grub_le_to_cpu64 (key_in.object_id);
   err = grub_btrfs_read_inode (data, &inode, data->inode, data->tree);
   if (err)
     {


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Big endian fixes for btrfs
  2012-03-25 13:36 [PATCH] Big endian fixes for btrfs Anton Blanchard
@ 2012-03-25 13:47 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2012-03-25 21:10   ` Anton Blanchard
  2012-03-31 20:14 ` [PATCH] " Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 1 reply; 6+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-03-25 13:47 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 143 bytes --]

object_id is left unconverted on purpose and is converted only on
comparisons.


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Big endian fixes for btrfs
  2012-03-25 13:47 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2012-03-25 21:10   ` Anton Blanchard
  2012-03-25 21:29     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 6+ messages in thread
From: Anton Blanchard @ 2012-03-25 21:10 UTC (permalink / raw)
  To: grub-devel


Hi Vladimir,

> object_id is left unconverted on purpose and is converted only on
> comparisons.

Could you be a bit more specific about which byteswapping of object_id
is bad?

Since we always byteswap when doing a comparison, object_ids need to be
created in little endian format:

-           key->object_id = GRUB_BTRFS_OBJECT_ID_CHUNK;
+           key->object_id = grub_cpu_to_le64 (GRUB_BTRFS_OBJECT_ID_CHUNK);

Whenever we use the contents of an object, eg as an address for reading
we need to byteswap it to native endian:

-         err = grub_btrfs_read_inode (data, &inode, cdirel->key.object_id,
+         err = grub_btrfs_read_inode (data, &inode,
+                                      grub_le_to_cpu64 (cdirel->key.object_id),
                                       tree);

and

-  data->inode = key_in.object_id;
+  data->inode = grub_le_to_cpu64 (key_in.object_id);

Comparisons need to be in native endian:

-         if (key_out.object_id != ino
+         if (grub_le_to_cpu64 (key_out.object_id) != ino


Finally we want to print the object_id in native endian or else they
will make no sense:

            grub_dprintf ("btrfs",
                          "leaf (depth %d) %" PRIxGRUB_UINT64_T
                          " %x %" PRIxGRUB_UINT64_T "\n", depth,
-                         leaf.key.object_id,leaf.key.type,leaf.key.offset);
+                         grub_le_to_cpu64(leaf.key.object_id),leaf.key.type,
+                         grub_le_to_cpu64 (leaf.key.offset));

I did test these with your fstest.sh script. Before the changes nothing
passed, after the changes everything passes.

Anton



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Big endian fixes for btrfs
  2012-03-25 21:10   ` Anton Blanchard
@ 2012-03-25 21:29     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2012-03-25 22:20       ` [PATCH v2] " Anton Blanchard
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-03-25 21:29 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

On 25.03.2012 23:10, Anton Blanchard wrote:
> -  data->inode = key_in.object_id;
> +  data->inode = grub_le_to_cpu64 (key_in.object_id);
the inode field is in little-endian as well (not native endian)

>-         if (key_out.object_id != ino
>+         if (grub_le_to_cpu64 (key_out.object_id) != ino

Not if you keep both sides little-endian

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] Big endian fixes for btrfs
  2012-03-25 21:29     ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2012-03-25 22:20       ` Anton Blanchard
  0 siblings, 0 replies; 6+ messages in thread
From: Anton Blanchard @ 2012-03-25 22:20 UTC (permalink / raw)
  To: grub-devel

2012-03-25  Anton Blanchard  <anton@samba.org>

	* grub-core/fs/btrfs.c (read_sblock): Fix incorrect endian conversion.
	(key_cmp): Likewise.
	(lower_bound): Likewise.
	(grub_btrfs_read_logical): Likewise.
	(grub_btrfs_read_inode): Likewise.
	(find_path): Likewise.
	(grub_btrfs_dir): Likewise.

Index: grub/grub-core/fs/btrfs.c
===================================================================
--- grub.orig/grub-core/fs/btrfs.c	2012-03-26 08:37:00.096578236 +1100
+++ grub/grub-core/fs/btrfs.c	2012-03-26 09:15:44.769981996 +1100
@@ -279,9 +279,9 @@ read_sblock (grub_disk_t disk, struct gr
 static int
 key_cmp (const struct grub_btrfs_key *a, const struct grub_btrfs_key *b)
 {
-  if (grub_cpu_to_le64 (a->object_id) < grub_cpu_to_le64 (b->object_id))
+  if (grub_le_to_cpu64 (a->object_id) < grub_le_to_cpu64 (b->object_id))
     return -1;
-  if (grub_cpu_to_le64 (a->object_id) > grub_cpu_to_le64 (b->object_id))
+  if (grub_le_to_cpu64 (a->object_id) > grub_le_to_cpu64 (b->object_id))
     return +1;
 
   if (a->type < b->type)
@@ -289,9 +289,9 @@ key_cmp (const struct grub_btrfs_key *a,
   if (a->type > b->type)
     return +1;
 
-  if (grub_cpu_to_le64 (a->offset) < grub_cpu_to_le64 (b->offset))
+  if (grub_le_to_cpu64 (a->offset) < grub_le_to_cpu64 (b->offset))
     return -1;
-  if (grub_cpu_to_le64 (a->offset) > grub_cpu_to_le64 (b->offset))
+  if (grub_le_to_cpu64 (a->offset) > grub_le_to_cpu64 (b->offset))
     return +1;
   return 0;
 }
@@ -400,7 +400,8 @@ lower_bound (struct grub_btrfs_data *dat
   grub_dprintf ("btrfs",
 		"retrieving %" PRIxGRUB_UINT64_T
 		" %x %" PRIxGRUB_UINT64_T "\n",
-		key_in->object_id, key_in->type, key_in->offset);
+		grub_le_to_cpu64 (key_in->object_id), key_in->type,
+		grub_le_to_cpu64 (key_in->offset));
 
   while (1)
     {
@@ -430,8 +431,9 @@ lower_bound (struct grub_btrfs_data *dat
 	      grub_dprintf ("btrfs",
 			    "internal node (depth %d) %" PRIxGRUB_UINT64_T
 			    " %x %" PRIxGRUB_UINT64_T "\n", depth,
-			    node.key.object_id, node.key.type,
-			    node.key.offset);
+			    grub_le_to_cpu64 (node.key.object_id),
+			    node.key.type,
+			    grub_le_to_cpu64 (node.key.offset));
 
 	      if (key_cmp (&node.key, key_in) == 0)
 		{
@@ -482,7 +484,8 @@ lower_bound (struct grub_btrfs_data *dat
 	    grub_dprintf ("btrfs",
 			  "leaf (depth %d) %" PRIxGRUB_UINT64_T
 			  " %x %" PRIxGRUB_UINT64_T "\n", depth,
-			  leaf.key.object_id, leaf.key.type, leaf.key.offset);
+			  grub_le_to_cpu64 (leaf.key.object_id), leaf.key.type,
+			  grub_le_to_cpu64 (leaf.key.offset));
 
 	    if (key_cmp (&leaf.key, key_in) == 0)
 	      {
@@ -642,9 +645,9 @@ grub_btrfs_read_logical (struct grub_btr
 	    * grub_le_to_cpu16 (chunk->nstripes);
 	}
 
-      key_in.object_id = GRUB_BTRFS_OBJECT_ID_CHUNK;
+      key_in.object_id = grub_cpu_to_le64 (GRUB_BTRFS_OBJECT_ID_CHUNK);
       key_in.type = GRUB_BTRFS_ITEM_TYPE_CHUNK;
-      key_in.offset = addr;
+      key_in.offset = grub_cpu_to_le64 (addr);
       err = lower_bound (data, &key_in, &key_out,
 			 grub_le_to_cpu64 (data->sblock.chunk_tree),
 			 &chaddr, &chsize, NULL);
@@ -776,7 +779,7 @@ grub_btrfs_read_logical (struct grub_btr
 		   With RAID5-like it will be more difficult.  */
 		stripe += stripen + i;
 
-		paddr = stripe->offset + stripe_offset;
+		paddr = grub_le_to_cpu64 (stripe->offset) + stripe_offset;
 
 		grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
 			      "+0x%" PRIxGRUB_UINT64_T
@@ -788,7 +791,7 @@ grub_btrfs_read_logical (struct grub_btr
 			      grub_le_to_cpu16 (chunk->nstripes),
 			      grub_le_to_cpu16 (chunk->nsubstripes),
 			      grub_le_to_cpu64 (chunk->stripe_length),
-			      stripen, stripe->offset);
+			      stripen, grub_le_to_cpu64 (stripe->offset));
 		grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T
 			      " for laddr 0x%" PRIxGRUB_UINT64_T "\n", paddr,
 			      addr);
@@ -1174,7 +1177,7 @@ find_path (struct grub_btrfs_data *data,
   unsigned symlinks_max = 32;
 
   *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
-  *tree = data->sblock.root_tree;
+  *tree = grub_le_to_cpu64 (data->sblock.root_tree);
   key->object_id = data->sblock.root_dir_objectid;
   key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
   key->offset = 0;
@@ -1344,7 +1347,7 @@ find_path (struct grub_btrfs_data *data,
 	  {
 	    struct grub_btrfs_root_item ri;
 	    err = lower_bound (data, &cdirel->key, &key_out,
-			       data->sblock.root_tree,
+			       grub_le_to_cpu64 (data->sblock.root_tree),
 			       &elemaddr, &elemsize, NULL);
 	    if (err)
 	      {
@@ -1372,7 +1375,7 @@ find_path (struct grub_btrfs_data *data,
 	      }
 	    key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
 	    key->offset = 0;
-	    key->object_id = GRUB_BTRFS_OBJECT_ID_CHUNK;
+	    key->object_id = grub_cpu_to_le64 (GRUB_BTRFS_OBJECT_ID_CHUNK);
 	    *tree = grub_le_to_cpu64 (ri.tree);
 	    break;
 	  }
@@ -1494,7 +1497,7 @@ grub_btrfs_dir (grub_device_t device, co
 	    grub_errno = GRUB_ERR_NONE;
 	  else
 	    {
-	      info.mtime = inode.mtime.sec;
+	      info.mtime = grub_le_to_cpu64 (inode.mtime.sec);
 	      info.mtimeset = 1;
 	    }
 	  c = cdirel->name[grub_le_to_cpu16 (cdirel->n)];


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Big endian fixes for btrfs
  2012-03-25 13:36 [PATCH] Big endian fixes for btrfs Anton Blanchard
  2012-03-25 13:47 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2012-03-31 20:14 ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 6+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-03-31 20:14 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 8696 bytes --]

On 25.03.2012 15:36, Anton Blanchard wrote:
> 2012-03-25  Anton Blanchard  <anton@samba.org>
>
> 	* grub-core/fs/btrfs.c (read_sblock): Fix incorrect endian conversion.
> 	(key_cmp): Likewise.
> 	(lower_bound): Likewise.
> 	(grub_btrfs_read_logical): Likewise.
> 	(grub_btrfs_read_inode): Likewise.
> 	(grub_btrfs_extent_read): Likewise.
> 	(find_path): Likewise.
> 	(grub_btrfs_dir): Likewise.
> 	(grub_btrfs_open): Likewise.
Applied it with some changes
Thanks.
> Index: grub/grub-core/fs/btrfs.c
> ===================================================================
> --- grub.orig/grub-core/fs/btrfs.c	2012-03-26 00:19:28.690769829 +1100
> +++ grub/grub-core/fs/btrfs.c	2012-03-26 00:23:40.019447649 +1100
> @@ -279,9 +279,9 @@ read_sblock (grub_disk_t disk, struct gr
>  static int
>  key_cmp (const struct grub_btrfs_key *a, const struct grub_btrfs_key *b)
>  {
> -  if (grub_cpu_to_le64 (a->object_id) < grub_cpu_to_le64 (b->object_id))
> +  if (grub_le_to_cpu64 (a->object_id) < grub_le_to_cpu64 (b->object_id))
>      return -1;
> -  if (grub_cpu_to_le64 (a->object_id) > grub_cpu_to_le64 (b->object_id))
> +  if (grub_le_to_cpu64 (a->object_id) > grub_le_to_cpu64 (b->object_id))
>      return +1;
>  
>    if (a->type < b->type)
> @@ -289,9 +289,9 @@ key_cmp (const struct grub_btrfs_key *a,
>    if (a->type > b->type)
>      return +1;
>  
> -  if (grub_cpu_to_le64 (a->offset) < grub_cpu_to_le64 (b->offset))
> +  if (grub_le_to_cpu64 (a->offset) < grub_le_to_cpu64 (b->offset))
>      return -1;
> -  if (grub_cpu_to_le64 (a->offset) > grub_cpu_to_le64 (b->offset))
> +  if (grub_le_to_cpu64 (a->offset) > grub_le_to_cpu64 (b->offset))
>      return +1;
>    return 0;
>  }
> @@ -400,7 +400,8 @@ lower_bound (struct grub_btrfs_data *dat
>    grub_dprintf ("btrfs",
>  		"retrieving %" PRIxGRUB_UINT64_T
>  		" %x %" PRIxGRUB_UINT64_T "\n",
> -		key_in->object_id, key_in->type, key_in->offset);
> +		grub_le_to_cpu64 (key_in->object_id), key_in->type,
> +		grub_le_to_cpu64 (key_in->offset));
>  
>    while (1)
>      {
> @@ -430,8 +431,9 @@ lower_bound (struct grub_btrfs_data *dat
>  	      grub_dprintf ("btrfs",
>  			    "internal node (depth %d) %" PRIxGRUB_UINT64_T
>  			    " %x %" PRIxGRUB_UINT64_T "\n", depth,
> -			    node.key.object_id, node.key.type,
> -			    node.key.offset);
> +			    grub_le_to_cpu64 (node.key.object_id),
> +			    node.key.type,
> +			    grub_le_to_cpu64 (node.key.offset));
>  
>  	      if (key_cmp (&node.key, key_in) == 0)
>  		{
> @@ -482,7 +484,8 @@ lower_bound (struct grub_btrfs_data *dat
>  	    grub_dprintf ("btrfs",
>  			  "leaf (depth %d) %" PRIxGRUB_UINT64_T
>  			  " %x %" PRIxGRUB_UINT64_T "\n", depth,
> -			  leaf.key.object_id, leaf.key.type, leaf.key.offset);
> +			  grub_le_to_cpu64 (leaf.key.object_id), leaf.key.type,
> +			  grub_le_to_cpu64 (leaf.key.offset));
>  
>  	    if (key_cmp (&leaf.key, key_in) == 0)
>  	      {
> @@ -642,9 +645,9 @@ grub_btrfs_read_logical (struct grub_btr
>  	    * grub_le_to_cpu16 (chunk->nstripes);
>  	}
>  
> -      key_in.object_id = GRUB_BTRFS_OBJECT_ID_CHUNK;
> +      key_in.object_id = grub_cpu_to_le64 (GRUB_BTRFS_OBJECT_ID_CHUNK);
>        key_in.type = GRUB_BTRFS_ITEM_TYPE_CHUNK;
> -      key_in.offset = addr;
> +      key_in.offset = grub_cpu_to_le64 (addr);
>        err = lower_bound (data, &key_in, &key_out,
>  			 grub_le_to_cpu64 (data->sblock.chunk_tree),
>  			 &chaddr, &chsize, NULL);
> @@ -776,7 +779,7 @@ grub_btrfs_read_logical (struct grub_btr
>  		   With RAID5-like it will be more difficult.  */
>  		stripe += stripen + i;
>  
> -		paddr = stripe->offset + stripe_offset;
> +		paddr = grub_le_to_cpu64 (stripe->offset) + stripe_offset;
>  
>  		grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
>  			      "+0x%" PRIxGRUB_UINT64_T
> @@ -788,7 +791,7 @@ grub_btrfs_read_logical (struct grub_btr
>  			      grub_le_to_cpu16 (chunk->nstripes),
>  			      grub_le_to_cpu16 (chunk->nsubstripes),
>  			      grub_le_to_cpu64 (chunk->stripe_length),
> -			      stripen, stripe->offset);
> +			      stripen, grub_le_to_cpu64 (stripe->offset));
>  		grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T
>  			      " for laddr 0x%" PRIxGRUB_UINT64_T "\n", paddr,
>  			      addr);
> @@ -883,14 +886,14 @@ grub_btrfs_read_inode (struct grub_btrfs
>    grub_size_t elemsize;
>    grub_err_t err;
>  
> -  key_in.object_id = num;
> +  key_in.object_id = grub_cpu_to_le64 (num);
>    key_in.type = GRUB_BTRFS_ITEM_TYPE_INODE_ITEM;
>    key_in.offset = 0;
>  
>    err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, NULL);
>    if (err)
>      return err;
> -  if (num != key_out.object_id
> +  if (num != grub_le_to_cpu64 (key_out.object_id)
>        || key_out.type != GRUB_BTRFS_ITEM_TYPE_INODE_ITEM)
>      return grub_error (GRUB_ERR_BAD_FS, "inode not found");
>  
> @@ -990,14 +993,14 @@ grub_btrfs_extent_read (struct grub_btrf
>  	  grub_size_t elemsize;
>  
>  	  grub_free (data->extent);
> -	  key_in.object_id = ino;
> +	  key_in.object_id = grub_cpu_to_le64 (ino);
>  	  key_in.type = GRUB_BTRFS_ITEM_TYPE_EXTENT_ITEM;
>  	  key_in.offset = grub_cpu_to_le64 (pos);
>  	  err = lower_bound (data, &key_in, &key_out, tree,
>  			     &elemaddr, &elemsize, NULL);
>  	  if (err)
>  	    return -1;
> -	  if (key_out.object_id != ino
> +	  if (grub_le_to_cpu64 (key_out.object_id) != ino
>  	      || key_out.type != GRUB_BTRFS_ITEM_TYPE_EXTENT_ITEM)
>  	    {
>  	      grub_error (GRUB_ERR_BAD_FS, "extent not found");
> @@ -1174,7 +1177,7 @@ find_path (struct grub_btrfs_data *data,
>    unsigned symlinks_max = 32;
>  
>    *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
> -  *tree = data->sblock.root_tree;
> +  *tree = grub_le_to_cpu64 (data->sblock.root_tree);
>    key->object_id = data->sblock.root_dir_objectid;
>    key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
>    key->offset = 0;
> @@ -1292,7 +1295,8 @@ find_path (struct grub_btrfs_data *data,
>  	    }
>  
>  	  err = grub_btrfs_read_inode (data, &inode,
> -				       cdirel->key.object_id, *tree);
> +				       grub_le_to_cpu64 (cdirel->key.object_id),
> +				       *tree);
>  	  if (err)
>  	    {
>  	      grub_free (direl);
> @@ -1310,7 +1314,8 @@ find_path (struct grub_btrfs_data *data,
>  	      return grub_errno;
>  	    }
>  
> -	  if (grub_btrfs_extent_read (data, cdirel->key.object_id,
> +	  if (grub_btrfs_extent_read (data,
> +				      grub_le_to_cpu64 (cdirel->key.object_id),
>  				      *tree, 0, tmp,
>  				      grub_le_to_cpu64 (inode.size))
>  	      != (grub_ssize_t) grub_le_to_cpu64 (inode.size))
> @@ -1344,7 +1349,7 @@ find_path (struct grub_btrfs_data *data,
>  	  {
>  	    struct grub_btrfs_root_item ri;
>  	    err = lower_bound (data, &cdirel->key, &key_out,
> -			       data->sblock.root_tree,
> +			       grub_le_to_cpu64 (data->sblock.root_tree),
>  			       &elemaddr, &elemsize, NULL);
>  	    if (err)
>  	      {
> @@ -1372,7 +1377,7 @@ find_path (struct grub_btrfs_data *data,
>  	      }
>  	    key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
>  	    key->offset = 0;
> -	    key->object_id = GRUB_BTRFS_OBJECT_ID_CHUNK;
> +	    key->object_id = grub_cpu_to_le64 (GRUB_BTRFS_OBJECT_ID_CHUNK);
>  	    *tree = grub_le_to_cpu64 (ri.tree);
>  	    break;
>  	  }
> @@ -1487,14 +1492,15 @@ grub_btrfs_dir (grub_device_t device, co
>  	  char c;
>  	  struct grub_btrfs_inode inode;
>  	  struct grub_dirhook_info info;
> -	  err = grub_btrfs_read_inode (data, &inode, cdirel->key.object_id,
> +	  err = grub_btrfs_read_inode (data, &inode,
> +				       grub_le_to_cpu64 (cdirel->key.object_id),
>  				       tree);
>  	  grub_memset (&info, 0, sizeof (info));
>  	  if (err)
>  	    grub_errno = GRUB_ERR_NONE;
>  	  else
>  	    {
> -	      info.mtime = inode.mtime.sec;
> +	      info.mtime = grub_le_to_cpu64 (inode.mtime.sec);
>  	      info.mtimeset = 1;
>  	    }
>  	  c = cdirel->name[grub_le_to_cpu16 (cdirel->n)];
> @@ -1541,7 +1547,7 @@ grub_btrfs_open (struct grub_file *file,
>        return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a regular file"));
>      }
>  
> -  data->inode = key_in.object_id;
> +  data->inode = grub_le_to_cpu64 (key_in.object_id);
>    err = grub_btrfs_read_inode (data, &inode, data->inode, data->tree);
>    if (err)
>      {
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-31 20:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-25 13:36 [PATCH] Big endian fixes for btrfs Anton Blanchard
2012-03-25 13:47 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-03-25 21:10   ` Anton Blanchard
2012-03-25 21:29     ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-03-25 22:20       ` [PATCH v2] " Anton Blanchard
2012-03-31 20:14 ` [PATCH] " Vladimir 'φ-coder/phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.