From: Anton Blanchard <anton@samba.org>
To: grub-devel@gnu.org
Subject: [PATCH v2] Big endian fixes for btrfs
Date: Mon, 26 Mar 2012 09:20:40 +1100 [thread overview]
Message-ID: <20120326092040.5d253958@kryten> (raw)
In-Reply-To: <4F6F8E33.4030700@gmail.com>
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)];
next prev parent reply other threads:[~2012-03-25 22:20 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 ` Anton Blanchard [this message]
2012-03-31 20:14 ` Vladimir 'φ-coder/phcoder' Serbinenko
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=20120326092040.5d253958@kryten \
--to=anton@samba.org \
--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.