mirror of
https://github.com/systemd/systemd.git
synced 2025-03-28 02:50:16 +03:00
dissect-image: return error if results are ambiguous
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.
This commit is contained in:
parent
7f2806d509
commit
7cc84b2cd3
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,10 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user