From: Coly Li <colyli@suse.de>
To: linux-bcache@vger.kernel.org
Cc: linux-block@vger.kernel.org, Coly Li <colyli@suse.de>
Subject: [RFC PATCH 2/4] struct_offset: print offset of each member of the on-disk data structure
Date: Mon, 6 Jul 2020 00:04:38 +0800 [thread overview]
Message-ID: <20200705160440.5801-3-colyli@suse.de> (raw)
In-Reply-To: <20200705160440.5801-1-colyli@suse.de>
This is a helper small program to print out the offset in bytes of each
member of the on-disk data structure. Currently the member print lines
are coded manually, hope latter it can be more intelligent to avoid the
hard code.
Signed-off-by: Coly Li <colyli@suse.de>
---
Makefile | 4 +++-
struct_offset.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 1 deletion(-)
create mode 100644 struct_offset.c
diff --git a/Makefile b/Makefile
index 2c326cf..b352d21 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ DRACUTLIBDIR=/lib/dracut
INSTALL=install
CFLAGS+=-O2 -Wall -g
-all: make-bcache probe-bcache bcache-super-show bcache-register bcache
+all: make-bcache probe-bcache bcache-super-show bcache-register bcache struct_offset
install: make-bcache probe-bcache bcache-super-show
$(INSTALL) -m0755 make-bcache bcache-super-show bcache $(DESTDIR)${PREFIX}/sbin/
@@ -22,6 +22,8 @@ clean:
bcache-test: LDLIBS += `pkg-config --libs openssl` -lm
+struct_offset: struct_offset.o
+
make-bcache: LDLIBS += `pkg-config --libs uuid blkid smartcols`
make-bcache: CFLAGS += `pkg-config --cflags uuid blkid smartcols`
make-bcache: make.o crc64.o lib.o zoned.o
diff --git a/struct_offset.c b/struct_offset.c
new file mode 100644
index 0000000..6061259
--- /dev/null
+++ b/struct_offset.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Author: Coly Li <colyli@suse.de>
+ *
+ * Print out offset of each member of on-disk structure
+ */
+
+#include <stdio.h>
+#include <stddef.h>
+#include <inttypes.h>
+#include <stdbool.h>
+
+#include "bcache.h"
+
+
+#define OFF_SB(m) offsetof(struct cache_sb, m)
+
+void print_cache_sb()
+{
+ printf(" struct cache_sb {:\n");
+ printf("/* %3.3lx */ uint64_t csum;\n", OFF_SB(csum));
+ printf("/* %3.3lx */ uint64_t offset;\n", OFF_SB(offset));
+ printf("/* %3.3lx */ uint64_t version;\n", OFF_SB(version));
+ printf("/* %3.3lx */ uint8_t magic[6];\n", OFF_SB(magic));
+ printf("/* %3.3lx */ uint8_t uuid[16];\n", OFF_SB(uuid));
+ printf(" union {;\n");
+ printf("/* %3.3lx */ uint8_t set_uuid;\n", OFF_SB(set_uuid));
+ printf("/* %3.3lx */ uint64_t set_magic;\n", OFF_SB(set_magic));
+ printf(" };\n");
+ printf("/* %3.3lx */ uint8_t label[%u];\n", OFF_SB(label),
+ SB_LABEL_SIZE);
+ printf("/* %3.3lx */ uint64_t flags;\n", OFF_SB(flags));
+ printf("/* %3.3lx */ uint64_t seq;\n", OFF_SB(seq));
+ printf("/* %3.3lx */ uint64_t pad[8];\n", OFF_SB(pad));
+ printf(" union {\n");
+ printf(" struct {\n");
+ printf("/* %3.3lx */ uint64_t nbuckets;\n", OFF_SB(nbuckets));
+ printf("/* %3.3lx */ uint16_t block_size;\n", OFF_SB(block_size));
+ printf("/* %3.3lx */ uint16_t bucket_size;\n", OFF_SB(bucket_size));
+ printf("/* %3.3lx */ uint16_t nr_in_set;\n", OFF_SB(nr_in_set));
+ printf("/* %3.3lx */ uint16_t nr_this_dev;\n", OFF_SB(nr_this_dev));
+ printf(" };\n");
+ printf(" struct {\n");
+ printf("/* %3.3lx */ uint64_t data_offset;\n", OFF_SB(data_offset));
+ printf(" };\n");
+ printf(" };\n");
+ printf("/* %3.3lx */ uint32_t last_mount;\n", OFF_SB(last_mount));
+ printf("/* %3.3lx */ uint16_t first_bucket;\n", OFF_SB(first_bucket));
+ printf(" union {\n");
+ printf("/* %3.3lx */ uint16_t njournal_buckets;\n", OFF_SB(njournal_buckets));
+ printf("/* %3.3lx */ uint16_t keys;\n", OFF_SB(keys));
+ printf(" };\n");
+ printf("/* %3.3lx */ uint64_t d[%u];\n", OFF_SB(d), SB_JOURNAL_BUCKETS);
+ printf("/* %3.3lx */ }\n", OFF_SB(d) + sizeof(uint64_t) * SB_JOURNAL_BUCKETS);
+}
+
+int main(int argc, char *argv[])
+{
+ print_cache_sb();
+ return 0;
+}
--
2.26.2
next prev parent reply other threads:[~2020-07-05 16:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-05 16:04 [RFC PATCH 0/4] bcache-tools: changes for large bucket size Coly Li
2020-07-05 16:04 ` Coly Li
2020-07-05 16:04 ` [RFC PATCH 1/4] bcache-tools: comments offset for members of struct cache_sb Coly Li
2020-07-05 16:04 ` Coly Li [this message]
2020-07-05 16:04 ` [RFC PATCH 3/4] bcache-tools: The new super block version BCACHE_SB_VERSION_BDEV_WITH_FEATURES Coly Li
2020-07-05 16:04 ` [RFC PATCH 4/4] bcache-tools: add large_bucket incompat feature Coly Li
2020-07-05 16:04 ` Coly Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200705160440.5801-3-colyli@suse.de \
--to=colyli@suse.de \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).