summaryrefslogtreecommitdiffstats
path: root/libs/blkid/src/probe.c
diff options
context:
space:
mode:
authorKarel Zak2009-01-22 01:06:57 +0100
committerKarel Zak2009-02-11 23:35:23 +0100
commitbb6c6673638629ead01c3cbd9bb2837799d1eef2 (patch)
tree6b25eff1b4ffddc2e2420633ebf7ae5f8265f2e6 /libs/blkid/src/probe.c
parentblkid: add netware regression test (diff)
downloadkernel-qcow2-util-linux-bb6c6673638629ead01c3cbd9bb2837799d1eef2.tar.gz
kernel-qcow2-util-linux-bb6c6673638629ead01c3cbd9bb2837799d1eef2.tar.xz
kernel-qcow2-util-linux-bb6c6673638629ead01c3cbd9bb2837799d1eef2.zip
blkid: set size for non-blkdevs, add blkid_probe_strcpy_uuid()
- fix blkid_probe_set_device() to work for non-blkdevs (e.g. file images), in such case we need to set the size of data from stat->st_size - add blkid_probe_strcpy_uuid() for filesystems where UUID is stored as a string (e.g. DDF raid, luks, ...) Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libs/blkid/src/probe.c')
-rw-r--r--libs/blkid/src/probe.c68
1 files changed, 47 insertions, 21 deletions
diff --git a/libs/blkid/src/probe.c b/libs/blkid/src/probe.c
index 5a4fad746..527193887 100644
--- a/libs/blkid/src/probe.c
+++ b/libs/blkid/src/probe.c
@@ -256,11 +256,23 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
pr->fd = fd;
pr->off = off;
+ pr->size = 0;
- if (!size)
- blkdev_get_size(fd, (unsigned long long *) &pr->size);
- else
+ if (size)
pr->size = size;
+ else {
+ struct stat sb;
+
+ if (fstat(fd, &sb))
+ return -1;
+
+ if (S_ISBLK(sb.st_mode))
+ blkdev_get_size(fd, (unsigned long long *) &pr->size);
+ else
+ pr->size = sb.st_size;
+ }
+ if (!pr->size)
+ return -1;
/* read SB to test if the device is readable */
if (!blkid_probe_get_buffer(pr, 0, 0x200)) {
@@ -269,7 +281,8 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
return -1;
}
- DBG(DEBUG_LOWPROBE, printf("a new device prepared for low-probing\n"));
+ DBG(DEBUG_LOWPROBE, printf("ready for low-probing, offset=%zd, size=%zd\n",
+ pr->off, pr->size));
pr->idx = 0;
return 0;
}
@@ -467,7 +480,7 @@ int blkid_do_probe(blkid_probe pr)
mag++;
}
- if (mag && mag->magic == NULL)
+ if (id->magics && id->magics[0].magic)
/* magic string(s) defined, but not found */
continue;
@@ -712,22 +725,7 @@ int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,
return 0;
va_start(ap, fmt);
-
- if (!strcmp(fmt, "%s")) {
- struct blkid_prval *v = NULL;
- const char *str = va_arg(ap, char *);
-
- if (str && *str)
- v = blkid_probe_assign_value(pr, "UUID");
- if (v) {
- strncpy((char *) v->data, str, BLKID_PROBVAL_BUFSIZ);
- v->data[BLKID_PROBVAL_BUFSIZ - 1] = '\0';
- v->len = strlen((char *) v->data);
- rc = 0;
- }
- } else
- rc = blkid_probe_vsprintf_value(pr, "UUID", fmt, ap);
-
+ rc = blkid_probe_vsprintf_value(pr, "UUID", fmt, ap);
va_end(ap);
/* convert to lower case (..be paranoid) */
@@ -742,6 +740,34 @@ int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,
return rc;
}
+/* function to set UUIDs that are in suberblocks stored as strings */
+int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len)
+{
+ struct blkid_prval *v;
+
+ if (str == NULL || *str == '\0')
+ return -1;
+ if (!len)
+ len = strlen((char *) str);
+ if (len > BLKID_PROBVAL_BUFSIZ)
+ len = BLKID_PROBVAL_BUFSIZ;
+
+ if ((pr->probreq & BLKID_PROBREQ_UUIDRAW) &&
+ blkid_probe_set_value(pr, "UUID_RAW", str, len) < 0)
+ return -1;
+ if (!(pr->probreq & BLKID_PROBREQ_UUID))
+ return 0;
+
+ v = blkid_probe_assign_value(pr, "UUID");
+ if (v) {
+ memcpy((char *) v->data, str, len);
+ v->data[len - 1] = '\0';
+ v->len = len;
+ return 0;
+ }
+ return -1;
+}
+
/* default _set_uuid function to set DCE UUIDs */
int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *name)
{