dissect-image: return error if results are ambiguous
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 30 Nov 2017 11:09:36 +0000 (12:09 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 30 Nov 2017 19:46:30 +0000 (20:46 +0100)
We let the caller make the decision. Existing callers are OK with treating an
ambiguous result the same as no content, but makefs and growfs should refuse such
partitions.

src/partition/growfs.c
src/partition/makefs.c
src/shared/dissect-image.c

index f9c604c..8b44c1d 100644 (file)
@@ -151,6 +151,8 @@ static int maybe_resize_slave_device(const char *mountpath, dev_t main_devno) {
 
         xsprintf_dev_num_path(devpath, "block", devno);
         r = probe_filesystem(devpath, &fstype);
+        if (r == -EUCLEAN)
+                return log_warning_errno(r, "Cannot reliably determine probe \"%s\", refusing to proceed.", devpath);
         if (r < 0)
                 return log_warning_errno(r, "Failed to probe \"%s\": %m", devpath);
 
index c24c6eb..e5e1252 100644 (file)
@@ -90,7 +90,11 @@ int main(int argc, char *argv[]) {
 
         r = probe_filesystem(device, &detected);
         if (r < 0) {
-                log_warning_errno(r, "Failed to probe \"%s\": %m", device);
+                log_warning_errno(r,
+                                  r == -EUCLEAN ?
+                                  "Cannot reliably determine probe \"%s\", refusing to proceed." :
+                                  "Failed to probe \"%s\": %m",
+                                  device);
                 goto finish;
         }
 
index 3c16f60..7835d99 100644 (file)
 #include "xattr-util.h"
 
 int probe_filesystem(const char *node, char **ret_fstype) {
+        /* Try to find device content type and return it in *ret_fstype. If nothing is found,
+         * 0/NULL will be returned. -EUCLEAN will be returned for ambigous results, and an
+         * different error otherwise. */
+
 #if HAVE_BLKID
         _cleanup_blkid_free_probe_ blkid_probe b = NULL;
         const char *fstype;
@@ -67,10 +71,14 @@ int probe_filesystem(const char *node, char **ret_fstype) {
 
         errno = 0;
         r = blkid_do_safeprobe(b);
-        if (IN_SET(r, -2, 1)) {
-                log_debug("Failed to identify any partition type on partition %s", node);
+        if (r == 1) {
+                log_debug("No type detected on partition %s", node);
                 goto not_found;
         }
+        if (r == -2) {
+                log_debug("Results ambiguous for partition %s", node);
+                return -EUCLEAN;
+        }
         if (r != 0)
                 return -errno ?: -EIO;
 
@@ -608,7 +616,7 @@ int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectI
 
                 if (!p->fstype && p->node) {
                         r = probe_filesystem(p->node, &p->fstype);
-                        if (r < 0)
+                        if (r < 0 && r != -EUCLEAN)
                                 return r;
                 }
 
@@ -1018,7 +1026,7 @@ int dissected_image_decrypt(
 
                 if (!p->decrypted_fstype && p->decrypted_node) {
                         r = probe_filesystem(p->decrypted_node, &p->decrypted_fstype);
-                        if (r < 0)
+                        if (r < 0 && r != -EUCLEAN)
                                 return r;
                 }
         }