return 0;
}
+static bool mtdblock_is_nand(char *mtdnum)
+{
+ char tmppath[64];
+ char buf[16];
+ FILE *fp;
+
+ snprintf(tmppath, sizeof(tmppath) - 1, "/sys/class/mtd/mtd%s/type", mtdnum);
+ fp = fopen(tmppath, "r");
+ if (!fp)
+ return false;
+
+ if (!fgets(buf, sizeof(buf), fp)) {
+ fclose(fp);
+ return false;
+ }
+ fclose(fp);
+ buf[sizeof(buf) - 1] = '\0'; /* make sure buf is 0-terminated */
+ buf[strlen(buf) - 1] = '\0'; /* strip final char (newline) */
+
+ if (strcmp(buf, "nand"))
+ return false;
+
+ /*
+ * --- CUT HERE ---
+ * Keep probing rootfs and rootfs_data in the meantime to not break
+ * devices using JFFS2 on NAND but only trigger the kernel warnings.
+ * Remove this once all devices using JFFS2 and squashfs directly on
+ * NAND have been converted to UBI.
+ */
+ snprintf(tmppath, sizeof(tmppath) - 1, "/sys/class/mtd/mtd%s/name", mtdnum);
+ fp = fopen(tmppath, "r");
+ if (!fp)
+ return false;
+
+ if (!fgets(buf, sizeof(buf), fp)) {
+ fclose(fp);
+ return false;
+ }
+ fclose(fp);
+ buf[sizeof(buf) - 1] = '\0'; /* make sure buf is 0-terminated */
+ buf[strlen(buf) - 1] = '\0'; /* strip final char (newline) */
+
+ /* only return true if name differs from 'rootfs' and 'rootfs_data' */
+ if (strcmp(buf, "rootfs") && strcmp(buf, "rootfs_data"))
+ return true;
+
+ /* --- CUT HERE --- */
+ return false;
+}
+
static struct probe_info* _probe_path(char *path)
{
- struct probe_info *pr;
+ struct probe_info *pr, *epr;
char tmppath[64];
- /* skip ubi device if ubiblock device is present */
+ if (!strncmp(path, "/dev/mtdblock", 13) && mtdblock_is_nand(path + 13))
+ return NULL;
+
+ pr = probe_path(path);
+ if (!pr)
+ return NULL;
+
if (path[5] == 'u' && path[6] == 'b' && path[7] == 'i' &&
path[8] >= '0' && path[8] <= '9' ) {
+ /* skip ubi device if not UBIFS (as it requires ubiblock) */
+ if (strcmp("ubifs", pr->type))
+ return NULL;
+
+ /* skip ubi device if ubiblock device is present */
snprintf(tmppath, sizeof(tmppath), "/dev/ubiblock%s", path + 8);
- list_for_each_entry(pr, &devices, list)
- if (!strcasecmp(pr->dev, tmppath))
+ list_for_each_entry(epr, &devices, list)
+ if (!strcmp(epr->dev, tmppath))
return NULL;
}
- return probe_path(path);
+ return pr;
}
static int _cache_load(const char *path)
err = exec_mount(source, target, fstype, mount_opts);
}
+ free(mount_opts);
+
return err;
}
static int umount_device(char *path, int type, bool all)
{
- char *mp;
+ char *mp, *devpath;
int err;
- mp = find_mount_point(path);
+ if (strlen(path) > 5 && !strncmp("/dev/", path, 5)) {
+ mp = find_mount_point(path);
+ } else {
+ devpath = malloc(strlen(path) + 6);
+ strcpy(devpath, "/dev/");
+ strcat(devpath, path);
+ mp = find_mount_point(devpath);
+ free(devpath);
+ }
+
if (!mp)
return -1;
- if (!strcmp(mp, "/") && !all)
+ if (!strcmp(mp, "/") && !all) {
+ free(mp);
return 0;
-
+ }
if (type != TYPE_AUTOFS)
blockd_notify("umount", basename(path), NULL, NULL);