diff --git a/internal/exec/util/blkid.c b/internal/exec/util/blkid.c index 3335cbac1..ff1ef8664 100644 --- a/internal/exec/util/blkid.c +++ b/internal/exec/util/blkid.c @@ -14,6 +14,7 @@ #include #include "blkid.h" +#include // blkid_free_probe is safe to call with NULL pointers static inline void _free_probe(blkid_probe *pr) { if (pr) blkid_free_probe(*pr); } @@ -248,3 +249,40 @@ static result_t extract_part_info(blkid_partition part, struct partition_info *i return RESULT_OK; } + +// blkid_get_block_devices_with_udf fetches the block devices with FSTYPE set to udf. +result_t blkid_get_block_devices_with_udf(struct block_device_list *device){ + blkid_dev_iterate iter; + blkid_dev dev; + blkid_cache cache = NULL; + int err, count = 0; + const char *ctmp = NULL; + + if ((err = blkid_get_cache(&cache,"/dev/null") != 0)) + return RESULT_FAIL_TO_RETRIEVE; + + if ((err = blkid_probe_all(cache) != 0)) + return RESULT_FAIL_TO_RETRIEVE; + + iter = blkid_dev_iterate_begin(cache); + + blkid_dev_set_search(iter, "TYPE", "udf"); + + while (blkid_dev_next(iter, &dev) == 0) { + dev = blkid_verify(cache, dev); + if (!dev) + continue; + ctmp = blkid_dev_devname(dev); + err = checked_copy(device->path[count], ctmp, MAX_BLOCK_DEVICE_PATH_LEN); + if (err) + return err; + count++; + if (count > MAX_BLOCK_DEVICES) + return RESULT_MAX_BLOCK_DEVICES; + } + blkid_dev_iterate_end(iter); + if (count == 0) + return RESULT_NO_BLOCK_DEVICE_FOUND; + device->length = count; + return RESULT_OK; +} diff --git a/internal/exec/util/blkid.go b/internal/exec/util/blkid.go index 1d44709e2..bd084172f 100644 --- a/internal/exec/util/blkid.go +++ b/internal/exec/util/blkid.go @@ -189,3 +189,20 @@ func filesystemLookup(device string, allowAmbivalent bool, fieldName string) (st } return string(buf[:bytes.IndexByte(buf[:], 0)]), nil } + +// GetUdfBlockDevices returns a slice of the block devices with filesystem set to udf +func GetUdfBlockDevices() ([]string, error) { + var dev C.struct_block_device_list + res := C.blkid_get_block_devices_with_udf(&dev) + + if res == C.RESULT_LOOKUP_FAILED || res == C.RESULT_OVERFLOW || res == C.RESULT_FAIL_TO_RETRIEVE || res == C.RESULT_MAX_BLOCK_DEVICES || res == C.RESULT_NO_BLOCK_DEVICE_FOUND { + return nil, fmt.Errorf("failed to retrieve block devices with filesystem set to udf") + } + + length := int(dev.length) + blkDeviceList := make([]string, length) + for i := 0; i < length; i++ { + blkDeviceList[i] = C.GoString(&dev.path[i][0]) + } + return blkDeviceList, nil +} diff --git a/internal/exec/util/blkid.h b/internal/exec/util/blkid.h index 276116437..8ad13257b 100644 --- a/internal/exec/util/blkid.h +++ b/internal/exec/util/blkid.h @@ -27,10 +27,13 @@ typedef enum { RESULT_NO_PARTITION_TABLE, RESULT_BAD_INDEX, RESULT_GET_PARTLIST_FAILED, + RESULT_FAIL_TO_RETRIEVE, RESULT_DISK_HAS_NO_TYPE, RESULT_DISK_NOT_GPT, RESULT_BAD_PARAMS, + RESULT_NO_BLOCK_DEVICE_FOUND, RESULT_OVERFLOW, + RESULT_MAX_BLOCK_DEVICES, RESULT_NO_TOPO, RESULT_NO_SECTOR_SIZE, RESULT_BAD_SECTOR_SIZE, @@ -48,6 +51,14 @@ struct partition_info { int number; }; +#define MAX_BLOCK_DEVICES 10 +#define MAX_BLOCK_DEVICE_PATH_LEN 50 + +struct block_device_list { + char path[MAX_BLOCK_DEVICES][MAX_BLOCK_DEVICE_PATH_LEN]; + int length; +}; + result_t blkid_lookup(const char *device, bool allow_ambivalent, const char *field_name, char buf[], size_t buf_len); result_t blkid_get_num_partitions(const char *device, int *ret); @@ -57,5 +68,6 @@ result_t blkid_get_logical_sector_size(const char *device, int *ret_sector_size) // WARNING part_num may not be what you expect. see the .c file's comment for why result_t blkid_get_partition(const char *device, int part_num, struct partition_info *info); -#endif // _BLKID_H_ +result_t blkid_get_block_devices_with_udf(struct block_device_list *device); +#endif // _BLKID_H_ diff --git a/internal/providers/azure/azure.go b/internal/providers/azure/azure.go index b77a0578a..033841c3e 100644 --- a/internal/providers/azure/azure.go +++ b/internal/providers/azure/azure.go @@ -70,6 +70,7 @@ func FetchFromOvfDevice(f *resource.Fetcher, ovfFsTypes []string) (types.Config, logger := f.Logger logger.Debug("waiting for config DVD...") + waitForCdrom(logger, devicePath) fsType, err := checkOvfFsType(logger, devicePath, ovfFsTypes)