1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-18 10:04:20 +03:00

fixes/improvements

This commit is contained in:
Alasdair Kergon 2012-03-24 02:58:56 +00:00
parent 3d962ed68f
commit 836bafac6e

View File

@ -78,11 +78,11 @@ static const char *root_hash;
static int version = -1;
static int data_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 char *hash_start_string = NULL;
static long long hash_start = 0;
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 *hash_file;
@ -127,7 +127,9 @@ struct superblock {
#define DM_VERITY_SIGNATURE "verity\0\0"
#define DM_VERITY_VERSION 0
__attribute__ ((noreturn))
#if defined(__GNUC__) && __GNUC__ >= 2
__attribute__((__noreturn__))
#endif
static void help(poptContext popt_context,
enum poptCallbackReason reason,
struct poptOption *key,
@ -170,9 +172,8 @@ static struct poptOption popt_options[] = {
};
#if defined(__GNUC__) && __GNUC__ >= 2
__attribute__((__format__(__printf__, 1, 2)))
__attribute__((__format__(__printf__, 1, 2), __noreturn__))
#endif
__attribute__((noreturn))
static void exit_err(const char *msg, ...)
{
va_list args;
@ -183,7 +184,9 @@ static void exit_err(const char *msg, ...)
exit(2);
}
__attribute__((noreturn))
#if defined(__GNUC__) && __GNUC__ >= 2
__attribute__((__noreturn__))
#endif
static void stream_err(FILE *f, const char *msg)
{
if (ferror(f)) {
@ -622,6 +625,8 @@ static void free_target_line(char **line)
static void create_or_verify(void)
{
int i;
memset(calculated_digest, 0, digest_size);
if (mode != MODE_ACTIVATE)
for (i = 0; i < levels; i++) {
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)
{
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);
}
if (!data_blocks) {
if (!data_blocks_string) {
data_blocks = sb_data_blocks;
data_blocks_string = (char *)"";
} else {
if (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.hash_block_bits = ffs(hash_block_size) - 1;
superblock.salt_size = htons(salt_size);
superblock.data_blocks_hi = htonl(data_blocks >> 31 >> 1);
superblock.data_blocks_lo = htonl(data_blocks & 0xFFFFFFFF);
superblock.data_blocks_hi = htonl(data_file_blocks >> 31 >> 1);
superblock.data_blocks_lo = htonl(data_file_blocks & 0xFFFFFFFF);
strncpy((char *)superblock.algorithm, hash_algorithm, sizeof superblock.algorithm);
memcpy(superblock.salt, salt_bytes, salt_size);
@ -818,7 +826,7 @@ int main(int argc, const char **argv)
poptContext popt_context;
int r;
const char *s;
char c;
char *end;
if (sizeof(struct superblock) != 512)
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);
}
if (hash_start_string)
if (sscanf(hash_start_string, "%lld%c", &hash_start, &c) != 1)
if (data_blocks_string) {
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");
}
if (hash_start < 0 ||
(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)
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)
exit_err("invalid number of data blocks");
@ -931,9 +943,8 @@ int main(int argc, const char **argv)
if (data_file_blocks < data_blocks)
exit_err("data file is too small");
if (data_blocks) {
if (data_blocks_string)
data_file_blocks = data_blocks;
}
if (use_superblock) {
hash_start = hash_start + (sizeof(struct superblock) + 511) / 512;