modinfo: match more standard module fields and fix version field

Previously, -F version could match the srcversion= string.

before :
  ~ # modinfo -F version tiwlan_drv
  version:        6.1.2012.05.29
  version:        533BB7E5866E52F63B9ACCB
  version:        0x%x, oui=0x%x, 0x%x, 0x%x
  version:        0x%x

  ~ # modinfo tiwlan_drv
  filename:       tiwlan_drv.ko
  author:         Texas Instruments Inc - Retouched by CyanogenDefy
  license:        GPL
  vermagic:       2.6.32.9 preempt mod_unload ARMv7
  parm:           g_sdio_debug_level:debug level
  depends:

now :
  ~ # modinfo -F version tiwlan_drv
  version:        6.1.2012.05.29

  ~ # modinfo tiwlan_drv
  filename:       tiwlan_drv.ko
  license:        GPL
  author:         Texas Instruments Inc - Retouched by CyanogenDefy
  version:        6.1.2012.05.29
  srcversion:     533BB7E5866E52F63B9ACCB
  depends:
  uts_release:    2.6.32.9-g306944c
  vermagic:       2.6.32.9 preempt mod_unload ARMv7
  parm:           g_sdio_debug_level:debug level

This patch also add support for the old "-n" and some other helpers

Change-Id: Icb4e9ca513cbce46b075a6f038799a7a19fb7e22
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Tanguy Pruvot 2012-05-30 08:00:46 +02:00 committed by Denys Vlasenko
parent ac164dd2a7
commit 772f17a843

View File

@ -24,9 +24,9 @@
enum {
OPT_TAGS = (1 << 8) - 1,
OPT_F = (1 << 8), /* field name */
OPT_0 = (1 << 9), /* \0 as separator */
OPT_TAGS = (1 << 12) - 1, /* shortcut count */
OPT_F = (1 << 12), /* field name */
OPT_0 = (1 << 13), /* \0 as separator */
};
struct modinfo_env {
@ -49,13 +49,17 @@ static void modinfo(const char *path, const char *version,
{
static const char *const shortcuts[] = {
"filename",
"description",
"author",
"license",
"author",
"description",
"version",
"alias",
"srcversion",
"depends",
"uts_release",
"vermagic",
"parm",
"firmware",
"depends",
};
size_t len;
int j, length;
@ -97,8 +101,11 @@ static void modinfo(const char *path, const char *version,
if (ptr == NULL) /* no occurance left, done */
break;
if (strncmp(ptr, pattern, length) == 0 && ptr[length] == '=') {
ptr += length + 1;
ptr += display(ptr, pattern, (1<<j) != tags);
/* field prefixes are 0x80 or 0x00 */
if ((ptr[-1] & 0x7F) == '\0') {
ptr += length + 1;
ptr += display(ptr, pattern, (1<<j) != tags);
}
}
++ptr;
}
@ -131,7 +138,7 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv)
env.field = NULL;
opt_complementary = "-1"; /* minimum one param */
opts = getopt32(argv, "fdalvpF:0", &env.field);
opts = getopt32(argv, "nladvAsDumpF:0", &env.field);
env.tags = opts & OPT_TAGS ? opts & OPT_TAGS : OPT_TAGS;
argv += optind;