dev->bid_devno == devno)
goto set_pri;
- if (stat(device, &st) == 0 && S_ISBLK(st.st_mode) &&
+ if (stat(device, &st) == 0 &&
+ (S_ISBLK(st.st_mode) ||
+ (S_ISCHR(st.st_mode) && !strncmp(ptname, "ubi", 3))) &&
st.st_rdev == devno) {
devname = blkid_strdup(device);
goto get_dev;
return num;
}
+static void
+ubi_probe_all(blkid_cache cache, int only_if_new)
+{
+ const char **dirname;
+
+ for (dirname = dirlist; *dirname; dirname++) {
+ DBG(DEBUG_DEVNAME, printf("probing UBI volumes under %s\n",
+ *dirname));
+
+ DIR *dir;
+ struct dirent *iter;
+
+ dir = opendir(*dirname);
+ if (dir == NULL)
+ continue ;
+
+ while ((iter = readdir(dir)) != NULL) {
+ char *name, *device;
+ struct stat st;
+ dev_t dev;
+
+ name = iter->d_name;
+
+ if (!strcmp(name, ".") || !strcmp(name, "..") ||
+ !strstr(name, "ubi"))
+ continue;
+ if (!strcmp(name, "ubi_ctrl"))
+ continue;
+ device = malloc(strlen(*dirname) + strlen(name) + 2);
+ if (!device)
+ break ;
+ sprintf(device, "%s/%s", *dirname, name);
+ if (stat(device, &st))
+ break ;
+
+ if (!(st.st_rdev & 0xFF)) { // It's an UBI Device
+ free(device);
+ continue ;
+ }
+ dev = st.st_rdev;
+ DBG(DEBUG_DEVNAME, printf("UBI vol %s: devno 0x%04X\n",
+ device,
+ (int) dev));
+ probe_one(cache, name, dev, BLKID_PRI_UBI,
+ only_if_new);
+ free(device);
+ }
+ closedir(dir);
+ }
+}
+
/*
* Read the device data for all available block devices in the system.
*/
#ifdef VG_DIR
lvm_probe_all(cache, only_if_new);
#endif
+ ubi_probe_all(cache, only_if_new);
proc = fopen(PROC_PARTITIONS, "r");
if (!proc)
pr->mode = sb.st_mode;
- if (S_ISBLK(sb.st_mode)) {
+ if (S_ISBLK(sb.st_mode))
blkdev_get_size(fd, (unsigned long long *) &pr->size);
+ else if (S_ISCHR(sb.st_mode))
+ pr->size = 1; /* UBI devices are char... */
+ else
+ pr->size = sb.st_size; /* regular file */
+
+ if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode))
pr->devno = sb.st_rdev;
- } else
- pr->size = sb.st_size;
}
+
if (!pr->size)
return -1;
if (!pr->devno) {
struct stat sb;
- if (fstat(pr->fd, &sb) == 0 && S_ISBLK(sb.st_mode))
+ if (fstat(pr->fd, &sb) == 0 &&
+ (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)))
pr->devno = sb.st_rdev;
}
return pr->devno;