2020-11-09 05:25:50 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2011-12-21 22:30:48 +01:00
|
|
|
/*
|
|
|
|
* probe disks for filesystems and partitions
|
|
|
|
*
|
2018-06-12 17:15:23 +02:00
|
|
|
* Copyright © 2011 Karel Zak <kzak@redhat.com>
|
2011-12-21 22:30:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2011-12-23 03:16:56 +01:00
|
|
|
#include <getopt.h>
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-12-21 22:30:48 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
#include "sd-id128.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2017-06-16 22:44:57 +02:00
|
|
|
#include "blkid-util.h"
|
2018-10-23 20:01:19 +02:00
|
|
|
#include "device-util.h"
|
2019-08-01 16:28:29 +02:00
|
|
|
#include "efi-loader.h"
|
2019-07-11 15:42:14 +02:00
|
|
|
#include "errno-util.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "fd-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "gpt.h"
|
2018-02-28 02:35:58 +01:00
|
|
|
#include "parse-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2018-08-29 09:12:22 +02:00
|
|
|
#include "strxcpyx.h"
|
|
|
|
#include "udev-builtin.h"
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2018-10-13 17:48:04 +02:00
|
|
|
static void print_property(sd_device *dev, bool test, const char *name, const char *value) {
|
2014-03-07 02:34:18 +01:00
|
|
|
char s[256];
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
s[0] = '\0';
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
if (streq(name, "TYPE")) {
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_TYPE", value);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
} else if (streq(name, "USAGE")) {
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_USAGE", value);
|
2011-12-23 04:06:34 +01:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
} else if (streq(name, "VERSION")) {
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_VERSION", value);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
} else if (streq(name, "UUID")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_safe_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_UUID", s);
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_UUID_ENC", s);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
} else if (streq(name, "UUID_SUB")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_safe_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_UUID_SUB", s);
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_UUID_SUB_ENC", s);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
} else if (streq(name, "LABEL")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_safe_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_LABEL", s);
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_LABEL_ENC", s);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
} else if (streq(name, "PTTYPE")) {
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_PART_TABLE_TYPE", value);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2013-09-19 17:36:40 +02:00
|
|
|
} else if (streq(name, "PTUUID")) {
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_PART_TABLE_UUID", value);
|
2013-09-19 17:36:40 +02:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
} else if (streq(name, "PART_ENTRY_NAME")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_PART_ENTRY_NAME", s);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
} else if (streq(name, "PART_ENTRY_TYPE")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_PART_ENTRY_TYPE", s);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-04-16 20:27:44 +02:00
|
|
|
} else if (startswith(name, "PART_ENTRY_")) {
|
2013-01-09 19:06:46 +01:00
|
|
|
strscpyl(s, sizeof(s), "ID_", name, NULL);
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, s, value);
|
2013-02-17 02:21:27 +01:00
|
|
|
|
|
|
|
} else if (streq(name, "SYSTEM_ID")) {
|
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_SYSTEM_ID", s);
|
2013-02-17 02:21:27 +01:00
|
|
|
|
|
|
|
} else if (streq(name, "PUBLISHER_ID")) {
|
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_PUBLISHER_ID", s);
|
2013-02-17 02:21:27 +01:00
|
|
|
|
|
|
|
} else if (streq(name, "APPLICATION_ID")) {
|
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_APPLICATION_ID", s);
|
2013-02-17 02:21:27 +01:00
|
|
|
|
|
|
|
} else if (streq(name, "BOOT_SYSTEM_ID")) {
|
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_BOOT_SYSTEM_ID", s);
|
2020-12-10 12:27:33 +01:00
|
|
|
|
|
|
|
} else if (streq(name, "VOLUME_ID")) {
|
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_VOLUME_ID", s);
|
|
|
|
|
|
|
|
} else if (streq(name, "LOGICAL_VOLUME_ID")) {
|
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_LOGICAL_VOLUME_ID", s);
|
|
|
|
|
|
|
|
} else if (streq(name, "VOLUME_SET_ID")) {
|
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_VOLUME_SET_ID", s);
|
|
|
|
|
|
|
|
} else if (streq(name, "DATA_PREPARER_ID")) {
|
|
|
|
blkid_encode_string(value, s, sizeof(s));
|
|
|
|
udev_builtin_add_property(dev, test, "ID_FS_DATA_PREPARER_ID", s);
|
2012-01-10 01:34:15 +01:00
|
|
|
}
|
2011-12-21 22:30:48 +01:00
|
|
|
}
|
|
|
|
|
2018-10-13 17:48:04 +02:00
|
|
|
static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) {
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
|
2017-10-03 10:41:51 +02:00
|
|
|
#if defined(GPT_ROOT_NATIVE) && ENABLE_EFI
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
|
|
|
|
_cleanup_free_ char *root_id = NULL;
|
|
|
|
bool found_esp = false;
|
|
|
|
blkid_partlist pl;
|
|
|
|
int i, nvals, r;
|
|
|
|
|
|
|
|
assert(pr);
|
|
|
|
|
|
|
|
/* Iterate through the partitions on this disk, and see if the
|
|
|
|
* EFI ESP we booted from is on it. If so, find the first root
|
|
|
|
* disk, and add a property indicating its partition UUID. */
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
pl = blkid_probe_get_partitions(pr);
|
|
|
|
if (!pl)
|
2019-07-11 15:42:14 +02:00
|
|
|
return errno_or_else(ENOMEM);
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
|
|
|
|
nvals = blkid_partlist_numof_partitions(pl);
|
|
|
|
for (i = 0; i < nvals; i++) {
|
|
|
|
blkid_partition pp;
|
|
|
|
const char *stype, *sid;
|
|
|
|
sd_id128_t type;
|
|
|
|
|
|
|
|
pp = blkid_partlist_get_partition(pl, i);
|
|
|
|
if (!pp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sid = blkid_partition_get_uuid(pp);
|
|
|
|
if (!sid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stype = blkid_partition_get_type_string(pp);
|
|
|
|
if (!stype)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sd_id128_from_string(stype, &type) < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sd_id128_equal(type, GPT_ESP)) {
|
|
|
|
sd_id128_t id, esp;
|
|
|
|
|
|
|
|
/* We found an ESP, let's see if it matches
|
|
|
|
* the ESP we booted from. */
|
|
|
|
|
|
|
|
if (sd_id128_from_string(sid, &id) < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
r = efi_loader_get_device_part_uuid(&esp);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (sd_id128_equal(id, esp))
|
|
|
|
found_esp = true;
|
|
|
|
|
|
|
|
} else if (sd_id128_equal(type, GPT_ROOT_NATIVE)) {
|
2016-06-09 10:51:20 +02:00
|
|
|
unsigned long long flags;
|
|
|
|
|
|
|
|
flags = blkid_partition_get_flags(pp);
|
|
|
|
if (flags & GPT_FLAG_NO_AUTO)
|
|
|
|
continue;
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
|
|
|
|
/* We found a suitable root partition, let's
|
|
|
|
* remember the first one. */
|
|
|
|
|
|
|
|
if (!root_id) {
|
|
|
|
root_id = strdup(sid);
|
|
|
|
if (!root_id)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We found the ESP on this disk, and also found a root
|
2014-03-07 03:30:30 +01:00
|
|
|
* partition, nice! Let's export its UUID */
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
if (found_esp && root_id)
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT_UUID", root_id);
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static int probe_superblocks(blkid_probe pr) {
|
2012-01-10 01:34:15 +01:00
|
|
|
struct stat st;
|
|
|
|
int rc;
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2018-10-23 11:26:06 +02:00
|
|
|
/* TODO: Return negative errno. */
|
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
if (fstat(blkid_probe_get_fd(pr), &st))
|
2017-02-21 22:42:46 +01:00
|
|
|
return -errno;
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_probe_enable_partitions(pr, 1);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2014-03-07 02:34:18 +01:00
|
|
|
if (!S_ISCHR(st.st_mode) &&
|
|
|
|
blkid_probe_get_size(pr) <= 1024 * 1440 &&
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_probe_is_wholedisk(pr)) {
|
|
|
|
/*
|
|
|
|
* check if the small disk is partitioned, if yes then
|
|
|
|
* don't probe for filesystems.
|
|
|
|
*/
|
|
|
|
blkid_probe_enable_superblocks(pr, 0);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
rc = blkid_do_fullprobe(pr);
|
|
|
|
if (rc < 0)
|
2014-03-07 02:34:18 +01:00
|
|
|
return rc; /* -1 = error, 1 = nothing, 0 = success */
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
if (blkid_probe_lookup_value(pr, "PTTYPE", NULL, NULL) == 0)
|
|
|
|
return 0; /* partition table detected */
|
|
|
|
}
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
|
|
|
|
blkid_probe_enable_superblocks(pr, 1);
|
2011-12-21 22:30:48 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
return blkid_do_safeprobe(pr);
|
2011-12-21 22:30:48 +01:00
|
|
|
}
|
|
|
|
|
2018-10-13 18:22:14 +02:00
|
|
|
static int builtin_blkid(sd_device *dev, int argc, char *argv[], bool test) {
|
2018-10-13 17:48:04 +02:00
|
|
|
const char *devnode, *root_partition = NULL, *data, *name;
|
tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.
In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.
Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.
Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.
Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
|
|
|
_cleanup_(blkid_free_probep) blkid_probe pr = NULL;
|
2018-10-13 17:48:04 +02:00
|
|
|
bool noraid = false, is_gpt = false;
|
|
|
|
_cleanup_close_ int fd = -1;
|
|
|
|
int64_t offset = 0;
|
|
|
|
int nvals, i, r;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
|
|
|
static const struct option options[] = {
|
2018-02-28 02:35:58 +01:00
|
|
|
{ "offset", required_argument, NULL, 'o' },
|
2012-01-10 01:34:15 +01:00
|
|
|
{ "noraid", no_argument, NULL, 'R' },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int option;
|
|
|
|
|
2018-02-28 02:35:58 +01:00
|
|
|
option = getopt_long(argc, argv, "o:R", options, NULL);
|
2012-01-10 01:34:15 +01:00
|
|
|
if (option == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case 'o':
|
2018-10-13 17:48:04 +02:00
|
|
|
r = safe_atoi64(optarg, &offset);
|
|
|
|
if (r < 0)
|
2018-10-23 20:01:19 +02:00
|
|
|
return log_device_error_errno(dev, r, "Failed to parse '%s' as an integer: %m", optarg);
|
2018-10-23 11:26:06 +02:00
|
|
|
if (offset < 0)
|
2019-01-13 09:50:47 +01:00
|
|
|
return log_device_error_errno(dev, SYNTHETIC_ERRNO(ERANGE), "Invalid offset %"PRIi64": %m", offset);
|
2012-01-10 01:34:15 +01:00
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
noraid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 11:26:06 +02:00
|
|
|
errno = 0;
|
2012-01-10 01:34:15 +01:00
|
|
|
pr = blkid_new_probe();
|
2012-04-13 15:08:55 +02:00
|
|
|
if (!pr)
|
2018-10-23 20:01:19 +02:00
|
|
|
return log_device_debug_errno(dev, errno > 0 ? errno : ENOMEM, "Failed to create blkid prober: %m");
|
2012-01-10 01:34:15 +01:00
|
|
|
|
|
|
|
blkid_probe_set_superblocks_flags(pr,
|
|
|
|
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
|
|
|
|
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
|
2017-06-28 19:27:40 +02:00
|
|
|
BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION);
|
2012-01-10 01:34:15 +01:00
|
|
|
|
|
|
|
if (noraid)
|
|
|
|
blkid_probe_filter_superblocks_usage(pr, BLKID_FLTR_NOTIN, BLKID_USAGE_RAID);
|
|
|
|
|
2018-10-13 17:48:04 +02:00
|
|
|
r = sd_device_get_devname(dev, &devnode);
|
|
|
|
if (r < 0)
|
2018-10-23 20:01:19 +02:00
|
|
|
return log_device_debug_errno(dev, r, "Failed to get device name: %m");
|
2018-10-13 17:48:04 +02:00
|
|
|
|
2019-11-04 21:23:15 +01:00
|
|
|
fd = open(devnode, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
|
2018-10-23 11:26:06 +02:00
|
|
|
if (fd < 0)
|
2018-10-23 20:01:19 +02:00
|
|
|
return log_device_debug_errno(dev, errno, "Failed to open block device %s: %m", devnode);
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2018-10-23 11:26:06 +02:00
|
|
|
errno = 0;
|
2018-10-13 17:48:04 +02:00
|
|
|
r = blkid_probe_set_device(pr, fd, offset, 0);
|
|
|
|
if (r < 0)
|
2018-10-23 20:01:19 +02:00
|
|
|
return log_device_debug_errno(dev, errno > 0 ? errno : ENOMEM, "Failed to set device to blkid prober: %m");
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2018-10-23 20:01:19 +02:00
|
|
|
log_device_debug(dev, "Probe %s with %sraid and offset=%"PRIi64, devnode, noraid ? "no" : "", offset);
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2018-10-13 17:48:04 +02:00
|
|
|
r = probe_superblocks(pr);
|
|
|
|
if (r < 0)
|
2018-10-23 20:01:19 +02:00
|
|
|
return log_device_debug_errno(dev, r, "Failed to probe superblocks: %m");
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2018-10-23 20:01:19 +02:00
|
|
|
/* If the device is a partition then its parent passed the root partition UUID to the device */
|
2018-10-13 17:48:04 +02:00
|
|
|
(void) sd_device_get_property_value(dev, "ID_PART_GPT_AUTO_ROOT_UUID", &root_partition);
|
2014-03-07 03:30:30 +01:00
|
|
|
|
2018-10-23 20:01:19 +02:00
|
|
|
errno = 0;
|
2012-01-10 01:34:15 +01:00
|
|
|
nvals = blkid_probe_numof_values(pr);
|
2018-10-23 20:01:19 +02:00
|
|
|
if (nvals < 0)
|
|
|
|
return log_device_debug_errno(dev, errno > 0 ? errno : ENOMEM, "Failed to get number of probed values: %m");
|
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
for (i = 0; i < nvals; i++) {
|
2018-10-23 20:01:19 +02:00
|
|
|
if (blkid_probe_get_value(pr, i, &name, &data, NULL) < 0)
|
2012-01-10 01:34:15 +01:00
|
|
|
continue;
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
|
2014-03-07 14:37:01 +01:00
|
|
|
print_property(dev, test, name, data);
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
|
2014-03-07 03:30:30 +01:00
|
|
|
/* Is this a disk with GPT partition table? */
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
if (streq(name, "PTTYPE") && streq(data, "gpt"))
|
|
|
|
is_gpt = true;
|
2014-03-07 03:30:30 +01:00
|
|
|
|
|
|
|
/* Is this a partition that matches the root partition
|
2018-10-23 20:01:19 +02:00
|
|
|
* property inherited from the parent? */
|
2014-03-07 03:30:30 +01:00
|
|
|
if (root_partition && streq(name, "PART_ENTRY_UUID") && streq(data, root_partition))
|
2018-10-13 17:48:04 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT", "1");
|
2012-01-10 01:34:15 +01:00
|
|
|
}
|
|
|
|
|
udev-builtin-blkid: when we find a GPT partition marked as root disk on the same disk as the ESP, expose a property on the udev device
This is preparation for a logic to automatically discover the root
partition to boot from if no partition has been configured explicitly.
This makes use of our newly defined GPT type GUIDs for our root disks:
#define GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
#define GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
We define differen GUIDs for different architectures to allow images
which finde the right root partition for the appropriate arch.
2014-03-07 02:35:19 +01:00
|
|
|
if (is_gpt)
|
|
|
|
find_gpt_root(dev, pr, test);
|
|
|
|
|
2018-10-23 11:26:06 +02:00
|
|
|
return 0;
|
2011-12-21 22:30:48 +01:00
|
|
|
}
|
|
|
|
|
2019-04-25 01:21:11 +02:00
|
|
|
const UdevBuiltin udev_builtin_blkid = {
|
2012-01-10 01:34:15 +01:00
|
|
|
.name = "blkid",
|
|
|
|
.cmd = builtin_blkid,
|
2015-01-05 13:19:55 +01:00
|
|
|
.help = "Filesystem and partition probing",
|
2012-01-10 01:34:15 +01:00
|
|
|
.run_once = true,
|
2011-12-21 22:30:48 +01:00
|
|
|
};
|