* grub-core/fs/btrfs.c: Some code style fixes.
This commit is contained in:
parent
b2d7e331e2
commit
b6085f3236
2 changed files with 94 additions and 97 deletions
|
@ -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>
|
2001-08-14 Szymon Janc <szymon@janc.net.pl>
|
||||||
|
|
||||||
Add helper functions for easier unaligned memory access.
|
Add helper functions for easier unaligned memory access.
|
||||||
|
|
|
@ -160,7 +160,8 @@ struct grub_btrfs_leaf_descriptor
|
||||||
{
|
{
|
||||||
unsigned depth;
|
unsigned depth;
|
||||||
unsigned allocated;
|
unsigned allocated;
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
grub_disk_addr_t addr;
|
grub_disk_addr_t addr;
|
||||||
unsigned iter;
|
unsigned iter;
|
||||||
unsigned maxiter;
|
unsigned maxiter;
|
||||||
|
@ -219,8 +220,8 @@ struct grub_btrfs_extent_data
|
||||||
#define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100
|
#define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100
|
||||||
|
|
||||||
static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2,
|
static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2,
|
||||||
256 * 1048576 * 2,
|
256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2
|
||||||
1048576ULL * 1048576ULL * 2 };
|
};
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
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--)
|
for (; desc->depth > 0; desc->depth--)
|
||||||
{
|
{
|
||||||
desc->data[desc->depth - 1].iter++;
|
desc->data[desc->depth - 1].iter++;
|
||||||
if (desc->data[desc->depth - 1].iter
|
if (desc->data[desc->depth - 1].iter <
|
||||||
< desc->data[desc->depth - 1].maxiter)
|
desc->data[desc->depth - 1].maxiter)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (desc->depth == 0)
|
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
|
err = grub_btrfs_read_logical (data, desc->data[desc->depth - 1].iter
|
||||||
* sizeof (node)
|
* sizeof (node)
|
||||||
+ sizeof (struct btrfs_header)
|
+ sizeof (struct btrfs_header)
|
||||||
+ desc->data[desc->depth - 1].addr, &node,
|
+ desc->data[desc->depth - 1].addr,
|
||||||
sizeof (node));
|
&node, sizeof (node));
|
||||||
if (err)
|
if (err)
|
||||||
return -err;
|
return -err;
|
||||||
|
|
||||||
err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr), &head,
|
err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr),
|
||||||
sizeof (head));
|
&head, sizeof (head));
|
||||||
if (err)
|
if (err)
|
||||||
return -err;
|
return -err;
|
||||||
|
|
||||||
|
@ -410,7 +411,8 @@ lower_bound (struct grub_btrfs_data *data,
|
||||||
grub_dprintf ("btrfs",
|
grub_dprintf ("btrfs",
|
||||||
"internal node (depth %d) %" PRIxGRUB_UINT64_T
|
"internal node (depth %d) %" PRIxGRUB_UINT64_T
|
||||||
" %x %" PRIxGRUB_UINT64_T "\n", depth,
|
" %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)
|
if (key_cmp (&node.key, key_in) == 0)
|
||||||
{
|
{
|
||||||
|
@ -503,8 +505,7 @@ lower_bound (struct grub_btrfs_data *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
static grub_device_t
|
static grub_device_t
|
||||||
find_device (struct grub_btrfs_data *data, grub_uint64_t id,
|
find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan)
|
||||||
int do_rescan)
|
|
||||||
{
|
{
|
||||||
grub_device_t dev_found = NULL;
|
grub_device_t dev_found = NULL;
|
||||||
auto int hook (const char *name);
|
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
|
static grub_err_t
|
||||||
grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
|
||||||
grub_disk_addr_t addr,
|
|
||||||
void *buf, grub_size_t size)
|
void *buf, grub_size_t size)
|
||||||
{
|
{
|
||||||
while (size > 0)
|
while (size > 0)
|
||||||
|
@ -602,19 +602,19 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
||||||
for (ptr = data->sblock.bootstrap_mapping;
|
for (ptr = data->sblock.bootstrap_mapping;
|
||||||
ptr < data->sblock.bootstrap_mapping
|
ptr < data->sblock.bootstrap_mapping
|
||||||
+ sizeof (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;
|
key = (struct grub_btrfs_key *) ptr;
|
||||||
if (key->type != GRUB_BTRFS_ITEM_TYPE_CHUNK)
|
if (key->type != GRUB_BTRFS_ITEM_TYPE_CHUNK)
|
||||||
break;
|
break;
|
||||||
chunk = (struct grub_btrfs_chunk_item *) (key + 1);
|
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 (key->offset),
|
||||||
grub_le_to_cpu64 (chunk->size));
|
grub_le_to_cpu64 (chunk->size));
|
||||||
if (grub_le_to_cpu64 (key->offset) <= addr
|
if (grub_le_to_cpu64 (key->offset) <= addr
|
||||||
&& addr < grub_le_to_cpu64 (key->offset)
|
&& addr <
|
||||||
+ grub_le_to_cpu64 (chunk->size))
|
grub_le_to_cpu64 (key->offset) + grub_le_to_cpu64 (chunk->size))
|
||||||
goto chunk_found;
|
goto chunk_found;
|
||||||
ptr += sizeof (*key) + sizeof (*chunk)
|
ptr += sizeof (*key) + sizeof (*chunk)
|
||||||
+ sizeof (struct grub_btrfs_chunk_stripe)
|
+ 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),
|
high = grub_divmod64 (middle, grub_le_to_cpu16 (chunk->nstripes),
|
||||||
&stripen);
|
&stripen);
|
||||||
stripe_offset = low + grub_le_to_cpu64 (chunk->stripe_length)
|
stripe_offset =
|
||||||
* high;
|
low + grub_le_to_cpu64 (chunk->stripe_length) * high;
|
||||||
csize = grub_le_to_cpu64 (chunk->stripe_length) - low;
|
csize = grub_le_to_cpu64 (chunk->stripe_length) - low;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -759,7 +759,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
||||||
paddr = stripe->offset + stripe_offset;
|
paddr = stripe->offset + stripe_offset;
|
||||||
|
|
||||||
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
|
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
|
PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT64_T
|
||||||
" maps to 0x%" PRIxGRUB_UINT64_T "\n",
|
" maps to 0x%" PRIxGRUB_UINT64_T "\n",
|
||||||
grub_le_to_cpu64 (key->offset),
|
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.type = GRUB_BTRFS_ITEM_TYPE_INODE_ITEM;
|
||||||
key_in.offset = 0;
|
key_in.offset = 0;
|
||||||
|
|
||||||
err = lower_bound (data, &key_in, &key_out, tree,
|
err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, NULL);
|
||||||
&elemaddr, &elemsize, NULL);
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
if (num != key_out.object_id
|
if (num != key_out.object_id
|
||||||
|
@ -917,19 +917,17 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
if (!data->extent)
|
if (!data->extent)
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
|
|
||||||
err = grub_btrfs_read_logical (data, elemaddr,
|
err = grub_btrfs_read_logical (data, elemaddr, data->extent,
|
||||||
data->extent, elemsize);
|
elemsize);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
data->extend = data->extstart
|
data->extend = data->extstart + grub_le_to_cpu64 (data->extent->size);
|
||||||
+ grub_le_to_cpu64 (data->extent->size);
|
|
||||||
if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR
|
if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR
|
||||||
&& (char *) &data->extent + elemsize
|
&& (char *) &data->extent + elemsize >=
|
||||||
>= (char *) &data->extent->filled
|
(char *) &data->extent->filled + sizeof (data->extent->filled))
|
||||||
+ sizeof (data->extent->filled))
|
data->extend =
|
||||||
data->extend = data->extstart
|
data->extstart + grub_le_to_cpu64 (data->extent->filled);
|
||||||
+ grub_le_to_cpu64 (data->extent->filled);
|
|
||||||
|
|
||||||
grub_dprintf ("btrfs", "extent 0x%" PRIxGRUB_UINT64_T "+0x%"
|
grub_dprintf ("btrfs", "extent 0x%" PRIxGRUB_UINT64_T "+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)
|
if (data->extent->encoding)
|
||||||
{
|
{
|
||||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "encoding not supported");
|
||||||
"encoding not supported");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1008,8 +1005,8 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
grub_free (tmp);
|
grub_free (tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (grub_zlib_decompress (tmp, zsize, extoff
|
if (grub_zlib_decompress (tmp, zsize, extoff +
|
||||||
+ grub_le_to_cpu64 (data->extent->offset),
|
grub_le_to_cpu64 (data->extent->offset),
|
||||||
buf, csize) != (grub_ssize_t) csize)
|
buf, csize) != (grub_ssize_t) csize)
|
||||||
{
|
{
|
||||||
grub_free (tmp);
|
grub_free (tmp);
|
||||||
|
@ -1021,8 +1018,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
err = grub_btrfs_read_logical (data,
|
err = grub_btrfs_read_logical (data,
|
||||||
grub_le_to_cpu64 (data->extent->laddr)
|
grub_le_to_cpu64 (data->extent->laddr)
|
||||||
+ grub_le_to_cpu64 (data->extent->offset)
|
+ grub_le_to_cpu64 (data->extent->offset)
|
||||||
+ extoff,
|
+ extoff, buf, csize);
|
||||||
buf, csize);
|
|
||||||
if (err)
|
if (err)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
@ -1097,8 +1093,8 @@ find_path (struct grub_btrfs_data *data,
|
||||||
key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
||||||
key->offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen));
|
key->offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen));
|
||||||
|
|
||||||
err = lower_bound (data, key, &key_out, *tree,
|
err = lower_bound (data, key, &key_out, *tree, &elemaddr, &elemsize,
|
||||||
&elemaddr, &elemsize, NULL);
|
NULL);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
grub_free (direl);
|
grub_free (direl);
|
||||||
|
@ -1247,8 +1243,7 @@ find_path (struct grub_btrfs_data *data,
|
||||||
grub_free (origpath);
|
grub_free (origpath);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = grub_btrfs_read_logical (data, elemaddr,
|
err = grub_btrfs_read_logical (data, elemaddr, &ri, sizeof (ri));
|
||||||
&ri, sizeof (ri));
|
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
grub_free (direl);
|
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)
|
if (type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
|
||||||
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
||||||
|
|
||||||
err = lower_bound (data, &key_in, &key_out, tree,
|
err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, &desc);
|
||||||
&elemaddr, &elemsize, &desc);
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
if (key_out.type != GRUB_BTRFS_ITEM_TYPE_DIR_ITEM
|
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;
|
return grub_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct grub_fs grub_btrfs_fs =
|
static struct grub_fs grub_btrfs_fs = {
|
||||||
{
|
|
||||||
.name = "btrfs",
|
.name = "btrfs",
|
||||||
.dir = grub_btrfs_dir,
|
.dir = grub_btrfs_dir,
|
||||||
.open = grub_btrfs_open,
|
.open = grub_btrfs_open,
|
||||||
|
|
Loading…
Reference in a new issue