libblkid-tiny: add support for UBI superblock
[project/fstools.git] / libblkid-tiny / libblkid-tiny.c
index a01a43e..352d1f6 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <sys/utsname.h>
 
+#include "libblkid-tiny.h"
 #include "superblocks.h"
 #include "linux_version.h"
 
@@ -124,13 +125,12 @@ int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *nam
 {
        short unsigned int*u = (short unsigned int*) uuid;
 
-       if (u[0])
+       if (u[0] && (!name || !strcmp(name, "UUID"))) {
                sprintf(pr->uuid,
                        "%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
                        be16_to_cpu(u[0]), be16_to_cpu(u[1]), be16_to_cpu(u[2]), be16_to_cpu(u[3]),
                        be16_to_cpu(u[4]), be16_to_cpu(u[5]), be16_to_cpu(u[6]), be16_to_cpu(u[7]));
-       if (name)
-               strncpy(pr->name, name, sizeof(pr->name));
+       }
 
        return 0;
 }
@@ -163,10 +163,13 @@ static const struct blkid_idinfo *idinfos[] =
        &ext2_idinfo,
        &jbd_idinfo,
        &squashfs_idinfo,
+       &ubi_idinfo,
        &ubifs_idinfo,
        &jffs2_idinfo,
        &hfsplus_idinfo,
        &hfs_idinfo,
+       &btrfs_idinfo,
+       &f2fs_idinfo,
 };
 
 int probe_block(char *block, struct blkid_struct_probe *pr)
@@ -174,7 +177,7 @@ int probe_block(char *block, struct blkid_struct_probe *pr)
        struct stat s;
        int i;
 
-       if (stat(block, &s) || (!S_ISBLK(s.st_mode) && !S_ISREG(s.st_mode)))
+       if (stat(block, &s) || (!S_ISBLK(s.st_mode) && !S_ISREG(s.st_mode) && !strncmp(block, "ubi", 3)))
                return -1;
 
        pr->err = -1;
@@ -196,7 +199,8 @@ int probe_block(char *block, struct blkid_struct_probe *pr)
                        char magic[32] = { 0 };
 
                        lseek(pr->fd, off, SEEK_SET);
-                       read(pr->fd, magic, mag->len);
+                       if (read(pr->fd, magic, mag->len) < 0)
+                               return -1;
 
                        DEBUG("magic: %s %s %d\n", mag->magic, magic, mag->len);
                        if (!memcmp(mag->magic, magic, mag->len))