diff options
author | Jeffy Chen <jeffy.chen@rock-chips.com> | 2017-02-20 21:26:58 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-02-24 05:42:55 -0800 |
commit | b1b5cf7ee83a7f70c23f015a53a34948bf23dd11 (patch) | |
tree | 4bfacf65a601a0ecdebddab6468dcf51170608a0 /cgpt | |
parent | 83bd850f3fd45648bb811f6080efac396c8a2062 (diff) | |
download | vboot-b1b5cf7ee83a7f70c23f015a53a34948bf23dd11.tar.gz |
cgpt: find: filter out more devices before touching them
A partition's name would always start with the disk name. And in
/proc/partitions, the partitions are always listed right after the
disk.
Let's filter out devices which are not followed by partitions when
go through the /proc/partitions.
BUG=chrome-os-partner:62955
TEST=run "cgpt find -t kernel" on kevin, no more this warning:
blk_update_request: I/O error, dev mmcblk0rpmb
Change-Id: If200a2476d26b1beaf644838d47ea2e60552855e
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Reviewed-on: https://chromium-review.googlesource.com/444492
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'cgpt')
-rw-r--r-- | cgpt/cgpt_find.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/cgpt/cgpt_find.c b/cgpt/cgpt_find.c index c35aade2..a02ad7ae 100644 --- a/cgpt/cgpt_find.c +++ b/cgpt/cgpt_find.c @@ -177,6 +177,7 @@ static int do_search(CgptFindParams *params, char *fileName) { #define PROC_PARTITIONS "/proc/partitions" #define DEV_DIR "/dev" #define SYS_BLOCK_DIR "/sys/block" +#define MAX_PARTITION_NAME_LEN 128 static const char *devdirs[] = { "/dev", "/devices", "/devfs", 0 }; @@ -219,7 +220,8 @@ static char *is_wholedev(const char *basename) { // returns true if any matches were found, false otherwise. static int scan_real_devs(CgptFindParams *params) { int found = 0; - char partname[128]; // max size for /proc/partition lines? + char partname[MAX_PARTITION_NAME_LEN]; + char partname_prev[MAX_PARTITION_NAME_LEN]; FILE *fp; char *pathname; @@ -231,6 +233,7 @@ static int scan_real_devs(CgptFindParams *params) { size_t line_length = 0; char *line = NULL; + partname_prev[0] = '\0'; while (getline(&line, &line_length, fp) != -1) { int ma, mi; long long unsigned int sz; @@ -238,11 +241,19 @@ static int scan_real_devs(CgptFindParams *params) { if (sscanf(line, " %d %d %llu %127[^\n ]", &ma, &mi, &sz, partname) != 4) continue; - if ((pathname = is_wholedev(partname))) { - if (do_search(params, pathname)) { - found++; + /* Only check devices that have partitions under them. + * We can tell by checking that an entry like "sda" is immediately + * followed by one like "sda0". */ + if (!strncmp(partname_prev, partname, strlen(partname_prev)) && + strlen(partname_prev)) { + if ((pathname = is_wholedev(partname_prev))) { + if (do_search(params, pathname)) { + found++; + } } } + + strcpy(partname_prev, partname); } fclose(fp); |