* grub-core/fs/btrfs.c: Some code style fixes.

This commit is contained in:
Szymon Janc 2011-08-14 11:42:53 +02:00
parent b2d7e331e2
commit b6085f3236
2 changed files with 94 additions and 97 deletions

View file

@ -1,3 +1,7 @@
2011-08-14 Szymon Janc <szymon@janc.net.pl>
* grub-core/fs/btrfs.c: Some code style fixes.
2001-08-14 Szymon Janc <szymon@janc.net.pl>
Add helper functions for easier unaligned memory access.

View file

@ -160,7 +160,8 @@ struct grub_btrfs_leaf_descriptor
{
unsigned depth;
unsigned allocated;
struct {
struct
{
grub_disk_addr_t addr;
unsigned iter;
unsigned maxiter;
@ -219,8 +220,8 @@ struct grub_btrfs_extent_data
#define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100
static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2,
256 * 1048576 * 2,
1048576ULL * 1048576ULL * 2 };
256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2
};
static grub_err_t
grub_btrfs_read_logical (struct grub_btrfs_data *data,
@ -316,8 +317,8 @@ next (struct grub_btrfs_data *data,
for (; desc->depth > 0; desc->depth--)
{
desc->data[desc->depth - 1].iter++;
if (desc->data[desc->depth - 1].iter
< desc->data[desc->depth - 1].maxiter)
if (desc->data[desc->depth - 1].iter <
desc->data[desc->depth - 1].maxiter)
break;
}
if (desc->depth == 0)
@ -330,13 +331,13 @@ next (struct grub_btrfs_data *data,
err = grub_btrfs_read_logical (data, desc->data[desc->depth - 1].iter
* sizeof (node)
+ sizeof (struct btrfs_header)
+ desc->data[desc->depth - 1].addr, &node,
sizeof (node));
+ desc->data[desc->depth - 1].addr,
&node, sizeof (node));
if (err)
return -err;
err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr), &head,
sizeof (head));
err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr),
&head, sizeof (head));
if (err)
return -err;
@ -410,7 +411,8 @@ lower_bound (struct grub_btrfs_data *data,
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);
node.key.object_id, node.key.type,
node.key.offset);
if (key_cmp (&node.key, key_in) == 0)
{
@ -503,8 +505,7 @@ lower_bound (struct grub_btrfs_data *data,
}
static grub_device_t
find_device (struct grub_btrfs_data *data, grub_uint64_t id,
int do_rescan)
find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan)
{
grub_device_t dev_found = NULL;
auto int hook (const char *name);
@ -579,8 +580,7 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id,
}
static grub_err_t
grub_btrfs_read_logical (struct grub_btrfs_data *data,
grub_disk_addr_t addr,
grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
void *buf, grub_size_t size)
{
while (size > 0)
@ -602,19 +602,19 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
for (ptr = data->sblock.bootstrap_mapping;
ptr < data->sblock.bootstrap_mapping
+ sizeof (data->sblock.bootstrap_mapping)
- sizeof (struct grub_btrfs_key);
)
- sizeof (struct grub_btrfs_key);)
{
key = (struct grub_btrfs_key *) ptr;
if (key->type != GRUB_BTRFS_ITEM_TYPE_CHUNK)
break;
chunk = (struct grub_btrfs_chunk_item *) (key + 1);
grub_dprintf ("btrfs", "%" PRIxGRUB_UINT64_T " %" PRIxGRUB_UINT64_T " \n",
grub_dprintf ("btrfs",
"%" PRIxGRUB_UINT64_T " %" PRIxGRUB_UINT64_T " \n",
grub_le_to_cpu64 (key->offset),
grub_le_to_cpu64 (chunk->size));
if (grub_le_to_cpu64 (key->offset) <= addr
&& addr < grub_le_to_cpu64 (key->offset)
+ grub_le_to_cpu64 (chunk->size))
&& addr <
grub_le_to_cpu64 (key->offset) + grub_le_to_cpu64 (chunk->size))
goto chunk_found;
ptr += sizeof (*key) + sizeof (*chunk)
+ sizeof (struct grub_btrfs_chunk_stripe)
@ -707,8 +707,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
high = grub_divmod64 (middle, grub_le_to_cpu16 (chunk->nstripes),
&stripen);
stripe_offset = low + grub_le_to_cpu64 (chunk->stripe_length)
* high;
stripe_offset =
low + grub_le_to_cpu64 (chunk->stripe_length) * high;
csize = grub_le_to_cpu64 (chunk->stripe_length) - low;
break;
}
@ -759,7 +759,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
paddr = stripe->offset + stripe_offset;
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
"+0x%" PRIxGRUB_UINT64_T " (%d stripes (%d substripes) of %"
"+0x%" PRIxGRUB_UINT64_T
" (%d stripes (%d substripes) of %"
PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT64_T
" maps to 0x%" PRIxGRUB_UINT64_T "\n",
grub_le_to_cpu64 (key->offset),
@ -866,8 +867,7 @@ grub_btrfs_read_inode (struct grub_btrfs_data *data,
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);
err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, NULL);
if (err)
return err;
if (num != key_out.object_id
@ -917,19 +917,17 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
if (!data->extent)
return grub_errno;
err = grub_btrfs_read_logical (data, elemaddr,
data->extent, elemsize);
err = grub_btrfs_read_logical (data, elemaddr, data->extent,
elemsize);
if (err)
return err;
data->extend = data->extstart
+ grub_le_to_cpu64 (data->extent->size);
data->extend = data->extstart + grub_le_to_cpu64 (data->extent->size);
if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR
&& (char *) &data->extent + elemsize
>= (char *) &data->extent->filled
+ sizeof (data->extent->filled))
data->extend = data->extstart
+ grub_le_to_cpu64 (data->extent->filled);
&& (char *) &data->extent + elemsize >=
(char *) &data->extent->filled + sizeof (data->extent->filled))
data->extend =
data->extstart + grub_le_to_cpu64 (data->extent->filled);
grub_dprintf ("btrfs", "extent 0x%" PRIxGRUB_UINT64_T "+0x%"
PRIxGRUB_UINT64_T " (0x%"
@ -966,8 +964,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
if (data->extent->encoding)
{
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"encoding not supported");
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "encoding not supported");
return -1;
}
@ -1008,8 +1005,8 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
grub_free (tmp);
return -1;
}
if (grub_zlib_decompress (tmp, zsize, extoff
+ grub_le_to_cpu64 (data->extent->offset),
if (grub_zlib_decompress (tmp, zsize, extoff +
grub_le_to_cpu64 (data->extent->offset),
buf, csize) != (grub_ssize_t) csize)
{
grub_free (tmp);
@ -1021,8 +1018,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
err = grub_btrfs_read_logical (data,
grub_le_to_cpu64 (data->extent->laddr)
+ grub_le_to_cpu64 (data->extent->offset)
+ extoff,
buf, csize);
+ extoff, buf, csize);
if (err)
return -1;
break;
@ -1097,8 +1093,8 @@ find_path (struct grub_btrfs_data *data,
key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
key->offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen));
err = lower_bound (data, key, &key_out, *tree,
&elemaddr, &elemsize, NULL);
err = lower_bound (data, key, &key_out, *tree, &elemaddr, &elemsize,
NULL);
if (err)
{
grub_free (direl);
@ -1247,8 +1243,7 @@ find_path (struct grub_btrfs_data *data,
grub_free (origpath);
return err;
}
err = grub_btrfs_read_logical (data, elemaddr,
&ri, sizeof (ri));
err = grub_btrfs_read_logical (data, elemaddr, &ri, sizeof (ri));
if (err)
{
grub_free (direl);
@ -1314,8 +1309,7 @@ grub_btrfs_dir (grub_device_t device, const char *path,
if (type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
err = lower_bound (data, &key_in, &key_out, tree,
&elemaddr, &elemsize, &desc);
err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, &desc);
if (err)
return err;
if (key_out.type != GRUB_BTRFS_ITEM_TYPE_DIR_ITEM
@ -1492,8 +1486,7 @@ grub_btrfs_label (grub_device_t device, char **label)
return grub_errno;
}
static struct grub_fs grub_btrfs_fs =
{
static struct grub_fs grub_btrfs_fs = {
.name = "btrfs",
.dir = grub_btrfs_dir,
.open = grub_btrfs_open,