mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
fixes/improvements
This commit is contained in:
parent
3d962ed68f
commit
836bafac6e
@ -78,11 +78,11 @@ static const char *root_hash;
|
|||||||
static int version = -1;
|
static int version = -1;
|
||||||
static int data_block_size = 0;
|
static int data_block_size = 0;
|
||||||
static int hash_block_size = 0;
|
static int hash_block_size = 0;
|
||||||
static long long hash_start = 0;
|
static char *data_blocks_string = NULL;
|
||||||
static long long data_blocks = 0;
|
static long long data_blocks = 0;
|
||||||
|
static char *hash_start_string = NULL;
|
||||||
|
static long long hash_start = 0;
|
||||||
static const char *salt_string = NULL;
|
static const char *salt_string = NULL;
|
||||||
static const char *hash_start_string = NULL;
|
|
||||||
static const char *data_blocks_string = NULL;
|
|
||||||
|
|
||||||
static FILE *data_file;
|
static FILE *data_file;
|
||||||
static FILE *hash_file;
|
static FILE *hash_file;
|
||||||
@ -127,7 +127,9 @@ struct superblock {
|
|||||||
#define DM_VERITY_SIGNATURE "verity\0\0"
|
#define DM_VERITY_SIGNATURE "verity\0\0"
|
||||||
#define DM_VERITY_VERSION 0
|
#define DM_VERITY_VERSION 0
|
||||||
|
|
||||||
__attribute__ ((noreturn))
|
#if defined(__GNUC__) && __GNUC__ >= 2
|
||||||
|
__attribute__((__noreturn__))
|
||||||
|
#endif
|
||||||
static void help(poptContext popt_context,
|
static void help(poptContext popt_context,
|
||||||
enum poptCallbackReason reason,
|
enum poptCallbackReason reason,
|
||||||
struct poptOption *key,
|
struct poptOption *key,
|
||||||
@ -170,9 +172,8 @@ static struct poptOption popt_options[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__GNUC__) && __GNUC__ >= 2
|
#if defined(__GNUC__) && __GNUC__ >= 2
|
||||||
__attribute__((__format__(__printf__, 1, 2)))
|
__attribute__((__format__(__printf__, 1, 2), __noreturn__))
|
||||||
#endif
|
#endif
|
||||||
__attribute__((noreturn))
|
|
||||||
static void exit_err(const char *msg, ...)
|
static void exit_err(const char *msg, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -183,7 +184,9 @@ static void exit_err(const char *msg, ...)
|
|||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((noreturn))
|
#if defined(__GNUC__) && __GNUC__ >= 2
|
||||||
|
__attribute__((__noreturn__))
|
||||||
|
#endif
|
||||||
static void stream_err(FILE *f, const char *msg)
|
static void stream_err(FILE *f, const char *msg)
|
||||||
{
|
{
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
@ -622,6 +625,8 @@ static void free_target_line(char **line)
|
|||||||
static void create_or_verify(void)
|
static void create_or_verify(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
memset(calculated_digest, 0, digest_size);
|
||||||
if (mode != MODE_ACTIVATE)
|
if (mode != MODE_ACTIVATE)
|
||||||
for (i = 0; i < levels; i++) {
|
for (i = 0; i < levels; i++) {
|
||||||
block_fseek(hash_file, hash_level_block[i], hash_block_size);
|
block_fseek(hash_file, hash_level_block[i], hash_block_size);
|
||||||
@ -682,7 +687,9 @@ static void create_or_verify(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((noreturn))
|
#if defined(__GNUC__) && __GNUC__ >= 2
|
||||||
|
__attribute__((__noreturn__))
|
||||||
|
#endif
|
||||||
static void activate(void)
|
static void activate(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -769,8 +776,9 @@ static void load_superblock(void)
|
|||||||
exit_err("hash block size (%d) does not match superblock value (%d)", hash_block_size, 1 << superblock.hash_block_bits);
|
exit_err("hash block size (%d) does not match superblock value (%d)", hash_block_size, 1 << superblock.hash_block_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data_blocks) {
|
if (!data_blocks_string) {
|
||||||
data_blocks = sb_data_blocks;
|
data_blocks = sb_data_blocks;
|
||||||
|
data_blocks_string = (char *)"";
|
||||||
} else {
|
} else {
|
||||||
if (data_blocks != sb_data_blocks)
|
if (data_blocks != sb_data_blocks)
|
||||||
exit_err("data blocks (%lld) does not match superblock value (%lld)", data_blocks, sb_data_blocks);
|
exit_err("data blocks (%lld) does not match superblock value (%lld)", data_blocks, sb_data_blocks);
|
||||||
@ -803,8 +811,8 @@ static void save_superblock(void)
|
|||||||
superblock.data_block_bits = ffs(data_block_size) - 1;
|
superblock.data_block_bits = ffs(data_block_size) - 1;
|
||||||
superblock.hash_block_bits = ffs(hash_block_size) - 1;
|
superblock.hash_block_bits = ffs(hash_block_size) - 1;
|
||||||
superblock.salt_size = htons(salt_size);
|
superblock.salt_size = htons(salt_size);
|
||||||
superblock.data_blocks_hi = htonl(data_blocks >> 31 >> 1);
|
superblock.data_blocks_hi = htonl(data_file_blocks >> 31 >> 1);
|
||||||
superblock.data_blocks_lo = htonl(data_blocks & 0xFFFFFFFF);
|
superblock.data_blocks_lo = htonl(data_file_blocks & 0xFFFFFFFF);
|
||||||
strncpy((char *)superblock.algorithm, hash_algorithm, sizeof superblock.algorithm);
|
strncpy((char *)superblock.algorithm, hash_algorithm, sizeof superblock.algorithm);
|
||||||
memcpy(superblock.salt, salt_bytes, salt_size);
|
memcpy(superblock.salt, salt_bytes, salt_size);
|
||||||
|
|
||||||
@ -818,7 +826,7 @@ int main(int argc, const char **argv)
|
|||||||
poptContext popt_context;
|
poptContext popt_context;
|
||||||
int r;
|
int r;
|
||||||
const char *s;
|
const char *s;
|
||||||
char c;
|
char *end;
|
||||||
|
|
||||||
if (sizeof(struct superblock) != 512)
|
if (sizeof(struct superblock) != 512)
|
||||||
exit_err("INTERNAL ERROR: bad superblock size %ld", (long)sizeof(struct superblock));
|
exit_err("INTERNAL ERROR: bad superblock size %ld", (long)sizeof(struct superblock));
|
||||||
@ -879,9 +887,17 @@ int main(int argc, const char **argv)
|
|||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hash_start_string)
|
if (data_blocks_string) {
|
||||||
if (sscanf(hash_start_string, "%lld%c", &hash_start, &c) != 1)
|
data_blocks = strtoll(data_blocks_string, &end, 10);
|
||||||
|
if (!*data_blocks_string || *end)
|
||||||
|
exit_err("invalid number of data blocks");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hash_start_string) {
|
||||||
|
hash_start = strtoll(hash_start_string, &end, 10);
|
||||||
|
if (!*hash_start_string || *end)
|
||||||
exit_err("invalid hash start");
|
exit_err("invalid hash start");
|
||||||
|
}
|
||||||
|
|
||||||
if (hash_start < 0 ||
|
if (hash_start < 0 ||
|
||||||
(unsigned long long)hash_start * 512 / 512 != hash_start ||
|
(unsigned long long)hash_start * 512 / 512 != hash_start ||
|
||||||
@ -919,10 +935,6 @@ int main(int argc, const char **argv)
|
|||||||
if (hash_block_size < 512 || (hash_block_size & (hash_block_size - 1)) || hash_block_size >= 1U << 31)
|
if (hash_block_size < 512 || (hash_block_size & (hash_block_size - 1)) || hash_block_size >= 1U << 31)
|
||||||
exit_err("invalid hash block size");
|
exit_err("invalid hash block size");
|
||||||
|
|
||||||
if (data_blocks_string)
|
|
||||||
if (sscanf(data_blocks_string, "%lld%c", &data_blocks, &c) != 1)
|
|
||||||
exit_err("invalid number of data blocks");
|
|
||||||
|
|
||||||
if (data_blocks < 0 || (off_t)data_blocks < 0 || (off_t)data_blocks != data_blocks)
|
if (data_blocks < 0 || (off_t)data_blocks < 0 || (off_t)data_blocks != data_blocks)
|
||||||
exit_err("invalid number of data blocks");
|
exit_err("invalid number of data blocks");
|
||||||
|
|
||||||
@ -931,9 +943,8 @@ int main(int argc, const char **argv)
|
|||||||
|
|
||||||
if (data_file_blocks < data_blocks)
|
if (data_file_blocks < data_blocks)
|
||||||
exit_err("data file is too small");
|
exit_err("data file is too small");
|
||||||
if (data_blocks) {
|
if (data_blocks_string)
|
||||||
data_file_blocks = data_blocks;
|
data_file_blocks = data_blocks;
|
||||||
}
|
|
||||||
|
|
||||||
if (use_superblock) {
|
if (use_superblock) {
|
||||||
hash_start = hash_start + (sizeof(struct superblock) + 511) / 512;
|
hash_start = hash_start + (sizeof(struct superblock) + 511) / 512;
|
||||||
|
Loading…
Reference in New Issue
Block a user