All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH] Big endian fixes for btrfs
Date: Sat, 31 Mar 2012 22:14:54 +0200	[thread overview]
Message-ID: <4F7765BE.6020102@gmail.com> (raw)
In-Reply-To: <20120326003636.38c4fdd5@kryten>

[-- 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 --]

      parent reply	other threads:[~2012-03-31 20:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F7765BE.6020102@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.