blkid-util: define enum for blkid_do_safeprobe() return values
libblkid really should define an enum for this on its own, but it currently doesn't and returns literal numeric values. Lets make this more readable by adding our own symbolic names via an enum.
This commit is contained in:
@@ -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)) ||
|
||||
|
||||
@@ -571,12 +571,14 @@ static int verify_xbootldr_blkid(
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user