mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-23 17:55:01 +00:00
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>
This commit is contained in:
@@ -177,6 +177,7 @@ static int do_search(CgptFindParams *params, char *fileName) {
|
|||||||
#define PROC_PARTITIONS "/proc/partitions"
|
#define PROC_PARTITIONS "/proc/partitions"
|
||||||
#define DEV_DIR "/dev"
|
#define DEV_DIR "/dev"
|
||||||
#define SYS_BLOCK_DIR "/sys/block"
|
#define SYS_BLOCK_DIR "/sys/block"
|
||||||
|
#define MAX_PARTITION_NAME_LEN 128
|
||||||
|
|
||||||
static const char *devdirs[] = { "/dev", "/devices", "/devfs", 0 };
|
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.
|
// returns true if any matches were found, false otherwise.
|
||||||
static int scan_real_devs(CgptFindParams *params) {
|
static int scan_real_devs(CgptFindParams *params) {
|
||||||
int found = 0;
|
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;
|
FILE *fp;
|
||||||
char *pathname;
|
char *pathname;
|
||||||
|
|
||||||
@@ -231,6 +233,7 @@ static int scan_real_devs(CgptFindParams *params) {
|
|||||||
|
|
||||||
size_t line_length = 0;
|
size_t line_length = 0;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
|
partname_prev[0] = '\0';
|
||||||
while (getline(&line, &line_length, fp) != -1) {
|
while (getline(&line, &line_length, fp) != -1) {
|
||||||
int ma, mi;
|
int ma, mi;
|
||||||
long long unsigned int sz;
|
long long unsigned int sz;
|
||||||
@@ -238,13 +241,21 @@ static int scan_real_devs(CgptFindParams *params) {
|
|||||||
if (sscanf(line, " %d %d %llu %127[^\n ]", &ma, &mi, &sz, partname) != 4)
|
if (sscanf(line, " %d %d %llu %127[^\n ]", &ma, &mi, &sz, partname) != 4)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((pathname = is_wholedev(partname))) {
|
/* 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)) {
|
if (do_search(params, pathname)) {
|
||||||
found++;
|
found++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strcpy(partname_prev, partname);
|
||||||
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
fp = fopen(PROC_MTD, "re");
|
fp = fopen(PROC_MTD, "re");
|
||||||
|
|||||||
Reference in New Issue
Block a user