* 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>
|
||||
|
||||
Add helper functions for easier unaligned memory access.
|
||||
|
|
|
@ -160,7 +160,8 @@ struct grub_btrfs_leaf_descriptor
|
|||
{
|
||||
unsigned depth;
|
||||
unsigned allocated;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
grub_disk_addr_t addr;
|
||||
unsigned iter;
|
||||
unsigned maxiter;
|
||||
|
@ -179,7 +180,7 @@ struct grub_btrfs_time
|
|||
{
|
||||
grub_int64_t sec;
|
||||
grub_uint32_t nanosec;
|
||||
} __attribute__ ((aligned(4)));
|
||||
} __attribute__ ((aligned (4)));
|
||||
|
||||
struct grub_btrfs_inode
|
||||
{
|
||||
|
@ -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,
|
||||
|
@ -307,7 +308,7 @@ save_ref (struct grub_btrfs_leaf_descriptor *desc,
|
|||
static int
|
||||
next (struct grub_btrfs_data *data,
|
||||
struct grub_btrfs_leaf_descriptor *desc,
|
||||
grub_disk_addr_t *outaddr, grub_size_t *outsize,
|
||||
grub_disk_addr_t * outaddr, grub_size_t * outsize,
|
||||
struct grub_btrfs_key *key_out)
|
||||
{
|
||||
grub_err_t err;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -362,7 +363,7 @@ lower_bound (struct grub_btrfs_data *data,
|
|||
const struct grub_btrfs_key *key_in,
|
||||
struct grub_btrfs_key *key_out,
|
||||
grub_disk_addr_t root,
|
||||
grub_disk_addr_t *outaddr, grub_size_t *outsize,
|
||||
grub_disk_addr_t * outaddr, grub_size_t * outsize,
|
||||
struct grub_btrfs_leaf_descriptor *desc)
|
||||
{
|
||||
grub_disk_addr_t addr = root;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -465,7 +467,7 @@ lower_bound (struct grub_btrfs_data *data,
|
|||
|
||||
if (key_cmp (&leaf.key, key_in) == 0)
|
||||
{
|
||||
grub_memcpy (key_out, &leaf.key, sizeof(*key_out));
|
||||
grub_memcpy (key_out, &leaf.key, sizeof (*key_out));
|
||||
*outsize = grub_le_to_cpu32 (leaf.size);
|
||||
*outaddr = addr + grub_le_to_cpu32 (leaf.offset);
|
||||
if (desc)
|
||||
|
@ -483,7 +485,7 @@ lower_bound (struct grub_btrfs_data *data,
|
|||
|
||||
if (have_last)
|
||||
{
|
||||
grub_memcpy (key_out, &leaf_last.key, sizeof(*key_out));
|
||||
grub_memcpy (key_out, &leaf_last.key, sizeof (*key_out));
|
||||
*outsize = grub_le_to_cpu32 (leaf_last.size);
|
||||
*outaddr = addr + grub_le_to_cpu32 (leaf_last.offset);
|
||||
if (desc)
|
||||
|
@ -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),
|
||||
|
@ -769,7 +770,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
grub_le_to_cpu64 (chunk->stripe_length),
|
||||
stripen, stripe->offset);
|
||||
grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T
|
||||
" for laddr 0x%" PRIxGRUB_UINT64_T"\n", paddr,
|
||||
" for laddr 0x%" PRIxGRUB_UINT64_T "\n", paddr,
|
||||
addr);
|
||||
|
||||
dev = find_device (data, stripe->device_id, j);
|
||||
|
@ -815,7 +816,7 @@ grub_btrfs_mount (grub_device_t dev)
|
|||
}
|
||||
|
||||
data = grub_zalloc (sizeof (*data));
|
||||
if (! data)
|
||||
if (!data)
|
||||
return NULL;
|
||||
|
||||
err = read_sblock (dev->disk, &data->sblock);
|
||||
|
@ -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;
|
||||
|
@ -1041,7 +1037,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
|||
static grub_err_t
|
||||
find_path (struct grub_btrfs_data *data,
|
||||
const char *path, struct grub_btrfs_key *key,
|
||||
grub_uint64_t *tree, grub_uint8_t *type)
|
||||
grub_uint64_t * tree, grub_uint8_t * type)
|
||||
{
|
||||
const char *slash = path;
|
||||
grub_err_t err;
|
||||
|
@ -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);
|
||||
|
@ -1291,7 +1286,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
static grub_err_t
|
||||
grub_btrfs_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
const struct grub_dirhook_info * info))
|
||||
{
|
||||
struct grub_btrfs_data *data = grub_btrfs_mount (device);
|
||||
struct grub_btrfs_key key_in, key_out;
|
||||
|
@ -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
|
||||
|
@ -1384,7 +1378,7 @@ grub_btrfs_dir (grub_device_t device, const char *path,
|
|||
}
|
||||
while (r > 0);
|
||||
|
||||
out:
|
||||
out:
|
||||
grub_free (direl);
|
||||
|
||||
free_iterator (&desc);
|
||||
|
@ -1456,7 +1450,7 @@ grub_btrfs_uuid (grub_device_t device, char **uuid)
|
|||
*uuid = NULL;
|
||||
|
||||
data = grub_btrfs_mount (device);
|
||||
if (! data)
|
||||
if (!data)
|
||||
return grub_errno;
|
||||
|
||||
*uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
|
||||
|
@ -1482,7 +1476,7 @@ grub_btrfs_label (grub_device_t device, char **label)
|
|||
*label = NULL;
|
||||
|
||||
data = grub_btrfs_mount (device);
|
||||
if (! data)
|
||||
if (!data)
|
||||
return grub_errno;
|
||||
|
||||
*label = grub_strndup (data->sblock.label, sizeof (data->sblock.label));
|
||||
|
@ -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,
|
||||
|
@ -1504,14 +1497,14 @@ static struct grub_fs grub_btrfs_fs =
|
|||
#ifdef GRUB_UTIL
|
||||
.reserved_first_sector = 1,
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
GRUB_MOD_INIT(btrfs)
|
||||
GRUB_MOD_INIT (btrfs)
|
||||
{
|
||||
grub_fs_register (&grub_btrfs_fs);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(btrfs)
|
||||
GRUB_MOD_FINI (btrfs)
|
||||
{
|
||||
grub_fs_unregister (&grub_btrfs_fs);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue