* grub-core/fs/bfs.c: Run indent.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-10-30 13:27:53 +01:00
parent 5825b3794b
commit c4a1628f67
2 changed files with 115 additions and 109 deletions

View file

@ -1,3 +1,7 @@
2011-10-30 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/bfs.c: Run indent.
2011-10-30 Vladimir Serbinenko <phcoder@gmail.com> 2011-10-30 Vladimir Serbinenko <phcoder@gmail.com>
BFS implementation based on the specification. BFS implementation based on the specification.

View file

@ -141,15 +141,12 @@ static grub_err_t
read_extent (grub_disk_t disk, read_extent (grub_disk_t disk,
const struct grub_bfs_superblock *sb, const struct grub_bfs_superblock *sb,
const struct grub_bfs_extent *in, const struct grub_bfs_extent *in,
grub_off_t off, grub_off_t off, grub_off_t byteoff, void *buf, grub_size_t len)
grub_off_t byteoff,
void *buf, grub_size_t len)
{ {
return grub_disk_read (disk, ((grub_bfs_to_cpu32 (in->ag) return grub_disk_read (disk, ((grub_bfs_to_cpu32 (in->ag)
<< grub_bfs_to_cpu32 (sb->log2_ag_size)) << grub_bfs_to_cpu32 (sb->log2_ag_size))
+ grub_bfs_to_cpu16 (in->start) + off) + grub_bfs_to_cpu16 (in->start) + off)
<< (grub_bfs_to_cpu32 (sb->log2_bsize) - 9) << (grub_bfs_to_cpu32 (sb->log2_bsize) - 9), byteoff,
, byteoff,
len, buf); len, buf);
} }
@ -159,13 +156,15 @@ read_bfs_file (grub_disk_t disk,
const struct grub_bfs_inode *ino, const struct grub_bfs_inode *ino,
grub_off_t off, void *buf, grub_size_t len, grub_off_t off, void *buf, grub_size_t len,
void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
unsigned offset, unsigned length)) unsigned offset,
unsigned length))
{ {
if (len == 0) if (len == 0)
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
if (off + len > grub_bfs_to_cpu64 (ino->size)) if (off + len > grub_bfs_to_cpu64 (ino->size))
return grub_error (GRUB_ERR_OUT_OF_RANGE, "attempt to read past the end of file"); return grub_error (GRUB_ERR_OUT_OF_RANGE,
"attempt to read past the end of file");
if (off < grub_bfs_to_cpu64 (ino->max_direct_range)) if (off < grub_bfs_to_cpu64 (ino->max_direct_range))
{ {
@ -210,8 +209,7 @@ read_bfs_file (grub_disk_t disk,
grub_err_t err; grub_err_t err;
grub_uint64_t pos = grub_bfs_to_cpu64 (ino->max_direct_range); grub_uint64_t pos = grub_bfs_to_cpu64 (ino->max_direct_range);
nentries = (grub_bfs_to_cpu16 (ino->indirect.len) nentries = (grub_bfs_to_cpu16 (ino->indirect.len)
<< (grub_bfs_to_cpu32 (sb->log2_bsize) << (grub_bfs_to_cpu32 (sb->log2_bsize) - LOG_EXTENT_SIZE));
- LOG_EXTENT_SIZE));
entries = grub_malloc (nentries << LOG_EXTENT_SIZE); entries = grub_malloc (nentries << LOG_EXTENT_SIZE);
if (!entries) if (!entries)
return grub_errno; return grub_errno;
@ -260,8 +258,7 @@ read_bfs_file (grub_disk_t disk,
grub_off_t last_l1n = ~0ULL; grub_off_t last_l1n = ~0ULL;
grub_err_t err; grub_err_t err;
nl1_entries = (grub_bfs_to_cpu16 (ino->double_indirect.len) nl1_entries = (grub_bfs_to_cpu16 (ino->double_indirect.len)
<< (grub_bfs_to_cpu32 (sb->log2_bsize) << (grub_bfs_to_cpu32 (sb->log2_bsize) - LOG_EXTENT_SIZE));
- LOG_EXTENT_SIZE));
l1_entries = grub_malloc (nl1_entries << LOG_EXTENT_SIZE); l1_entries = grub_malloc (nl1_entries << LOG_EXTENT_SIZE);
if (!l1_entries) if (!l1_entries)
return grub_errno; return grub_errno;
@ -295,11 +292,11 @@ read_bfs_file (grub_disk_t disk,
l2n = ((double_indirect_offset >> (grub_bfs_to_cpu32 (sb->log2_bsize) l2n = ((double_indirect_offset >> (grub_bfs_to_cpu32 (sb->log2_bsize)
+ DOUBLE_INDIRECT_SHIFT)) + DOUBLE_INDIRECT_SHIFT))
& ((1 << (grub_bfs_to_cpu32 (sb->log2_bsize) - LOG_EXTENT_SIZE & ((1 << (grub_bfs_to_cpu32 (sb->log2_bsize) - LOG_EXTENT_SIZE
+ DOUBLE_INDIRECT_SHIFT)) + DOUBLE_INDIRECT_SHIFT)) - 1));
- 1)); l1n =
l1n = (double_indirect_offset >> (2 * grub_bfs_to_cpu32 (sb->log2_bsize) (double_indirect_offset >>
- LOG_EXTENT_SIZE (2 * grub_bfs_to_cpu32 (sb->log2_bsize) - LOG_EXTENT_SIZE +
+ 2 * DOUBLE_INDIRECT_SHIFT)); 2 * DOUBLE_INDIRECT_SHIFT));
if (l1n > nl1_entries) if (l1n > nl1_entries)
{ {
grub_free (l1_entries); grub_free (l1_entries);
@ -383,9 +380,10 @@ iterate_in_b_tree (grub_disk_t disk,
if (err) if (err)
return 0; return 0;
err = read_bfs_file (disk, sb, ino, node_off err = read_bfs_file (disk, sb, ino, node_off
+ ALIGN_UP (sizeof (node) + grub_bfs_to_cpu16 (node.total_key_len), + ALIGN_UP (sizeof (node) +
8) grub_bfs_to_cpu16 (node.total_key_len),
+ grub_bfs_to_cpu16 (node.count_keys) * 2, 8) +
grub_bfs_to_cpu16 (node.count_keys) * 2,
&key_value, sizeof (grub_uint64_t), 0); &key_value, sizeof (grub_uint64_t), 0);
if (err) if (err)
return 0; return 0;
@ -406,24 +404,28 @@ iterate_in_b_tree (grub_disk_t disk,
unsigned i; unsigned i;
grub_uint16_t start = 0, end = 0; grub_uint16_t start = 0, end = 0;
err = read_bfs_file (disk, sb, ino, node_off + sizeof (node), key_data, err =
grub_bfs_to_cpu16 (node.total_key_len), 0); read_bfs_file (disk, sb, ino, node_off + sizeof (node), key_data,
grub_bfs_to_cpu16 (node.total_key_len), 0);
if (err) if (err)
return 0; return 0;
key_data[grub_bfs_to_cpu16 (node.total_key_len)] = 0; key_data[grub_bfs_to_cpu16 (node.total_key_len)] = 0;
err = read_bfs_file (disk, sb, ino, node_off err = read_bfs_file (disk, sb, ino, node_off
+ ALIGN_UP (sizeof (node) + grub_bfs_to_cpu16 (node.total_key_len), + ALIGN_UP (sizeof (node) +
8), grub_bfs_to_cpu16 (node.
keylen_idx, grub_bfs_to_cpu16 (node.count_keys) total_key_len),
* 2, 0); 8), keylen_idx,
grub_bfs_to_cpu16 (node.count_keys) * 2, 0);
if (err) if (err)
return 0; return 0;
err = read_bfs_file (disk, sb, ino, node_off err = read_bfs_file (disk, sb, ino, node_off
+ ALIGN_UP (sizeof (node) + grub_bfs_to_cpu16 (node.total_key_len), + ALIGN_UP (sizeof (node) +
8) grub_bfs_to_cpu16 (node.
+ grub_bfs_to_cpu16 (node.count_keys) * 2, total_key_len),
key_values, grub_bfs_to_cpu16 (node.count_keys) 8) +
* 8, 0); grub_bfs_to_cpu16 (node.count_keys) * 2,
key_values,
grub_bfs_to_cpu16 (node.count_keys) * 8, 0);
if (err) if (err)
return 0; return 0;
@ -449,7 +451,7 @@ static grub_err_t
find_in_b_tree (grub_disk_t disk, find_in_b_tree (grub_disk_t disk,
const struct grub_bfs_superblock *sb, const struct grub_bfs_superblock *sb,
const struct grub_bfs_inode *ino, const char *name, const struct grub_bfs_inode *ino, const char *name,
grub_uint64_t *res) grub_uint64_t * res)
{ {
struct grub_bfs_btree_header head; struct grub_bfs_btree_header head;
grub_err_t err; grub_err_t err;
@ -477,26 +479,28 @@ find_in_b_tree (grub_disk_t disk,
grub_uint64_t key_values[grub_bfs_to_cpu16 (node.count_keys)]; grub_uint64_t key_values[grub_bfs_to_cpu16 (node.count_keys)];
unsigned i; unsigned i;
grub_uint16_t start = 0, end = 0; grub_uint16_t start = 0, end = 0;
err = read_bfs_file (disk, sb, ino, node_off + sizeof (node), key_data, err =
grub_bfs_to_cpu16 (node.total_key_len), 0); read_bfs_file (disk, sb, ino, node_off + sizeof (node), key_data,
grub_bfs_to_cpu16 (node.total_key_len), 0);
if (err) if (err)
return err; return err;
key_data[grub_bfs_to_cpu16 (node.total_key_len)] = 0; key_data[grub_bfs_to_cpu16 (node.total_key_len)] = 0;
err = read_bfs_file (disk, sb, ino, node_off err = read_bfs_file (disk, sb, ino, node_off
+ +
ALIGN_UP (sizeof (node) +grub_bfs_to_cpu16 (node.total_key_len), ALIGN_UP (sizeof (node) +
8), grub_bfs_to_cpu16 (node.total_key_len),
keylen_idx, grub_bfs_to_cpu16 (node.count_keys) 8), keylen_idx,
* 2, 0); grub_bfs_to_cpu16 (node.count_keys) * 2, 0);
if (err) if (err)
return err; return err;
err = read_bfs_file (disk, sb, ino, node_off err = read_bfs_file (disk, sb, ino, node_off
+ ALIGN_UP (sizeof (node) +
+ ALIGN_UP (sizeof (node) + grub_bfs_to_cpu16 (node.total_key_len), grub_bfs_to_cpu16 (node.
8) total_key_len),
+ grub_bfs_to_cpu16 (node.count_keys) * 2, 8) +
key_values, grub_bfs_to_cpu16 (node.count_keys) grub_bfs_to_cpu16 (node.count_keys) * 2,
* 8, 0); key_values,
grub_bfs_to_cpu16 (node.count_keys) * 8, 0);
if (err) if (err)
return err; return err;
@ -544,8 +548,7 @@ find_in_b_tree (grub_disk_t disk,
static grub_err_t static grub_err_t
hop_level (grub_disk_t disk, hop_level (grub_disk_t disk,
const struct grub_bfs_superblock *sb, const struct grub_bfs_superblock *sb,
struct grub_bfs_inode *ino, struct grub_bfs_inode *ino, const char *name)
const char *name)
{ {
grub_err_t err; grub_err_t err;
grub_uint64_t res; grub_uint64_t res;
@ -564,13 +567,13 @@ hop_level (grub_disk_t disk,
static grub_err_t static grub_err_t
find_file (const char *path, grub_disk_t disk, find_file (const char *path, grub_disk_t disk,
const struct grub_bfs_superblock *sb, const struct grub_bfs_superblock *sb, struct grub_bfs_inode *ino)
struct grub_bfs_inode *ino)
{ {
char *ptr, *ptr2; char *ptr, *ptr2;
char *alloc = NULL; char *alloc = NULL;
grub_err_t err; grub_err_t err;
union { union
{
struct grub_bfs_inode ino; struct grub_bfs_inode ino;
grub_uint8_t raw[grub_bfs_to_cpu32 (sb->bsize)]; grub_uint8_t raw[grub_bfs_to_cpu32 (sb->bsize)];
} old_ino; } old_ino;
@ -619,7 +622,6 @@ find_file (const char *path, grub_disk_t disk,
{ {
grub_size_t symsize = grub_bfs_to_cpu64 (ino->size); grub_size_t symsize = grub_bfs_to_cpu64 (ino->size);
alloc = grub_malloc ((ptr2 ? grub_strlen (ptr2) : 0) alloc = grub_malloc ((ptr2 ? grub_strlen (ptr2) : 0)
+ symsize + 1); + symsize + 1);
if (!alloc) if (!alloc)
{ {
@ -627,8 +629,7 @@ find_file (const char *path, grub_disk_t disk,
return grub_errno; return grub_errno;
} }
grub_free (old_alloc); grub_free (old_alloc);
err = read_bfs_file (disk, sb, ino, err = read_bfs_file (disk, sb, ino, 0, alloc, symsize, 0);
0, alloc, symsize, 0);
if (err) if (err)
{ {
grub_free (alloc); grub_free (alloc);
@ -653,7 +654,7 @@ find_file (const char *path, grub_disk_t disk,
if (alloc[0] == '/') if (alloc[0] == '/')
{ {
err = read_extent (disk, sb, &sb->root_dir, 0, 0, ino, err = read_extent (disk, sb, &sb->root_dir, 0, 0, ino,
grub_bfs_to_cpu32 (sb->bsize)); grub_bfs_to_cpu32 (sb->bsize));
if (err) if (err)
{ {
grub_free (alloc); grub_free (alloc);
@ -683,8 +684,7 @@ static grub_err_t
mount (grub_disk_t disk, struct grub_bfs_superblock *sb) mount (grub_disk_t disk, struct grub_bfs_superblock *sb)
{ {
grub_err_t err; grub_err_t err;
err = grub_disk_read (disk, 1, 0, err = grub_disk_read (disk, 1, 0, sizeof (*sb), sb);
sizeof (*sb), sb);
if (err == GRUB_ERR_OUT_OF_RANGE) if (err == GRUB_ERR_OUT_OF_RANGE)
return grub_error (GRUB_ERR_BAD_FS, "not a BFS filesystem"); return grub_error (GRUB_ERR_BAD_FS, "not a BFS filesystem");
if (err) if (err)
@ -701,7 +701,7 @@ mount (grub_disk_t disk, struct grub_bfs_superblock *sb)
static grub_err_t static grub_err_t
grub_bfs_dir (grub_device_t device, const char *path, grub_bfs_dir (grub_device_t device, const char *path,
int (*hook_in) (const char *filename, int (*hook_in) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info * info))
{ {
struct grub_bfs_superblock sb; struct grub_bfs_superblock sb;
grub_err_t err; grub_err_t err;
@ -710,15 +710,15 @@ grub_bfs_dir (grub_device_t device, const char *path,
int hook (const char *name, grub_uint64_t value) int hook (const char *name, grub_uint64_t value)
{ {
grub_err_t err2; grub_err_t err2;
union { union
{
struct grub_bfs_inode ino; struct grub_bfs_inode ino;
grub_uint8_t raw[grub_bfs_to_cpu32 (sb.bsize)]; grub_uint8_t raw[grub_bfs_to_cpu32 (sb.bsize)];
} ino; } ino;
struct grub_dirhook_info info; struct grub_dirhook_info info;
err2 = grub_disk_read (device->disk, value err2 = grub_disk_read (device->disk, value
<< (grub_bfs_to_cpu32 (sb.log2_bsize) - 9) << (grub_bfs_to_cpu32 (sb.log2_bsize) - 9), 0,
, 0,
grub_bfs_to_cpu32 (sb.bsize), (char *) ino.raw); grub_bfs_to_cpu32 (sb.bsize), (char *) ino.raw);
if (err2) if (err2)
{ {
@ -736,7 +736,8 @@ grub_bfs_dir (grub_device_t device, const char *path,
return err; return err;
{ {
union { union
{
struct grub_bfs_inode ino; struct grub_bfs_inode ino;
grub_uint8_t raw[grub_bfs_to_cpu32 (sb.bsize)]; grub_uint8_t raw[grub_bfs_to_cpu32 (sb.bsize)];
} ino; } ino;
@ -762,7 +763,8 @@ grub_bfs_open (struct grub_file *file, const char *name)
return err; return err;
{ {
union { union
{
struct grub_bfs_inode ino; struct grub_bfs_inode ino;
grub_uint8_t raw[grub_bfs_to_cpu32 (sb.bsize)]; grub_uint8_t raw[grub_bfs_to_cpu32 (sb.bsize)];
} ino; } ino;
@ -801,8 +803,7 @@ grub_bfs_read (grub_file_t file, char *buf, grub_size_t len)
struct grub_bfs_data *data = file->data; struct grub_bfs_data *data = file->data;
err = read_bfs_file (file->device->disk, &data->sb, err = read_bfs_file (file->device->disk, &data->sb,
data->ino, data->ino, file->offset, buf, len, file->read_hook);
file->offset, buf, len, file->read_hook);
if (err) if (err)
return -1; return -1;
return len; return len;
@ -828,12 +829,10 @@ static grub_ssize_t
read_bfs_attr (grub_disk_t disk, read_bfs_attr (grub_disk_t disk,
const struct grub_bfs_superblock *sb, const struct grub_bfs_superblock *sb,
const struct grub_bfs_inode *ino, const struct grub_bfs_inode *ino,
const char *name, const char *name, void *buf, grub_size_t len)
void *buf, grub_size_t len)
{ {
grub_uint8_t *ptr = (grub_uint8_t *) ino->small_data; grub_uint8_t *ptr = (grub_uint8_t *) ino->small_data;
grub_uint8_t *end = ((grub_uint8_t *) ino grub_uint8_t *end = ((grub_uint8_t *) ino + grub_bfs_to_cpu32 (sb->bsize));
+ grub_bfs_to_cpu32 (sb->bsize));
while (ptr + sizeof (struct grub_bfs_small_data_element_header) < end) while (ptr + sizeof (struct grub_bfs_small_data_element_header) < end)
{ {
@ -859,36 +858,36 @@ read_bfs_attr (grub_disk_t disk,
} }
if (ino->attr.len != 0) if (ino->attr.len != 0)
{ {
union { union
struct grub_bfs_inode ino; {
grub_uint8_t raw[grub_bfs_to_cpu32 (sb->bsize)]; struct grub_bfs_inode ino;
} ino2; grub_uint8_t raw[grub_bfs_to_cpu32 (sb->bsize)];
grub_size_t read; } ino2;
grub_err_t err; grub_size_t read;
grub_uint64_t res; grub_err_t err;
grub_uint64_t res;
err = read_extent (disk, sb, &ino->attr, 0, 0, ino2.raw, err = read_extent (disk, sb, &ino->attr, 0, 0, ino2.raw,
grub_bfs_to_cpu32 (sb->bsize)); grub_bfs_to_cpu32 (sb->bsize));
if (err) if (err)
return -1; return -1;
err = find_in_b_tree (disk, sb, &ino2.ino, name, &res); err = find_in_b_tree (disk, sb, &ino2.ino, name, &res);
if (err) if (err)
return -1; return -1;
grub_disk_read (disk, res grub_disk_read (disk, res
<< (grub_bfs_to_cpu32 (sb->log2_bsize) - 9) << (grub_bfs_to_cpu32 (sb->log2_bsize) - 9), 0,
, 0, grub_bfs_to_cpu32 (sb->bsize), (char *) &ino2);
grub_bfs_to_cpu32 (sb->bsize), (char *) &ino2); read = grub_bfs_to_cpu64 (ino2.ino.size);
read = grub_bfs_to_cpu64 (ino2.ino.size); if (read > len)
if (read > len) read = len;
read = len;
err = read_bfs_file (disk, sb, &ino2.ino, 0, buf, read, 0); err = read_bfs_file (disk, sb, &ino2.ino, 0, buf, read, 0);
if (err) if (err)
return -1; return -1;
return read; return read;
} }
return -1; return -1;
} }
@ -905,7 +904,8 @@ grub_bfs_uuid (grub_device_t device, char **uuid)
return err; return err;
{ {
union { union
{
struct grub_bfs_inode ino; struct grub_bfs_inode ino;
grub_uint8_t raw[grub_bfs_to_cpu32 (sb.bsize)]; grub_uint8_t raw[grub_bfs_to_cpu32 (sb.bsize)];
} ino; } ino;
@ -917,7 +917,8 @@ grub_bfs_uuid (grub_device_t device, char **uuid)
return err; return err;
if (read_bfs_attr (device->disk, &sb, &ino.ino, "be:volume_id", if (read_bfs_attr (device->disk, &sb, &ino.ino, "be:volume_id",
&vid, 8) == 8) &vid, 8) == 8)
*uuid = grub_xasprintf ("%016" PRIxGRUB_UINT64_T, grub_bfs_to_cpu64 (vid)); *uuid =
grub_xasprintf ("%016" PRIxGRUB_UINT64_T, grub_bfs_to_cpu64 (vid));
} }
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -938,7 +939,8 @@ static struct grub_fs grub_bfs_fs = {
GRUB_MOD_INIT (bfs) GRUB_MOD_INIT (bfs)
{ {
COMPILE_TIME_ASSERT (1 << LOG_EXTENT_SIZE == sizeof (struct grub_bfs_extent)); COMPILE_TIME_ASSERT (1 << LOG_EXTENT_SIZE ==
sizeof (struct grub_bfs_extent));
grub_fs_register (&grub_bfs_fs); grub_fs_register (&grub_bfs_fs);
} }