mmc-utils: improve lsmmc usability
Subsystems (2)
v4 cover mmc-utils: improve lsmmc usability
This series improves lsmmc in three areas: external manufacturer ID files and accepting /dev and /sys/block paths for register reads, an mmc list command, and bash completion for mmc-utils.
Changes since v3 (review by Avri Altman):
- Patch 1 didn't compile on its own: the mmc list implementation (find_block_devname, print_list_entry, do_list, month_name) had accidentally been committed in this patch instead of the "Add mmc list command" patch. Moved all of it out, and squashed in the former patch 2 ("Accept /dev and /sys/block paths for register reads") since the two don't have independent value split apart from the list command.
- Patch 2 (Add mmc list command): now contains the full mmc list implementation that previously leaked into patch 1.
- Patch 3 (Add bash completion): subcommand completion is now driven by parsing 'mmc help' output instead of maintaining a parallel hardcoded verb list, so it stays in sync as commands are added or removed.
Torstein Eide (3):
mmc-utils: lsmmc: Use external .ids files and accept /dev, /sys/block
paths
mmc-utils: lsmmc: Add mmc list command
mmc-utils: Add bash completion
Makefile | 11 +- completion/mmc | 52 ++++ docs/HOWTO.rst | 77 +++++- lsmmc.c | 621 ++++++++++++++++++++++++++------------------- mmc.c | 6 +- mmc_cmds.h | 1 + multimediacard.ids | 16 ++ sdcard.ids | 23 ++ 8 files changed, 533 insertions(+), 274 deletions(-) create mode 100644 completion/mmc create mode 100644 multimediacard.ids create mode 100644 sdcard.ids
Signature · 1 line
2.53.0
PATCH v4 1/3 mmc-utils: lsmmc: Use external .ids files and accept /dev, /sys/block paths
Similar to pci.ids and usb.ids, move the statically defined manufacturer ID arrays out of the source and into external sdcard.ids and multimediacard.ids files. This allows other programs to use the same database without an API, ABI, or cmd interface.
Make the program able to read from the base directory to test without installing.
Make it possible from the Makefile to change the install directory of the database.
Also accept /dev and /sys/block paths for register reads. Commands like 'cid read' previously required a raw sysfs device path such as /sys/bus/mmc/devices/mmc0:0001/. Most users know their block device as /dev/mmcblk0 or /sys/block/mmcblk0.
Add resolve_dev_path() which follows /sys/class/block/<dev>/device via realpath() to reach the canonical sysfs device directory. Paths that start with /dev/ or /sys/block/ are resolved automatically in do_read_reg() before processing, and the resolved sysfs path is printed so the caller can see which device was matched.
--- Makefile | 8 +- docs/HOWTO.rst | 59 +++++- lsmmc.c | 476 ++++++++++++++++++++------------------------- multimediacard.ids | 16 ++ sdcard.ids | 23 +++ 5 files changed, 308 insertions(+), 274 deletions(-) create mode 100644 multimediacard.ids create mode 100644 sdcard.ids
Makefile +7 -1
@@ -3,7 +3,9 @@ CC ?= gcc # e.g., v1.0-5-2023-10-01 GIT_VERSION := "$(shell git describe --abbrev=0 --tags)-$$(git rev-list --count $$(git describe --abbrev=0 --tags)..HEAD)-$$(git log -1 --format=%cd --date=short)" AM_CFLAGS = -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 \ - -DVERSION=\"$(GIT_VERSION)\" + -DVERSION=\"$(GIT_VERSION)\" \ + -DSD_IDS_PATH=\"$(idsdir)/sdcard.ids\" \ + -DMMC_IDS_PATH=\"$(idsdir)/multimediacard.ids\" CFLAGS ?= -g -O2 objects = \ mmc.o \
@@ -21,6 +23,7 @@ override CFLAGS := $(CHECKFLAGS) $(AM_CFLAGS) $(CFLAGS) INSTALL = install prefix ?= /usr/local bindir = $(prefix)/bin +idsdir ?= /usr/share/misc LIBS= RESTORE_LIBS= mandir = /usr/share/man
@@ -57,6 +60,9 @@ install: $(progs) $(INSTALL) $(progs) $(DESTDIR)$(bindir) $(INSTALL) -m755 -d $(DESTDIR)$(mandir)/man1 $(INSTALL) -m 644 mmc.1 $(DESTDIR)$(mandir)/man1 + $(INSTALL) -m755 -d $(DESTDIR)$(idsdir) + $(INSTALL) -m 644 sdcard.ids $(DESTDIR)$(idsdir) + $(INSTALL) -m 644 multimediacard.ids $(DESTDIR)$(idsdir) -include $(foreach obj,$(objects), $(dir $(obj))/.$(notdir $(obj)).d)
docs/HOWTO.rst +50 -9
69 lines not on this page · raw message
lsmmc.c +212 -264
623 lines not on this page · raw message
multimediacard.ids new file +16 -0
@@ -0,0 +1,16 @@ +# MMC manufacturer IDs +# This file is maintained at: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git +0x00 SanDisk +0x02 Kingston/SanDisk +0x03 Toshiba +0x05 Unknown +0x06 Unknown +0x11 Toshiba +0x13 Micron +0x15 Samsung/SanDisk/LG +0x37 KingMax +0x44 ATP +0x45 SanDisk Corporation +0x2c Kingston +0x70 Kingston +0xfe Micron
sdcard.ids new file +23 -0
@@ -0,0 +1,23 @@ +# SD card (secure digital) manufacturer IDs +# This file is maintained at: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git +0x01 Panasonic +0x02 Toshiba/Kingston/Viking +0x03 SanDisk +0x08 Silicon Power +0x18 Infineon +0x1b Transcend/Samsung +0x1c Transcend +0x1d Corsair/AData +0x1e Transcend +0x1f Kingston +0x27 Delkin/Phison +0x28 Lexar +0x30 SanDisk +0x31 Silicon Power +0x33 STMicroelectronics +0x41 Kingston +0x6f STMicroelectronics +0x74 Transcend +0x76 Patriot +0x82 Gobe/Sony +0x89 Unknown
Signature · 1 line
2.53.0
PATCH v4 2/3 mmc-utils: lsmmc: Add mmc list command
In reply to Torstein EideAdd a 'mmc list' command that scans /sys/bus/mmc/devices/, resolves each card's sysfs path, and prints a one-line summary per device.
find_block_devname() maps a sysfs device path back to its mmcblkN name by scanning /sys/class/block/mmcblkN/device symlinks.
print_list_entry() parses the CID register and formats a fixed-width table row with device name, /dev path, bus type, manufacturer, product, revision, serial number, and manufacturing date.
The header is printed once before the first result. Devices without a readable cid file are skipped silently via access() so unrelated sysfs entries do not produce spurious error messages.
--- docs/HOWTO.rst | 12 ++++ lsmmc.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ mmc.c | 6 +- mmc_cmds.h | 1 + 4 files changed, 165 insertions(+), 1 deletion(-)
docs/HOWTO.rst +12 -0
@@ -90,6 +90,18 @@ Running mmc-utils sysfs: /sys/devices/platform/fe320000.mmc/mmc_host/mmc1/mmc1:aaaa SCR Register: 0235800000000000 + ``list`` + List all MMC/SD devices present on the system. Output is a table with + columns: DEVICE (sysfs name), DEV (/dev path), TYPE (MMC or SD), + MANUFACTURER, PRODUCT, REV, SERIAL, and DATE. + + Example:: + + $ mmc list + DEVICE DEV TYPE MANUFACTURER PRODUCT REV SERIAL DATE + mmc0:0001 /dev/mmcblk0 MMC Samsung MAG4FA 1.0 0x1a2b3c4d 2021-jan + mmc1:aaaa /dev/mmcblk1 SD SanDisk SP32G 8.0 0x5e6f7a8b 2020-mar + ``ffu <image name> <device> [chunk-bytes]`` Default mode. Run Field Firmware Update with `<image name>` on `<device>`. `[chunk-bytes]` is optional and defaults to its max - 512k. Should be in decimal bytes and sector aligned.
lsmmc.c +147 -0
159 lines not on this page · raw message
mmc.c +5 -1
@@ -306,6 +306,11 @@ static struct Command commands[] = { "3. Only up to 512K bytes of boot data will be transferred.\n" "4. The MMC will perform a soft reset, if your system cannot handle that do not use the boot operation from mmc-utils.\n", }, + { do_list,0 , +"list" ,"\n" +"List all MMC/SD devices with their /dev path and CID info." , +NULL + }, { NULL, 0, NULL, NULL } };
@@ -590,4 +595,3 @@ int main(int ac, char **av )exit (func (nargs, args)); } -
mmc_cmds.h +1 -0
@@ -62,6 +62,7 @@ int do_opt_ffu4(int nargs, char **argv);int do_read_scr (int argc,char **argv);int do_read_cid (int argc,char **argv);int do_read_csd (int argc,char **argv); +int do_list (int nargs,char **argv);int do_erase (int nargs,char **argv);int do_general_cmd_read (int nargs,char **argv);int do_softreset (int nargs,char **argv);
Signature · 1 line
2.53.0
RE: [PATCH v4 2/3] mmc-utils: lsmmc: Add mmc list command
Quoted 80 lines
Add a 'mmc list' command that scans
/sys/bus/mmc/devices/, resolves each card's sysfs path, and prints a one-line summary per device.
find_block_devname()maps a sysfs device path back to its mmcblkN name by scanning/sys/class/block/mmcblkN/devicesymlinks.
print_list_entry()parses the CID register and formats a fixed-width table row with device name, /dev path, bus type, manufacturer, product, revision, serial number, and manufacturing date.The header is printed once before the first result. Devices without a readable cid file are skipped silently via
access()so unrelated sysfs entries do not produce spurious error messages.Signed-off-by Torstein Eide <[email protected]>--- docs/HOWTO.rst | 12 ++++ lsmmc.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ mmc.c | 6 +- mmc_cmds.h | 1 + 4 files changed, 165 insertions(+), 1 deletion(-)docs/HOWTO.rst +0
-0@@ -90,6 +90,18 @@ Running mmc-utils sysfs:/sys/devices/platform/fe320000.mmc/mmc_host/mmc1/mmc1:aaaa
SCR Register: 0235800000000000docs/HOWTO.rst +9
-0+ ``list`` + List all MMC/SD devices present on the system. Output is a table with + columns: DEVICE (sysfs name), DEV (/dev path), TYPE (MMC or SD), + MANUFACTURER, PRODUCT, REV, SERIAL, and DATE. + + Example:: + + $ mmc list + DEVICE DEV TYPE MANUFACTURER PRODUCT REVSERIAL DATE
+ mmc0:0001/dev/mmcblk0MMC Samsung MAG4FA 1.00x1a2b3c4d2021-jan
+ mmc1:aaaa/dev/mmcblk1SD SanDisk SP32G 8.00x5e6f7a8b2020-mar
+
``ffu <image name> <device> [chunk-bytes]``
Default mode. Run Field Firmware Update with<image name>on<device>.[chunk-bytes]is optional and defaults to its max - 512k. Should be in decimal bytes and sector aligned.lsmmc.c +22
-0@@ -229,6 +229,39 @@ fallback:return strdup (name); } +static char *find_block_devname (const char *sysfs_devpath) { +DIR *d; +struct dirent *ent; + + d =opendir ("/sys/class/block" ); +if (!d) +return NULL ; + +while ((ent =readdir (d)) !=NULL ) { +char linkpath[PATH_MAX ]; +char resolved[PATH_MAX ]; + +if (strncmp (ent->d_name,"mmcblk" ,6 ) !=0 ) +continue ; +if (strchr (ent->d_name +6 ,'p' )) +continue ; + +snprintf (linkpath,sizeof (linkpath), +"/sys/class/block/%s/device" , ent->d_name); +if (realpath (linkpath, resolved) ==NULL ) +continue ; +if (strcmp (resolved, sysfs_devpath) ==0 ) {
lsmmc.c fallback: · line 263
Quoted 10 lines
lsmmc.c +10
-0+closedir (d); +return strdup (ent->d_name); + } + } + +closedir (d); +return NULL ; +} + +
Double blank line.
lsmmc.c
Quoted 8 lines
lsmmc.c +1
-0/* MMC/SD file parsing functions */ static char *read_file_at(const char *dir, const char *name) { @@ -2274,6 +2307,120 @@ static int do_read_reg(int argc, char **argv, enum REG_TYPE reg) return ret;}
lsmmc.c +2
-0+static const char *month_name (unsigned int month) { +static const char *months[] = {
mdt_month is 1-based - see print_sd_cid & print_mmc_cid
Quoted 26 lines
lsmmc.c +26
-0+"jan" ,"feb" ,"mar" ,"apr" ,"may" ,"jun" , +"jul" ,"aug" ,"sep" ,"oct" ,"nov" ,"dec" , + "invalid0", "invalid1", "invalid2", "invalid3", + }; + +if (month >=ARRAY_SIZE (months)) +return "invalid" ; + +return months[month]; +} + +static void print_list_entry (struct config *cfg,const char *devname, +const char *blkdev,char *cid) { +char *mfr; +char devnode[32 ]; + +snprintf (devnode,sizeof (devnode),"/dev/%s" , blkdev ? blkdev : +"?" ); + +if (cfg->bus ==SD ) { +struct sd_cid c; + +parse_sd_cid (cid, &c); + mfr =get_manufacturer (cfg, c.mid); + printf("%-14s %-14s SD %-20s %-10s %u.%u 0x%08x %u-%s\n", + devname, devnode, mfr ? mfr : "Unlisted", c.pnm,
lsmmc.c static int do_read_reg(int argc, char **argv, enum REG_TYPE reg) · line 2348
Quoted 10 lines
lsmmc.c +10
-0+ c.prv_major, c.prv_minor, c.psn,2000 + c.mdt_year, + month_name(c.mdt_month)); + }else { +struct mmc_cid c; + +parse_mmc_cid (cid, &c); + mfr =get_manufacturer (cfg, c.mid); + printf("%-14s %-14s MMC %-20s %-10s %u.%u 0x%08x %u-%s\n", + devname, devnode, mfr ? mfr : "Unlisted", c.pnm, + c.prv_major, c.prv_minor, c.psn, 1997 + c.mdt_year,
This hardcodes 1997 + c.mdt_year which is wrong - see how print_mmc_cid derive the base year.
lsmmc.c static int do_read_reg(int argc, char **argv, enum REG_TYPE reg) · line 2353
Quoted 5 lines
lsmmc.c +5
-0+ month_name(c.mdt_month)); + } + +free (mfr); +}
How about factoring out the shared pieces of month & year into small helpers and have all three callers - print_sd_cid, print_mmc_cid, and print_list_entry use them? Then we would have a single month's table and one place for the base-year logic: unsigned sd_cid_year(...) / unsigned mmc_cid_year(..., ext_csd_rev) Probably as a preparatory patch.
Thanks,
Avri
Quoted 108 lines
lsmmc.c +70
-0+ +int do_list (int nargs,char **argv) +{ +const char *bus_path ="/sys/bus/mmc/devices" ; +DIR *d; +struct dirent *ent; +bool header_printed = false; + + d =opendir (bus_path); +if (!d) { +fprintf (stderr,"Cannot open %s\n" , bus_path); +return -1 ; + } + +struct config cfg = {}; + +/* Probe ids files so any warning appears before table output */ + cfg.bus =SD ; +free (get_manufacturer (&cfg, ~0u )); + cfg.bus =MMC ; +free (get_manufacturer (&cfg, ~0u )); + +while ((ent =readdir (d)) !=NULL ) { +char devpath[PATH_MAX ]; +char resolved[PATH_MAX ]; +char *type, *cid, *blkdev; + +if (!strchr (ent->d_name,':' )) +continue ; + +snprintf (devpath,sizeof (devpath),"%s/%s" , bus_path, ent->d_name); +if (realpath (devpath, resolved) ==NULL ) +continue ; + + type =read_file_at (resolved,"type" ); +if (!type) +continue ; + +if (strcmp (type,"MMC" ) !=0 &&strcmp (type,"SD" ) !=0 ) { +free (type); +continue ; + } + + cid =read_file_at (resolved,"cid" ); +if (!cid) { +free (type); +continue ; + } + + blkdev =find_block_devname (resolved); + cfg.bus =strcmp (type,"MMC" ) ?SD :MMC ; + +if (!header_printed) { +printf ("%-14s %-14s %-5s%-20s %-10s %-5s %-12s %s\n" , +"DEVICE" ,"DEV" ,"TYPE" ,"MANUFACTURER" ,"PRODUCT" , +"REV" ,"SERIAL" ,"DATE" ); + header_printed = true; + } + +print_list_entry (&cfg, ent->d_name, blkdev, cid); + +free (blkdev); +free (cid); +free (type); + } + +closedir (d); +return 0 ; +} +int do_read_csd (int argc,char **argv) { return do_read_reg(argc, argv, CSD); diff --git a/mmc.c b/mmc.c indexfce7eef..b0f1f9b 100644
mmc.c +5
-1@@ -306,6 +306,11 @@ static struct Command commands[] = { "3. Only up to 512K bytes of boot data will be transferred.\n" "4. The MMC will perform a soft reset, if your system cannot handle that do not use the boot operation from mmc-utils.\n", }, + { do_list, 0, + "list", "\n" + "List all MMC/SD devices with their /dev path and CID info.", + NULL + }, { NULL, 0, NULL, NULL } };@@ -590,4 +595,3 @@ int main(int ac, char **av )exit (func (nargs, args)); } -mmc_cmds.h +0
-0@@ -62,6 +62,7 @@ int do_opt_ffu4(int nargs, char **argv); int do_read_scr(intargc, char **argv); int
do_read_cid(int argc, char **argv); intdo_read_csd(int argc, char **argv);
+intdo_list(int nargs, char **argv);
intdo_erase(int nargs, char **argv);
intdo_general_cmd_read(int nargs, char **argv); int do_softreset(int nargs,
char **argv);
--
2.53.0
PATCH v4 3/3 mmc-utils: Add bash completion
In reply to Torstein EideAdd a bash completion script in completion/mmc that completes subcommands and /dev/mmcblkN device paths for all mmc commands.
Subcommand completion is driven by parsing 'mmc help' output rather than maintaining a parallel hardcoded verb list, so it stays in sync as commands are added or removed.
The completion directory is named 'completion/' rather than 'bash-completion/' so shell-specific scripts for other shells (zsh, fish, etc.) can be placed alongside it without renaming.
Add bashcompletiondir variable to the Makefile (defaulting to the standard /usr/share/bash-completion/completions) and install the script as part of 'make install'. The install path can be overridden at build time with make bashcompletiondir=<path>.
--- Makefile | 5 ++++- completion/mmc | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ docs/HOWTO.rst | 6 ++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 completion/mmc
Makefile +4 -1
@@ -7,6 +7,8 @@ AM_CFLAGS = -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 \ -DSD_IDS_PATH=\"$(idsdir)/sdcard.ids\" \ -DMMC_IDS_PATH=\"$(idsdir)/multimediacard.ids\" CFLAGS ?= -g -O2 +idsdir = /usr/share/misc +bashcompletiondir = /usr/share/bash-completion/completions objects = \ mmc.o \ mmc_cmds.o \
@@ -23,7 +25,6 @@ override CFLAGS := $(CHECKFLAGS) $(AM_CFLAGS) $(CFLAGS) INSTALL = install prefix ?= /usr/local bindir = $(prefix)/bin -idsdir ?= /usr/share/misc LIBS= RESTORE_LIBS= mandir = /usr/share/man
@@ -63,6 +64,8 @@ install: $(progs) $(INSTALL) -m755 -d $(DESTDIR)$(idsdir) $(INSTALL) -m 644 sdcard.ids $(DESTDIR)$(idsdir) $(INSTALL) -m 644 multimediacard.ids $(DESTDIR)$(idsdir) + $(INSTALL) -m755 -d $(DESTDIR)$(bashcompletiondir) + $(INSTALL) -m 644 completion/mmc $(DESTDIR)$(bashcompletiondir)/mmc -include $(foreach obj,$(objects), $(dir $(obj))/.$(notdir $(obj)).d)
completion/mmc new file +52 -0
52 lines not on this page · raw message
docs/HOWTO.rst +6 -0
@@ -2,6 +2,12 @@ Running mmc-utils ----------------- +**Bash completion** + Source ``completion/mmc`` to enable tab-completion for all subcommands and + device paths. When installed via ``make install``, the file is placed in + ``$(bashcompletiondir)`` (default: ``/usr/share/bash-completion/completions/mmc``) + and loaded automatically by bash-completion. + **Name** mmc - a tool for configuring MMC storage devices **Synopsis**
Signature · 1 line
2.53.0
RE: [PATCH v4 3/3] mmc-utils: Add bash completion
Quoted 2 lines
Add a bash completion script in completion/mmc that completes subcommands and
/dev/mmcblkNdevice paths for all mmc commands.
rpmb commands e.g. rpmb read-block/write-block etc take /dev/mmcblkNrpmb
Quoted 99 lines
Subcommand completion is driven by parsing 'mmc help' output rather than maintaining a parallel hardcoded verb list, so it stays in sync as commands are added or removed.
The completion directory is named 'completion/' rather than 'bash-completion/' so shell-specific scripts for other shells (zsh, fish, etc.) can be placed alongside it without renaming.
Add bashcompletiondir variable to the
Makefile(defaulting to the standard/usr/share/bash-completion/completions) and install the script as part of 'make install'. The install path can be overridden at build time with make bashcompletiondir=<path>.Signed-off-by Torstein Eide <[email protected]>--- Makefile | 5 ++++- completion/mmc | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ docs/HOWTO.rst | 6 ++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644completion/mmc
Makefile +2
-0@@ -7,6 +7,8 @@ AM_CFLAGS = -D_FILE_OFFSET_BITS=64 - D_FORTIFY_SOURCE=2 \ -DSD_IDS_PATH=\"$(idsdir)/sdcard.ids\" \ -DMMC_IDS_PATH=\"$(idsdir)/multimediacard.ids\" CFLAGS ?= -g -O2 +idsdir = /usr/share/misc +bashcompletiondir = /usr/share/bash-completion/completions objects = \ mmc.o \mmc_cmds.o \Makefile +0
-0@@ -23,7 +25,6 @@ override CFLAGS := $(CHECKFLAGS) $(AM_CFLAGS)$(CFLAGS) INSTALL = install prefix ?=
/usr/localbindir = $(prefix)/bin -idsdir ?=/usr/share/miscLIBS= RESTORE_LIBS= mandir =/usr/share/man@@ -63,6 +64,8 @@ install: $(progs)$(INSTALL) -m755 -d $(DESTDIR)$(idsdir) $(INSTALL) -m 644 sdcard.ids $(DESTDIR)$(idsdir) $(INSTALL) -m 644 multimediacard.ids $(DESTDIR)$(idsdir)Makefile +3
-0+ $(INSTALL) -m755 -d $(DESTDIR)$(bashcompletiondir) + $(INSTALL) -m 644 completion/mmc + $(DESTDIR)$(bashcompletiondir)/mmc -include $(foreach obj,$(objects), $(dir $(obj))/.$(notdir $(obj)).d)completion/mmc new file mode 100644 index renamed from completion/mmc +0
-00000000..1924c15
completion/mmc new file +16
-0@@ -0,0 +1,52 @@ +_mmc_complete() { + local cur prev words cword + _init_completion || return + + local devices + devices=$(compgen -G "/dev/mmcblk*" 2>/dev/null | grep -E + '^/dev/mmcblk[0-9]+$') + + local mmcbin + mmcbin=$(type -P "${words[0]}") || return + + # "mmc help" prints one "Usage for command\t<verb words...> <args...>" + # line per command. Argument placeholders always start with '<', so + # stripping from the first '<' onward leaves just the verb words. + local verbs + verbs=$("$mmcbin" help 2>/dev/null | sed -n 's/^Usage forcommand[[:space:]]*//p' | sed 's/<.*//')
completion/mmc new file +27
-0+ [[ -z $verbs ]] && return + + local -a typed=("${words[@]:1:cword-1}") + local -A next_words=() + local have_leaf= + + local line i match + while IFS= read -r line; do + [[ -z $line ]] && continue + local -a w + read -ra w <<<"$line" + [[ ${#w[@]} -lt ${#typed[@]} ]] && continue + + match=1 + for ((i = 0; i < ${#typed[@]}; i++)); do + if [[ ${w[i]} != "${typed[i]}" ]]; then + match=0 + break + fi + done + [[ $match -eq 0 ]] && continue + + if [[ ${#w[@]} -gt ${#typed[@]} ]]; then + next_words[${w[${#typed[@]}]}]=1 + else + have_leaf=1 + fi
completion/mmc line 52
Quoted 10 lines
completion/mmc new file +10
-0+ done <<<"$verbs" + + if [[ ${#next_words[@]} -gt 0 ]]; then + COMPREPLY=($(compgen -W "${!next_words[*]}" -- "$cur")) + elif [[ -n $have_leaf ]]; then + COMPREPLY=($(compgen -W "$devices" -- "$cur")) + fi +} + +complete -F _mmc_complete mmc
Nit: Maybe also register ./mmc - to allow testing what I've just compile?
Thanks,
Avri
Quoted 21 lines
docs/HOWTO.rst +2
-0@@ -2,6 +2,12 @@ Running mmc-utils ----------------- +**Bash completion** + Source ``completion/mmc`` to enable tab-completion for all subcommandsand
docs/HOWTO.rst +2
-0+ device paths. When installed via ``make install``, the file is placed in + ``$(bashcompletiondir)`` (default: ``/usr/share/bash-completion/completions/mmc``)
docs/HOWTO.rst +2
-1+ and loaded automatically by bash-completion. + **Name** mmc - a tool for configuring MMC storage devices **Synopsis** --2.53.0
Quoted 3 lines
This series improves lsmmc in three areas: external manufacturer ID files and accepting /dev and
/sys/blockpaths for register reads, an mmc list command, and bash completion for mmc-utils.
One structural request: please split the bash completion out of this series. It is independent of the lsmmc work.
Submitting it separately will make both easier to review and merge.
Thanks,
Avri
Quoted 37 lines
Changes since v3 (review by Avri Altman):
- Patch 1 didn't compile on its own: the mmc list implementation (find_block_devname,print_list_entry,do_list,month_name) had accidentally been committed in this patch instead of the "Add mmc list command" patch. Moved all of it out, and squashed in the former patch 2 ("Accept /dev and/sys/blockpaths for register reads") since the two don't have independent value split apart from the list command.
- Patch 2 (Add mmc list command): now contains the full mmc list implementation that previously leaked into patch 1.
- Patch 3 (Add bash completion): subcommand completion is now driven by parsing 'mmc help' output instead of maintaining a parallel hardcoded verb list, so it stays in sync as commands are added or removed.Torstein Eide (3):
mmc-utils: lsmmc: Use external .ids files and accept /dev,/sys/block
paths
mmc-utils: lsmmc: Add mmc list command
mmc-utils: Add bash completionMakefile | 11 +- completion/mmc | 52 ++++ docs/HOWTO.rst | 77 +++++- lsmmc.c | 621 ++++++++++++++++++++++++++------------------- mmc.c | 6 +- mmc_cmds.h | 1 + multimediacard.ids | 16 ++ sdcard.ids | 23 ++ 8 files changed, 533 insertions(+), 274 deletions(-) create mode 100644completion/mmc create mode 100644 multimediacard.ids create mode 100644 sdcard.ids
--
2.53.0