summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafał Miłecki <rafal@milecki.pl>2020-05-05 08:49:17 +0200
committerRafał Miłecki <rafal@milecki.pl>2020-05-05 08:49:17 +0200
commit37c9148a3ae17665e75f99b459b6ff2b461d6739 (patch)
tree7de2e919e73ba8b8d37446e50bcc407b1cccfdf9
parentd70774de24413f91087e9c3c873cf7a4ec3df813 (diff)
downloadfstools-37c9148a3ae17665e75f99b459b6ff2b461d6739.tar.gz
block: simplify check_extroot() a bit
Avoid too big code indent. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
-rw-r--r--block.c89
1 files changed, 47 insertions, 42 deletions
diff --git a/block.c b/block.c
index a7631c4..fd35d6b 100644
--- a/block.c
+++ b/block.c
@@ -1386,7 +1386,12 @@ static int test_fs_support(const char *name)
static int check_extroot(char *path)
{
struct probe_info *pr = NULL;
+ struct probe_info *tmp;
+ struct stat s;
+ char uuid[64] = { 0 };
char devpath[32];
+ char tag[64];
+ FILE *fp;
#ifdef UBIFS_EXTROOT
if (find_block_mtd("\"rootfs\"", devpath, sizeof(devpath))) {
@@ -1408,53 +1413,53 @@ static int check_extroot(char *path)
}
#endif
- list_for_each_entry(pr, &devices, list) {
- if (!strcmp(pr->dev, devpath)) {
- struct stat s;
- FILE *fp = NULL;
- char tag[64];
- char uuid[64] = { 0 };
-
- snprintf(tag, sizeof(tag), "%s/etc", path);
- if (stat(tag, &s))
- mkdir_p(tag);
-
- snprintf(tag, sizeof(tag), "%s/etc/.extroot-uuid", path);
- if (stat(tag, &s)) {
- fp = fopen(tag, "w+");
- if (!fp) {
- ULOG_ERR("extroot: failed to write UUID to %s: %d (%m)\n",
- tag, errno);
- /* return 0 to continue boot regardless of error */
- return 0;
- }
- fputs(pr->uuid, fp);
- fclose(fp);
- return 0;
- }
-
- fp = fopen(tag, "r");
- if (!fp) {
- ULOG_ERR("extroot: failed to read UUID from %s: %d (%m)\n",
- tag, errno);
- return -1;
- }
+ /* Find root device probe_info so we know its UUID */
+ list_for_each_entry(tmp, &devices, list) {
+ if (!strcmp(tmp->dev, devpath)) {
+ pr = tmp;
+ break;
+ }
+ }
+ if (!pr) {
+ ULOG_ERR("extroot: unable to lookup root device %s\n", devpath);
+ return -1;
+ }
- if (!fgets(uuid, sizeof(uuid), fp))
- ULOG_ERR("extroot: failed to read UUID from %s: %d (%m)\n",
- tag, errno);
- fclose(fp);
+ snprintf(tag, sizeof(tag), "%s/etc", path);
+ if (stat(tag, &s))
+ mkdir_p(tag);
- if (*uuid && !strcasecmp(uuid, pr->uuid))
- return 0;
-
- ULOG_ERR("extroot: UUID mismatch (root: %s, %s: %s)\n",
- pr->uuid, basename(path), uuid);
- return -1;
+ snprintf(tag, sizeof(tag), "%s/etc/.extroot-uuid", path);
+ if (stat(tag, &s)) {
+ fp = fopen(tag, "w+");
+ if (!fp) {
+ ULOG_ERR("extroot: failed to write UUID to %s: %d (%m)\n",
+ tag, errno);
+ /* return 0 to continue boot regardless of error */
+ return 0;
}
+ fputs(pr->uuid, fp);
+ fclose(fp);
+ return 0;
}
- ULOG_ERR("extroot: unable to lookup root device %s\n", devpath);
+ fp = fopen(tag, "r");
+ if (!fp) {
+ ULOG_ERR("extroot: failed to read UUID from %s: %d (%m)\n", tag,
+ errno);
+ return -1;
+ }
+
+ if (!fgets(uuid, sizeof(uuid), fp))
+ ULOG_ERR("extroot: failed to read UUID from %s: %d (%m)\n", tag,
+ errno);
+ fclose(fp);
+
+ if (*uuid && !strcasecmp(uuid, pr->uuid))
+ return 0;
+
+ ULOG_ERR("extroot: UUID mismatch (root: %s, %s: %s)\n", pr->uuid,
+ basename(path), uuid);
return -1;
}