Re: [PATCH bpf-next v5 3/9] bpftool: Implement btf_save_raw()
flat view
From: Andrii Nakryiko <hidden>
Date: 2022-02-02 18:48:29
Also in:
bpf
On Fri, Jan 28, 2022 at 2:33 PM Mauricio Vásquez [off-list ref] wrote:
Helper function to save a BTF object to a file. Signed-off-by: Mauricio Vásquez <redacted> Signed-off-by: Rafael David Tinoco <redacted> Signed-off-by: Lorenzo Fontana <redacted> Signed-off-by: Leonardo Di Donato <redacted> ---
The logic looks good, but you need to merge adding this static function with the patch that's using that static function. Otherwise you will break bisectability because compiler will warn about unused static function.
quoted hunk ↗ jump to hunk
tools/bpf/bpftool/gen.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c index 7db31b0f265f..64371f466fa6 100644 --- a/tools/bpf/bpftool/gen.c +++ b/tools/bpf/bpftool/gen.c@@ -1096,6 +1096,28 @@ static int do_help(int argc, char **argv) return 0; } +static int btf_save_raw(const struct btf *btf, const char *path) +{ + const void *data; + FILE *f = NULL; + __u32 data_sz; + int err = 0; + + data = btf__raw_data(btf, &data_sz); + if (!data) + return -ENOMEM; + + f = fopen(path, "wb"); + if (!f) + return -errno; + + if (fwrite(data, 1, data_sz, f) != data_sz) + err = -errno; + + fclose(f); + return err; +} + /* Create BTF file for a set of BPF objects */ static int btfgen(const char *src_btf, const char *dst_btf, const char *objspaths[]) { --2.25.1