libfstools: check for overlay mounting errors
[project/fstools.git] / libfstools / overlay.c
index d7d8f48e1279589e5f55127fa6c6a068878d5892..87fad1144397d99b735aa1418365c6aaeda1a8cf 100644 (file)
@@ -175,14 +175,20 @@ static int
 switch2jffs(struct volume *v)
 {
        struct stat s;
-       int ret;
+       int ret, fd;
 
        if (!stat(SWITCH_JFFS2, &s)) {
                ULOG_ERR("jffs2 switch already running\n");
                return -1;
        }
 
-       creat(SWITCH_JFFS2, 0600);
+       fd = creat(SWITCH_JFFS2, 0600);
+       if (fd == -1) {
+               ULOG_ERR("failed - cannot create jffs2 switch mark: %m\n");
+               return -1;
+       }
+       close(fd);
+
        ret = mount(v->blk, OVERLAYDIR, "jffs2", MS_NOATIME, NULL);
        unlink(SWITCH_JFFS2);
        if (ret) {
@@ -410,6 +416,7 @@ int fs_state_set(const char *dir, enum fs_state state)
 int mount_overlay(struct volume *v)
 {
        char *mp, *fs_name;
+       int err;
 
        if (!v)
                return -1;
@@ -420,7 +427,9 @@ int mount_overlay(struct volume *v)
                return -1;
        }
 
-       overlay_mount_fs(v);
+       err = overlay_mount_fs(v);
+       if (err)
+               return err;
 
        extroot_prefix = "/tmp/overlay";
        if (!mount_extroot()) {