summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_find.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgpt/cgpt_find.c')
-rw-r--r--cgpt/cgpt_find.c119
1 files changed, 69 insertions, 50 deletions
diff --git a/cgpt/cgpt_find.c b/cgpt/cgpt_find.c
index 6f4bbae5..8046aad3 100644
--- a/cgpt/cgpt_find.c
+++ b/cgpt/cgpt_find.c
@@ -96,19 +96,6 @@ static void showmatch(CgptFindParams *params, const char *filename,
EntryDetails(entry, partnum - 1, params->numeric);
}
-// This handles the MTD devices. ChromeOS uses /dev/mtdX for kernel partitions,
-// /dev/ubiblockX_0 for root partitions, and /dev/ubiX for stateful partition.
-static void chromeos_mtd_show(CgptFindParams *params, const char *filename,
- int partnum, GptEntry *entry) {
- if (GuidEqual(&guid_chromeos_kernel, &entry->type)) {
- printf("/dev/mtd%d\n", partnum);
- } else if (GuidEqual(&guid_chromeos_rootfs, &entry->type)) {
- printf("/dev/ubiblock%d_0\n", partnum);
- } else {
- printf("/dev/ubi%d_0\n", partnum);
- }
-}
-
// This returns true if a GPT partition matches the search criteria. If a match
// isn't found (or if the file doesn't contain a GPT), it returns false. The
// filename and partition number that matched is left in a global, since we
@@ -214,51 +201,29 @@ static char *is_wholedev(const char *basename) {
return 0;
}
-// This scans all the physical devices it can find, looking for a match. It
-// returns true if any matches were found, false otherwise.
-static int scan_real_devs(CgptFindParams *params) {
+#ifdef GPT_SPI_NOR
+// This handles the MTD devices. ChromeOS uses /dev/mtdX for kernel partitions,
+// /dev/ubiblockX_0 for root partitions, and /dev/ubiX for stateful partition.
+static void chromeos_mtd_show(CgptFindParams *params, const char *filename,
+ int partnum, GptEntry *entry) {
+ if (GuidEqual(&guid_chromeos_kernel, &entry->type)) {
+ printf("/dev/mtd%d\n", partnum);
+ } else if (GuidEqual(&guid_chromeos_rootfs, &entry->type)) {
+ printf("/dev/ubiblock%d_0\n", partnum);
+ } else {
+ printf("/dev/ubi%d_0\n", partnum);
+ }
+}
+
+static int scan_spi_gpt(CgptFindParams *params) {
int found = 0;
char partname[MAX_PARTITION_NAME_LEN];
- char partname_prev[MAX_PARTITION_NAME_LEN];
FILE *fp;
- char *pathname;
-
- fp = fopen(PROC_PARTITIONS, "re");
- if (!fp) {
- perror("can't read " PROC_PARTITIONS);
- return found;
- }
-
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;
-
- if (sscanf(line, " %d %d %llu %127[^\n ]", &ma, &mi, &sz, partname) != 4)
- continue;
-
- /* 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);
fp = fopen(PROC_MTD, "re");
if (!fp) {
- free(line);
return found;
}
@@ -299,6 +264,60 @@ cleanup:
free(line);
return found;
}
+#else
+// Stub
+static int scan_spi_gpt(CgptFindParams *params) {
+ return 0;
+}
+#endif
+
+// This scans all the physical devices it can find, looking for a match. It
+// returns true if any matches were found, false otherwise.
+static int scan_real_devs(CgptFindParams *params) {
+ int found = 0;
+ char partname[MAX_PARTITION_NAME_LEN];
+ char partname_prev[MAX_PARTITION_NAME_LEN];
+ FILE *fp;
+ char *pathname;
+
+ fp = fopen(PROC_PARTITIONS, "re");
+ if (!fp) {
+ perror("can't read " PROC_PARTITIONS);
+ return found;
+ }
+
+ 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;
+
+ if (sscanf(line, " %d %d %llu %127[^\n ]", &ma, &mi, &sz, partname) != 4)
+ continue;
+
+ /* 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);
+ free(line);
+
+ found += scan_spi_gpt(params);
+
+ return found;
+}
void CgptFind(CgptFindParams *params) {