mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 11:50:10 +01:00
Set UUID in device-mapper for LUKS devices.
Device mapper device should use UUID string if possible. UDEV can then easily distinguish the device type etc. cryptsetup now uses CRYPT prefix for uuid. git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@55 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
@@ -37,7 +37,7 @@ struct setup_backend {
|
|||||||
int (*init)(void);
|
int (*init)(void);
|
||||||
void (*exit)(void);
|
void (*exit)(void);
|
||||||
int (*create)(int reload, struct crypt_options *options,
|
int (*create)(int reload, struct crypt_options *options,
|
||||||
const char *key);
|
const char *key, const char *uuid);
|
||||||
int (*status)(int details, struct crypt_options *options,
|
int (*status)(int details, struct crypt_options *options,
|
||||||
char **key);
|
char **key);
|
||||||
int (*remove)(int force, struct crypt_options *options);
|
int (*remove)(int force, struct crypt_options *options);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
#define DEVICE_DIR "/dev"
|
#define DEVICE_DIR "/dev"
|
||||||
|
#define UUID_PREFIX "CRYPT-"
|
||||||
#define CRYPT_TARGET "crypt"
|
#define CRYPT_TARGET "crypt"
|
||||||
#define RETRY_COUNT 5
|
#define RETRY_COUNT 5
|
||||||
|
|
||||||
@@ -247,19 +247,26 @@ static int _dm_remove(struct crypt_options *options, int force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int dm_create_device(int reload, struct crypt_options *options,
|
static int dm_create_device(int reload, struct crypt_options *options,
|
||||||
const char *key)
|
const char *key, const char *uuid)
|
||||||
{
|
{
|
||||||
struct dm_task *dmt = NULL;
|
struct dm_task *dmt = NULL;
|
||||||
struct dm_task *dmt_query = NULL;
|
struct dm_task *dmt_query = NULL;
|
||||||
struct dm_info dmi;
|
struct dm_info dmi;
|
||||||
char *params = NULL;
|
char *params = NULL;
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
|
char dev_uuid[64];
|
||||||
int r = -EINVAL;
|
int r = -EINVAL;
|
||||||
uint32_t read_ahead = 0;
|
uint32_t read_ahead = 0;
|
||||||
|
|
||||||
params = get_params(options, key);
|
params = get_params(options, key);
|
||||||
if (!params)
|
if (!params)
|
||||||
goto out_no_removal;
|
goto out_no_removal;
|
||||||
|
|
||||||
|
if (uuid) {
|
||||||
|
strcpy(dev_uuid, UUID_PREFIX);
|
||||||
|
strcat(dev_uuid, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(dmt = dm_task_create(reload ? DM_DEVICE_RELOAD
|
if (!(dmt = dm_task_create(reload ? DM_DEVICE_RELOAD
|
||||||
: DM_DEVICE_CREATE)))
|
: DM_DEVICE_CREATE)))
|
||||||
goto out;
|
goto out;
|
||||||
@@ -275,6 +282,10 @@ static int dm_create_device(int reload, struct crypt_options *options,
|
|||||||
!dm_task_set_read_ahead(dmt, read_ahead, DM_READ_AHEAD_MINIMUM_FLAG))
|
!dm_task_set_read_ahead(dmt, read_ahead, DM_READ_AHEAD_MINIMUM_FLAG))
|
||||||
goto out;
|
goto out;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (uuid && !dm_task_set_uuid(dmt, dev_uuid))
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (!dm_task_run(dmt))
|
if (!dm_task_run(dmt))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
@@ -284,6 +295,8 @@ static int dm_create_device(int reload, struct crypt_options *options,
|
|||||||
goto out;
|
goto out;
|
||||||
if (!dm_task_set_name(dmt, options->name))
|
if (!dm_task_set_name(dmt, options->name))
|
||||||
goto out;
|
goto out;
|
||||||
|
if (uuid && !dm_task_set_uuid(dmt, dev_uuid))
|
||||||
|
goto out;
|
||||||
if (!dm_task_run(dmt))
|
if (!dm_task_run(dmt))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ static int __crypt_create_device(int reload, struct setup_backend *backend,
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = backend->create(reload, options, processed_key);
|
r = backend->create(reload, options, processed_key, NULL);
|
||||||
|
|
||||||
safe_free(processed_key);
|
safe_free(processed_key);
|
||||||
|
|
||||||
@@ -404,7 +404,7 @@ static int __crypt_resize_device(int details, struct setup_backend *backend,
|
|||||||
if (infos.readonly)
|
if (infos.readonly)
|
||||||
options->flags |= CRYPT_FLAG_READONLY;
|
options->flags |= CRYPT_FLAG_READONLY;
|
||||||
|
|
||||||
r = backend->create(1, &tmp, key);
|
r = backend->create(1, &tmp, key, NULL);
|
||||||
|
|
||||||
safe_free(key);
|
safe_free(key);
|
||||||
|
|
||||||
@@ -579,7 +579,9 @@ start:
|
|||||||
r = -EINVAL; goto out2;
|
r = -EINVAL; goto out2;
|
||||||
}
|
}
|
||||||
options->size -= options->offset;
|
options->size -= options->offset;
|
||||||
r = backend->create(0, options, mk->key);
|
/* FIXME: code allows multiple crypt mapping, cannot use uuid then.
|
||||||
|
* anyway, it is dangerous and can corrupt data. Remove it in next version! */
|
||||||
|
r = backend->create(0, options, mk->key, excl ? hdr.uuid : NULL);
|
||||||
|
|
||||||
out2:
|
out2:
|
||||||
free(dmCipherSpec);
|
free(dmCipherSpec);
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ static int setup_mapping(const char *cipher, const char *name,
|
|||||||
|
|
||||||
set_error(NULL);
|
set_error(NULL);
|
||||||
|
|
||||||
r = backend->create(0, options, key);
|
r = backend->create(0, options, key, NULL);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user