* 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> 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.

View file

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