|
|
f96e0b |
From 1d4fd1febde6768099515759de61cbea61291cec Mon Sep 17 00:00:00 2001
|
|
|
f96e0b |
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
Date: Thu, 28 Feb 2013 09:36:55 +0100
|
|
|
f96e0b |
Subject: [PATCH 164/482] * util/grub-fstest.c: Remove nested functions.
|
|
|
f96e0b |
|
|
|
f96e0b |
---
|
|
|
f96e0b |
ChangeLog | 4 ++
|
|
|
f96e0b |
util/grub-fstest.c | 166 ++++++++++++++++++++++++++++-------------------------
|
|
|
f96e0b |
2 files changed, 93 insertions(+), 77 deletions(-)
|
|
|
f96e0b |
|
|
|
f96e0b |
diff --git a/ChangeLog b/ChangeLog
|
|
|
f96e0b |
index bb02830..06123b6 100644
|
|
|
f96e0b |
--- a/ChangeLog
|
|
|
f96e0b |
+++ b/ChangeLog
|
|
|
f96e0b |
@@ -1,3 +1,7 @@
|
|
|
f96e0b |
+2013-02-28 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ * util/grub-fstest.c: Remove nested functions.
|
|
|
f96e0b |
+
|
|
|
f96e0b |
2013-02-27 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
|
|
|
f96e0b |
* grub-core/loader/machoXX.c: Remove nested functions.
|
|
|
f96e0b |
diff --git a/util/grub-fstest.c b/util/grub-fstest.c
|
|
|
f96e0b |
index a546b75..253dee8 100644
|
|
|
f96e0b |
--- a/util/grub-fstest.c
|
|
|
f96e0b |
+++ b/util/grub-fstest.c
|
|
|
f96e0b |
@@ -79,7 +79,7 @@ static grub_disk_addr_t skip, leng;
|
|
|
f96e0b |
static int uncompress = 0;
|
|
|
f96e0b |
|
|
|
f96e0b |
static void
|
|
|
f96e0b |
-read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
|
|
f96e0b |
+read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len, void *hook_arg), void *hook_arg)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
static char buf[BUF_SIZE];
|
|
|
f96e0b |
grub_file_t file;
|
|
|
f96e0b |
@@ -108,7 +108,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
|
|
f96e0b |
grub_util_error (_("disk read fails at offset %lld, length %d"),
|
|
|
f96e0b |
skip, len);
|
|
|
f96e0b |
|
|
|
f96e0b |
- if (hook (skip, buf, len))
|
|
|
f96e0b |
+ if (hook (skip, buf, len, hook_arg))
|
|
|
f96e0b |
break;
|
|
|
f96e0b |
|
|
|
f96e0b |
skip += len;
|
|
|
f96e0b |
@@ -158,7 +158,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
|
|
f96e0b |
break;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
- if ((sz == 0) || (hook (ofs, buf, sz)))
|
|
|
f96e0b |
+ if ((sz == 0) || (hook (ofs, buf, sz, hook_arg)))
|
|
|
f96e0b |
break;
|
|
|
f96e0b |
|
|
|
f96e0b |
ofs += sz;
|
|
|
f96e0b |
@@ -169,87 +169,99 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
|
|
f96e0b |
grub_file_close (file);
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
-static void
|
|
|
f96e0b |
-cmd_cp (char *src, char *dest)
|
|
|
f96e0b |
+struct cp_hook_ctx
|
|
|
f96e0b |
{
|
|
|
f96e0b |
FILE *ff;
|
|
|
f96e0b |
+ const char *dest;
|
|
|
f96e0b |
+};
|
|
|
f96e0b |
|
|
|
f96e0b |
- auto int cp_hook (grub_off_t ofs, char *buf, int len);
|
|
|
f96e0b |
- int cp_hook (grub_off_t ofs, char *buf, int len)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- (void) ofs;
|
|
|
f96e0b |
+static int
|
|
|
f96e0b |
+cp_hook (grub_off_t ofs, char *buf, int len, void *_ctx)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ struct cp_hook_ctx *ctx = _ctx;
|
|
|
f96e0b |
+ (void) ofs;
|
|
|
f96e0b |
|
|
|
f96e0b |
- if ((int) fwrite (buf, 1, len, ff) != len)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- grub_util_error (_("cannot write to `%s': %s"),
|
|
|
f96e0b |
- dest, strerror (errno));
|
|
|
f96e0b |
- return 1;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
+ if ((int) fwrite (buf, 1, len, ctx->ff) != len)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_util_error (_("cannot write to `%s': %s"),
|
|
|
f96e0b |
+ ctx->dest, strerror (errno));
|
|
|
f96e0b |
+ return 1;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
|
|
|
f96e0b |
- return 0;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
|
|
|
f96e0b |
- ff = fopen (dest, "wb");
|
|
|
f96e0b |
- if (ff == NULL)
|
|
|
f96e0b |
+static void
|
|
|
f96e0b |
+cmd_cp (char *src, const char *dest)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ struct cp_hook_ctx ctx =
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .dest = dest
|
|
|
f96e0b |
+ };
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ ctx.ff = fopen (dest, "wb");
|
|
|
f96e0b |
+ if (ctx.ff == NULL)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
grub_util_error (_("cannot open OS file `%s': %s"), dest,
|
|
|
f96e0b |
strerror (errno));
|
|
|
f96e0b |
return;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
- read_file (src, cp_hook);
|
|
|
f96e0b |
- fclose (ff);
|
|
|
f96e0b |
+ read_file (src, cp_hook, &ctx;;
|
|
|
f96e0b |
+ fclose (ctx.ff);
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static int
|
|
|
f96e0b |
+cat_hook (grub_off_t ofs, char *buf, int len, void *_arg __attribute__ ((unused)))
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ (void) ofs;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if ((int) fwrite (buf, 1, len, stdout) != len)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_util_error (_("cannot write to the stdout: %s"),
|
|
|
f96e0b |
+ strerror (errno));
|
|
|
f96e0b |
+ return 1;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
static void
|
|
|
f96e0b |
cmd_cat (char *src)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
- auto int cat_hook (grub_off_t ofs, char *buf, int len);
|
|
|
f96e0b |
- int cat_hook (grub_off_t ofs, char *buf, int len)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- (void) ofs;
|
|
|
f96e0b |
+ read_file (src, cat_hook, 0);
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
|
|
|
f96e0b |
- if ((int) fwrite (buf, 1, len, stdout) != len)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- grub_util_error (_("cannot write to the stdout: %s"),
|
|
|
f96e0b |
- strerror (errno));
|
|
|
f96e0b |
- return 1;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
+static int
|
|
|
f96e0b |
+cmp_hook (grub_off_t ofs, char *buf, int len, void *ff_in)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ FILE *ff = ff_in;
|
|
|
f96e0b |
+ static char buf_1[BUF_SIZE];
|
|
|
f96e0b |
+ if ((int) fread (buf_1, 1, len, ff) != len)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_util_error (_("read error at offset %llu: %s"), ofs,
|
|
|
f96e0b |
+ grub_errmsg);
|
|
|
f96e0b |
+ return 1;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
|
|
|
f96e0b |
- return 0;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
+ if (grub_memcmp (buf, buf_1, len) != 0)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ int i;
|
|
|
f96e0b |
|
|
|
f96e0b |
- read_file (src, cat_hook);
|
|
|
f96e0b |
+ for (i = 0; i < len; i++, ofs++)
|
|
|
f96e0b |
+ if (buf_1[i] != buf[i])
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_util_error (_("compare fail at offset %llu"), ofs);
|
|
|
f96e0b |
+ return 1;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
+
|
|
|
f96e0b |
static void
|
|
|
f96e0b |
cmd_cmp (char *src, char *dest)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
FILE *ff;
|
|
|
f96e0b |
- static char buf_1[BUF_SIZE];
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- auto int cmp_hook (grub_off_t ofs, char *buf, int len);
|
|
|
f96e0b |
- int cmp_hook (grub_off_t ofs, char *buf, int len)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- if ((int) fread (buf_1, 1, len, ff) != len)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- grub_util_error (_("read error at offset %llu: %s"), ofs,
|
|
|
f96e0b |
- grub_errmsg);
|
|
|
f96e0b |
- return 1;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- if (grub_memcmp (buf, buf_1, len))
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- int i;
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- for (i = 0; i < len; i++, ofs++)
|
|
|
f96e0b |
- if (buf_1[i] != buf[i])
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- grub_util_error (_("compare fail at offset %llu"), ofs);
|
|
|
f96e0b |
- return 1;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
- return 0;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
|
|
|
f96e0b |
struct stat st;
|
|
|
f96e0b |
if (stat (dest, &st) == -1)
|
|
|
f96e0b |
@@ -306,7 +318,7 @@ cmd_cmp (char *src, char *dest)
|
|
|
f96e0b |
grub_util_error (_("cannot seek `%s': %s"), dest,
|
|
|
f96e0b |
strerror (errno));
|
|
|
f96e0b |
|
|
|
f96e0b |
- read_file (src, cmp_hook);
|
|
|
f96e0b |
+ read_file (src, cmp_hook, ff);
|
|
|
f96e0b |
|
|
|
f96e0b |
{
|
|
|
f96e0b |
grub_uint64_t pre;
|
|
|
f96e0b |
@@ -318,17 +330,26 @@ cmd_cmp (char *src, char *dest)
|
|
|
f96e0b |
fclose (ff);
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
+static int
|
|
|
f96e0b |
+hex_hook (grub_off_t ofs, char *buf, int len, void *arg __attribute__ ((unused)))
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ hexdump (ofs, buf, len);
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
static void
|
|
|
f96e0b |
cmd_hex (char *pathname)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
- auto int hex_hook (grub_off_t ofs, char *buf, int len);
|
|
|
f96e0b |
- int hex_hook (grub_off_t ofs, char *buf, int len)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- hexdump (ofs, buf, len);
|
|
|
f96e0b |
- return 0;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
+ read_file (pathname, hex_hook, 0);
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
|
|
|
f96e0b |
- read_file (pathname, hex_hook);
|
|
|
f96e0b |
+static int
|
|
|
f96e0b |
+crc_hook (grub_off_t ofs, char *buf, int len, void *crc_ctx)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ (void) ofs;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ GRUB_MD_CRC32->write(crc_ctx, buf, len);
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
static void
|
|
|
f96e0b |
@@ -337,16 +358,7 @@ cmd_crc (char *pathname)
|
|
|
f96e0b |
grub_uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
|
|
|
f96e0b |
GRUB_MD_CRC32->init(crc32_context);
|
|
|
f96e0b |
|
|
|
f96e0b |
- auto int crc_hook (grub_off_t ofs, char *buf, int len);
|
|
|
f96e0b |
- int crc_hook (grub_off_t ofs, char *buf, int len)
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- (void) ofs;
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- GRUB_MD_CRC32->write(crc32_context, buf, len);
|
|
|
f96e0b |
- return 0;
|
|
|
f96e0b |
- }
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- read_file (pathname, crc_hook);
|
|
|
f96e0b |
+ read_file (pathname, crc_hook, crc32_context);
|
|
|
f96e0b |
GRUB_MD_CRC32->final(crc32_context);
|
|
|
f96e0b |
printf ("%08x\n",
|
|
|
f96e0b |
grub_be_to_cpu32 (grub_get_unaligned32 (GRUB_MD_CRC32->read (crc32_context))));
|
|
|
f96e0b |
--
|
|
|
f96e0b |
1.8.2.1
|
|
|
f96e0b |
|