Create hash image if doesn't exist in veritysetup format.

This commit is contained in:
Milan Broz
2012-08-12 22:49:42 +02:00
parent 65f975655c
commit 49b018c765
4 changed files with 22 additions and 13 deletions

View File

@@ -26,7 +26,9 @@
#include <inttypes.h>
#include <popt.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "cryptsetup.h"
@@ -140,8 +142,20 @@ static int action_format(int arg)
struct crypt_device *cd = NULL;
struct crypt_params_verity params = {};
uint32_t flags = CRYPT_VERITY_CREATE_HASH;
struct stat st;
int r;
/* Try to create hash image if doesn't exist */
if (stat(action_argv[1], &st) < 0) {
log_dbg("Creating hash image %s.", action_argv[1]);
r = open(action_argv[1], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
if (r < 0) {
log_err(_("Cannot create hash image %s for writing.\n"), action_argv[1]);
return -EINVAL;
}
close(r);
}
if ((r = crypt_init(&cd, action_argv[1])))
goto out;