/* Get kernel driver protocol version and comapre it with library version. */ static int _check_version(char *version, size_t size) { struct dm_task *task; int r; if (!(task = dm_task_create(DM_DEVICE_VERSION))) { log_error("Failed to get device-mapper version"); version[0] = '\0'; return 0; } r = dm_task_run(task); dm_task_get_driver_version(task, version, size); dm_task_destroy(task); return r; }
/* Retrieve device-mapper driver version. */ int dm_version(struct lib_context *lc, char *version, size_t size) { int ret; struct dm_task *dmt; /* Be prepared for device-mapper not in kernel. */ strncpy(version, "unknown", size); _init_dm(); ret = (dmt = dm_task_create(DM_DEVICE_VERSION)) && dm_task_run(dmt) && dm_task_get_driver_version(dmt, version, size); _exit_dm(dmt); return ret; }
void dm_check_version(void) { char *saveptr, *version; struct dm_task *task = dm_task_create(DM_DEVICE_VERSION); if(!task) { die("dm_task_create"); } dm_task_run(task); version = steg_malloc(1024); dm_task_get_driver_version(task, version, 1024); version[1023] = 0; strtok_r(version, ".", &saveptr); if(strncmp(version, MESG_STR("4"))) { die("unknown device mapper version"); } steg_free(version); dm_task_destroy(task); }