From 592cc544acebfb1179bf91083870a235f72f2f64 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 28 Apr 2022 23:04:01 +0200 Subject: [PATCH] modinfo: add -k option for kernel version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is useful to be able to specify kernel version when generating initramfs and similar for a kernel version that might not be the running one. bloatcheck on x86_64: function old new delta packed_usage 26193 26218 +25 modinfo_main 391 414 +23 .rodata 80296 80298 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 50/0) Total: 50 bytes text data bss dec hex filename 834606 14124 2008 850738 cfb32 busybox_old 834657 14124 2008 850789 cfb65 busybox_unstripped Signed-off-by: Natanael Copa --- modutils/modinfo.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/modutils/modinfo.c b/modutils/modinfo.c index 0a86c3296..53bc02880 100644 --- a/modutils/modinfo.c +++ b/modutils/modinfo.c @@ -38,17 +38,18 @@ static const char *const shortcuts[] ALIGN_PTR = { enum { OPT_0 = (1 << 0), /* \0 as separator */ - OPT_F = (1 << 1), /* field name */ + OPT_k = (1 << 1), /* kernel version */ + OPT_F = (1 << 2), /* field name */ /* first bits are for -nadlp options, the rest are for * fields not selectable with "shortcut" options */ - OPT_n = (1 << 2), - OPT_TAGS = ((1 << ARRAY_SIZE(shortcuts)) - 1) << 2, + OPT_n = (1 << 3), + OPT_TAGS = ((1 << ARRAY_SIZE(shortcuts)) - 1) << 3, }; static void display(const char *data, const char *pattern) { - int flag = option_mask32 >> 1; /* shift out -0 bit */ + int flag = option_mask32 >> 2; /* shift out -0 and -k bits */ if (flag & (flag-1)) { /* more than one field to show: print "FIELD:" pfx */ int n = printf("%s:", pattern); @@ -82,7 +83,8 @@ static void modinfo(const char *path, const char *version, } } - for (j = 1; (1<