mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 06:25:37 +03:00
Merge pull request #25593 from poettering/blkid-safeprobe-enum
define symbolic enum for blkid_do_safeprobe() return values
This commit is contained in:
commit
4f0fafb6f0
@ -141,17 +141,19 @@ static int probe_file_system_by_fd(
|
||||
errno = 0;
|
||||
r = blkid_probe_set_device(b, fd, 0, 0);
|
||||
if (r != 0)
|
||||
return errno > 0 ? -errno : -ENOMEM;
|
||||
return errno_or_else(ENOMEM);
|
||||
|
||||
(void) blkid_probe_enable_superblocks(b, 1);
|
||||
(void) blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE|BLKID_SUBLKS_UUID);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
if (IN_SET(r, -2, 1)) /* nothing found or ambiguous result */
|
||||
if (r == _BLKID_SAFEPROBE_ERROR)
|
||||
return errno_or_else(EIO);
|
||||
if (IN_SET(r, _BLKID_SAFEPROBE_AMBIGUOUS, _BLKID_SAFEPROBE_NOT_FOUND))
|
||||
return -ENOPKG;
|
||||
if (r != 0)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
|
||||
if (!fstype)
|
||||
@ -656,7 +658,7 @@ static int luks_validate(
|
||||
errno = 0;
|
||||
r = blkid_probe_set_device(b, fd, 0, 0);
|
||||
if (r != 0)
|
||||
return errno > 0 ? -errno : -ENOMEM;
|
||||
return errno_or_else(ENOMEM);
|
||||
|
||||
(void) blkid_probe_enable_superblocks(b, 1);
|
||||
(void) blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
|
||||
@ -665,10 +667,12 @@ static int luks_validate(
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
if (IN_SET(r, -2, 1)) /* nothing found or ambiguous result */
|
||||
if (r == _BLKID_SAFEPROBE_ERROR)
|
||||
return errno_or_else(EIO);
|
||||
if (IN_SET(r, _BLKID_SAFEPROBE_AMBIGUOUS, _BLKID_SAFEPROBE_NOT_FOUND))
|
||||
return -ENOPKG;
|
||||
if (r != 0)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
|
||||
if (streq_ptr(fstype, "crypto_LUKS")) {
|
||||
@ -687,12 +691,12 @@ static int luks_validate(
|
||||
errno = 0;
|
||||
pl = blkid_probe_get_partitions(b);
|
||||
if (!pl)
|
||||
return errno > 0 ? -errno : -ENOMEM;
|
||||
return errno_or_else(ENOMEM);
|
||||
|
||||
errno = 0;
|
||||
n = blkid_partlist_numof_partitions(pl);
|
||||
if (n < 0)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
sd_id128_t id = SD_ID128_NULL;
|
||||
@ -701,7 +705,7 @@ static int luks_validate(
|
||||
errno = 0;
|
||||
pp = blkid_partlist_get_partition(pl, i);
|
||||
if (!pp)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
return errno_or_else(EIO);
|
||||
|
||||
if (sd_id128_string_equal(blkid_partition_get_type_string(pp), SD_GPT_USER_HOME) <= 0)
|
||||
continue;
|
||||
|
@ -4840,12 +4840,14 @@ static int resolve_copy_blocks_auto_candidate(
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
if (IN_SET(r, -2, 1)) { /* nothing found or ambiguous result */
|
||||
if (r == _BLKID_SAFEPROBE_ERROR)
|
||||
return log_error_errno(errno_or_else(EIO), "Unable to probe for partition table of '%s': %m", p);
|
||||
if (IN_SET(r, _BLKID_SAFEPROBE_AMBIGUOUS, _BLKID_SAFEPROBE_NOT_FOUND)) {
|
||||
log_debug("Didn't find partition table on block device '%s'.", p);
|
||||
return false;
|
||||
}
|
||||
if (r != 0)
|
||||
return log_error_errno(errno_or_else(EIO), "Unable to probe for partition table of '%s': %m", p);
|
||||
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "PTTYPE", &pttype, NULL);
|
||||
if (!streq_ptr(pttype, "gpt")) {
|
||||
@ -4857,7 +4859,6 @@ static int resolve_copy_blocks_auto_candidate(
|
||||
pl = blkid_probe_get_partitions(b);
|
||||
if (!pl)
|
||||
return log_error_errno(errno_or_else(EIO), "Unable read partition table of '%s': %m", p);
|
||||
errno = 0;
|
||||
|
||||
pp = blkid_partlist_devno_to_partition(pl, partition_devno);
|
||||
if (!pp) {
|
||||
|
@ -34,4 +34,14 @@ static inline int blkid_partition_get_type_id128(blkid_partition p, sd_id128_t *
|
||||
|
||||
return sd_id128_from_string(s, ret);
|
||||
}
|
||||
|
||||
/* Define symbolic names for blkid_do_safeprobe() return values, since blkid only uses literal numbers. We
|
||||
* prefix these symbolic definitions with underscores, to not invade libblkid's namespace needlessly. */
|
||||
enum {
|
||||
_BLKID_SAFEPROBE_FOUND = 0,
|
||||
_BLKID_SAFEPROBE_NOT_FOUND = 1,
|
||||
_BLKID_SAFEPROBE_AMBIGUOUS = -2,
|
||||
_BLKID_SAFEPROBE_ERROR = -1,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -119,14 +119,16 @@ int probe_filesystem_full(int fd, const char *path, char **ret_fstype) {
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
if (r == 1)
|
||||
if (r == _BLKID_SAFEPROBE_NOT_FOUND)
|
||||
goto not_found;
|
||||
if (r == -2)
|
||||
if (r == _BLKID_SAFEPROBE_AMBIGUOUS)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EUCLEAN),
|
||||
"Results ambiguous for partition %s", path);
|
||||
if (r != 0)
|
||||
if (r == _BLKID_SAFEPROBE_ERROR)
|
||||
return log_debug_errno(errno_or_else(EIO), "Failed to probe partition %s: %m", path);
|
||||
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
|
||||
|
||||
if (fstype) {
|
||||
@ -439,10 +441,12 @@ static int dissect_image(
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
if (IN_SET(r, -2, 1))
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ENOPKG), "Failed to identify any partition table.");
|
||||
if (r != 0)
|
||||
if (r == _BLKID_SAFEPROBE_ERROR)
|
||||
return errno_or_else(EIO);
|
||||
if (IN_SET(r, _BLKID_SAFEPROBE_AMBIGUOUS, _BLKID_SAFEPROBE_NOT_FOUND))
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ENOPKG), "Failed to identify any partition table.");
|
||||
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
if ((!(flags & DISSECT_IMAGE_GPT_ONLY) &&
|
||||
(flags & DISSECT_IMAGE_GENERIC_ROOT)) ||
|
||||
|
@ -564,19 +564,21 @@ static int verify_xbootldr_blkid(
|
||||
errno = 0;
|
||||
b = blkid_new_probe_from_filename(node);
|
||||
if (!b)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(ENOMEM), "%s: Failed to create blkid probe: %m", node);
|
||||
return log_error_errno(errno_or_else(ENOMEM), "%s: Failed to create blkid probe: %m", node);
|
||||
|
||||
blkid_probe_enable_partitions(b, 1);
|
||||
blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
if (r == -2)
|
||||
if (r == _BLKID_SAFEPROBE_AMBIGUOUS)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENODEV), "%s: File system is ambiguous.", node);
|
||||
else if (r == 1)
|
||||
if (r == _BLKID_SAFEPROBE_NOT_FOUND)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENODEV), "%s: File system does not contain a label.", node);
|
||||
else if (r != 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "%s: Failed to probe file system: %m", node);
|
||||
if (r == _BLKID_SAFEPROBE_ERROR)
|
||||
return log_error_errno(errno_or_else(EIO), "%s: Failed to probe file system: %m", node);
|
||||
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &type, NULL);
|
||||
if (r != 0)
|
||||
@ -588,7 +590,7 @@ static int verify_xbootldr_blkid(
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "%s: Failed to probe PART_ENTRY_TYPE: %m", node);
|
||||
return log_error_errno(errno_or_else(EIO), "%s: Failed to probe PART_ENTRY_TYPE: %m", node);
|
||||
if (sd_id128_string_equal(v, SD_GPT_XBOOTLDR) <= 0)
|
||||
return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
|
||||
searching ? SYNTHETIC_ERRNO(EADDRNOTAVAIL) : SYNTHETIC_ERRNO(ENODEV),
|
||||
@ -597,7 +599,7 @@ static int verify_xbootldr_blkid(
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_UUID", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "%s: Failed to probe PART_ENTRY_UUID: %m", node);
|
||||
return log_error_errno(errno_or_else(EIO), "%s: Failed to probe PART_ENTRY_UUID: %m", node);
|
||||
r = sd_id128_from_string(v, &uuid);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "%s: Partition has invalid UUID PART_ENTRY_TYPE=%s: %m", node, v);
|
||||
@ -607,7 +609,7 @@ static int verify_xbootldr_blkid(
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "%s: Failed to probe PART_ENTRY_TYPE: %m", node);
|
||||
return log_error_errno(errno_or_else(EIO), "%s: Failed to probe PART_ENTRY_TYPE: %m", node);
|
||||
if (!streq(v, "0xea"))
|
||||
return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
|
||||
searching ? SYNTHETIC_ERRNO(EADDRNOTAVAIL) : SYNTHETIC_ERRNO(ENODEV),
|
||||
|
Loading…
Reference in New Issue
Block a user