]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/udev/udev-builtin-blkid.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / udev / udev-builtin-blkid.c
index 5b976abd8d70dbb2f607af0b394e22e43a301372..004ddb023f3b337d886453c8cee60cdab340a8e4 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <string.h>
+#include <blkid/blkid.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/stat.h>
-#include <blkid/blkid.h>
 
 #include "sd-id128.h"
-#include "gpt.h"
+
 #include "efivars.h"
+#include "gpt.h"
+#include "string-util.h"
 #include "udev.h"
 
-static void print_property(struct udev_device *dev, bool test, const char *name, const char *value)
-{
+static void print_property(struct udev_device *dev, bool test, const char *name, const char *value) {
         char s[256];
 
         s[0] = '\0';
@@ -146,6 +145,11 @@ static int find_gpt_root(struct udev_device *dev, blkid_probe pr, bool test) {
 
                 if (sd_id128_equal(type, GPT_ESP)) {
                         sd_id128_t id, esp;
+                        unsigned long long flags;
+
+                        flags = blkid_partition_get_flags(pp);
+                        if (flags & GPT_FLAG_NO_AUTO)
+                                continue;
 
                         /* We found an ESP, let's see if it matches
                          * the ESP we booted from. */
@@ -182,8 +186,7 @@ static int find_gpt_root(struct udev_device *dev, blkid_probe pr, bool test) {
         return 0;
 }
 
-static int probe_superblocks(blkid_probe pr)
-{
+static int probe_superblocks(blkid_probe pr) {
         struct stat st;
         int rc;
 
@@ -215,8 +218,7 @@ static int probe_superblocks(blkid_probe pr)
         return blkid_do_safeprobe(pr);
 }
 
-static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool test)
-{
+static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool test) {
         const char *root_partition;
         int64_t offset = 0;
         bool noraid = false;
@@ -224,9 +226,9 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t
         blkid_probe pr;
         const char *data;
         const char *name;
+        const char *prtype = NULL;
         int nvals;
         int i;
-        size_t len;
         int err = 0;
         bool is_gpt = false;
 
@@ -260,14 +262,15 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t
         blkid_probe_set_superblocks_flags(pr,
                 BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
                 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
-                BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION);
+                BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
+                BLKID_SUBLKS_BADCSUM);
 
         if (noraid)
                 blkid_probe_filter_superblocks_usage(pr, BLKID_FLTR_NOTIN, BLKID_USAGE_RAID);
 
         fd = open(udev_device_get_devnode(dev), O_RDONLY|O_CLOEXEC);
         if (fd < 0) {
-                fprintf(stderr, "error: %s: %m\n", udev_device_get_devnode(dev));
+                err = log_debug_errno(errno, "Failure opening block device %s: %m", udev_device_get_devnode(dev));
                 goto out;
         }
 
@@ -275,13 +278,22 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t
         if (err < 0)
                 goto out;
 
-        log_debug("probe %s %sraid offset=%llu",
+        log_debug("probe %s %sraid offset=%"PRIi64,
                   udev_device_get_devnode(dev),
-                  noraid ? "no" : "", (unsigned long long) offset);
+                  noraid ? "no" : "", offset);
 
         err = probe_superblocks(pr);
         if (err < 0)
                 goto out;
+        if (blkid_probe_has_value(pr, "SBBADCSUM")) {
+                if (!blkid_probe_lookup_value(pr, "TYPE", &prtype, NULL))
+                        log_warning("incorrect %s checksum on %s",
+                                    prtype, udev_device_get_devnode(dev));
+                else
+                        log_warning("incorrect checksum on %s",
+                                    udev_device_get_devnode(dev));
+                goto out;
+        }
 
         /* If we are a partition then our parent passed on the root
          * partition UUID to us */
@@ -289,11 +301,10 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t
 
         nvals = blkid_probe_numof_values(pr);
         for (i = 0; i < nvals; i++) {
-                if (blkid_probe_get_value(pr, i, &name, &data, &len))
+                if (blkid_probe_get_value(pr, i, &name, &data, NULL))
                         continue;
 
-                len = strnlen((char *) data, len);
-                print_property(dev, test, name, (char *) data);
+                print_property(dev, test, name, data);
 
                 /* Is this a disk with GPT partition table? */
                 if (streq(name, "PTTYPE") && streq(data, "gpt"))
@@ -319,6 +330,6 @@ out:
 const struct udev_builtin udev_builtin_blkid = {
         .name = "blkid",
         .cmd = builtin_blkid,
-        .help = "filesystem and partition probing",
+        .help = "Filesystem and partition probing",
         .run_once = true,
 };