summaryrefslogtreecommitdiffstats
path: root/shlibs
diff options
context:
space:
mode:
authorCorentin Chary2009-08-24 13:11:54 +0200
committerKarel Zak2009-09-24 15:42:48 +0200
commitc1ba7962f60672be37f41a5d01c10acf46442f2e (patch)
tree3aa18255f8bcf7f2ce0178fd73a68be62b4ff2e4 /shlibs
parentblkid: allow to use -s <TAG> for low-level probing (-p mode) (diff)
downloadkernel-qcow2-util-linux-c1ba7962f60672be37f41a5d01c10acf46442f2e.tar.gz
kernel-qcow2-util-linux-c1ba7962f60672be37f41a5d01c10acf46442f2e.tar.xz
kernel-qcow2-util-linux-c1ba7962f60672be37f41a5d01c10acf46442f2e.zip
libblkid: add UBI volume support
Probe UBI volume under /dev (or /devfs, /devices). ubi_ctrl skip is hardcoded, maybe we should find a cleaner way to do that. Also change probe.c to handle char devices. [kzak@redhat.com: - rebase the patch to the current HEAD] Signed-off-by: Corentin Chary <corentincj@iksaif.net> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs')
-rw-r--r--shlibs/blkid/src/blkidP.h1
-rw-r--r--shlibs/blkid/src/devname.c56
-rw-r--r--shlibs/blkid/src/probe.c14
3 files changed, 66 insertions, 5 deletions
diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h
index 40002c5c6..68116c0ca 100644
--- a/shlibs/blkid/src/blkidP.h
+++ b/shlibs/blkid/src/blkidP.h
@@ -294,6 +294,7 @@ extern char *blkid_strndup(const char *s, const int length);
/*
* Priority settings for different types of devices
*/
+#define BLKID_PRI_UBI 50
#define BLKID_PRI_DM 40
#define BLKID_PRI_EVMS 30
#define BLKID_PRI_LVM 20
diff --git a/shlibs/blkid/src/devname.c b/shlibs/blkid/src/devname.c
index f0672ddcd..1acb9d5a4 100644
--- a/shlibs/blkid/src/devname.c
+++ b/shlibs/blkid/src/devname.c
@@ -229,7 +229,9 @@ static void probe_one(blkid_cache cache, const char *ptname,
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;
@@ -388,6 +390,57 @@ evms_probe_all(blkid_cache cache, int only_if_new)
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.
*/
@@ -419,6 +472,7 @@ static int probe_all(blkid_cache cache, int only_if_new)
#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)
diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c
index bac49771e..89c16a201 100644
--- a/shlibs/blkid/src/probe.c
+++ b/shlibs/blkid/src/probe.c
@@ -522,12 +522,17 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
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;
@@ -842,7 +847,8 @@ dev_t blkid_probe_get_devno(blkid_probe pr)
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;