commit 8a3a0a424a357b36f0aed1fe607785e673993197
parent 8fa085f1d375dade1e0423b00d22549dc7604af5
Author: sin <sin@2f30.org>
Date: Mon, 4 Mar 2013 13:17:53 +0000
mdiff: Update file format to include endianness/version info
Remove docs/mdiff-fmt.
Diffstat:
5 files changed, 14 insertions(+), 27 deletions(-)
diff --git a/docs/mdiff-fmt b/docs/mdiff-fmt
@@ -1,24 +0,0 @@
-File format of the mdiff files
-==============================
-
-struct mdiff_hdr {
- /* MDIFF */
- char magic[8];
- /* Number of memory diff regions */
- uint32_t nregions;
- /* Block size */
- uint32_t blksize;
-};
-
-struct mdiff_region {
- /* Offset into memory where this region should
- * be written to */
- uint32_t offset;
- /* Length of this memory diff region */
- uint32_t len;
- /* Actual data */
- char buf[];
-};
-
-We have a fixed header at the start and a series of
-`mdiff_region' structures following.
diff --git a/mdiff.c b/mdiff.c
@@ -51,7 +51,7 @@ parse_mdiff_hdr(int fd)
ret = read(fd, hdr, sizeof(*hdr));
if (ret != sizeof(*hdr))
err(1, "read");
- if (strncmp(hdr->magic, "MDIFF", 5))
+ if (strncmp((char *)hdr->magic, "MDIFF", 5))
return NULL;
if (!hdr->nregions)
return NULL;
diff --git a/mdiffdump.c b/mdiffdump.c
@@ -20,8 +20,11 @@ main(int argc, char *argv[])
hdr = parse_mdiff_hdr(fd);
if (!hdr)
errx(1, "%s: failed to parse mdiff", argv[1]);
- printf("nregions: %lu\n", (unsigned long)hdr->nregions);
+ printf("endianness: %s\n",
+ hdr->endianness ? "big endian" : "little endian");
+ printf("version: %hhu\n", hdr->version);
printf("blksize: %lu\n", (unsigned long)hdr->blksize);
+ printf("nregions: %lu\n", (unsigned long)hdr->nregions);
for (i = 0; i < hdr->nregions; i++) {
mdiff = mdiff_read_diff(fd, hdr, i);
printf("offset: %lu\n", (unsigned long)mdiff->offset);
diff --git a/memzap.c b/memzap.c
@@ -100,6 +100,8 @@ main(int argc, char *argv[])
memset(&hdr, 0, sizeof(hdr));
strncpy((char *)hdr.magic, "MDIFF", 5);
hdr.blksize = BLKSIZE;
+ hdr.endianness = 0;
+ hdr.version = 1;
mdiff_start_diff(fd);
do {
readmem(pid, buf, addr, len);
diff --git a/proto.h b/proto.h
@@ -103,7 +103,13 @@ RB_HEAD(mem_tree, mem_tree_entry);
struct mdiff_hdr {
/* MDIFF */
- char magic[8];
+ uint8_t magic[8];
+ /* 0 for little endian, 1 for big endian */
+ uint8_t endianness;
+ /* Version info */
+ uint8_t version;
+ /* Reserved */
+ uint8_t reserved;
/* Number of memory diff regions */
uint32_t nregions;
/* Block size */