1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Handle decimal digits with --units instead of ignoring them silently.

Fix remaining warnings and compile with -Wpointer-arith.
This commit is contained in:
Alasdair Kergon 2011-02-18 23:09:55 +00:00
parent faf2288895
commit a8d13f9499
7 changed files with 63 additions and 52 deletions

View File

@ -1,5 +1,7 @@
Version 2.02.85 - Version 2.02.85 -
=================================== ===================================
Handle decimal digits with --units instead of ignoring them silently.
Fix remaining warnings and compile with -Wpointer-arith.
Fix gcc warnings for unused variables. Fix gcc warnings for unused variables.
Add stack backtraces for error paths in process_each_lv(). Add stack backtraces for error paths in process_each_lv().
Fixing some const cast gcc warnings in the code. Fixing some const cast gcc warnings in the code.

View File

@ -57,7 +57,7 @@ static DM_LIST_INIT(_open_devices);
* The standard io loop that keeps submitting an io until it's * The standard io loop that keeps submitting an io until it's
* all gone. * all gone.
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
static int _io(struct device_area *where, void *buffer, int should_write) static int _io(struct device_area *where, char *buffer, int should_write)
{ {
int fd = dev_fd(where->dev); int fd = dev_fd(where->dev);
ssize_t n = 0; ssize_t n = 0;
@ -161,10 +161,10 @@ static void _widen_region(unsigned int block_size, struct device_area *region,
result->size += block_size - delta; result->size += block_size - delta;
} }
static int _aligned_io(struct device_area *where, void *buffer, static int _aligned_io(struct device_area *where, char *buffer,
int should_write) int should_write)
{ {
void *bounce, *bounce_buf; char *bounce, *bounce_buf;
unsigned int block_size = 0; unsigned int block_size = 0;
uintptr_t mask; uintptr_t mask;
struct device_area widened; struct device_area widened;
@ -195,7 +195,7 @@ static int _aligned_io(struct device_area *where, void *buffer,
* Realign start of bounce buffer (using the extra sector) * Realign start of bounce buffer (using the extra sector)
*/ */
if (((uintptr_t) bounce) & mask) if (((uintptr_t) bounce) & mask)
bounce = (void *) ((((uintptr_t) bounce) + mask) & ~mask); bounce = (char *) ((((uintptr_t) bounce) + mask) & ~mask);
/* channel the io through the bounce buffer */ /* channel the io through the bounce buffer */
if (!_io(&widened, bounce, 0)) { if (!_io(&widened, bounce, 0)) {
@ -645,7 +645,7 @@ int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer)
* 'buf' should be len+len2. * 'buf' should be len+len2.
*/ */
int dev_read_circular(struct device *dev, uint64_t offset, size_t len, int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
uint64_t offset2, size_t len2, void *buf) uint64_t offset2, size_t len2, char *buf)
{ {
if (!dev_read(dev, offset, len, buf)) { if (!dev_read(dev, offset, len, buf)) {
log_error("Read from %s failed", dev_name(dev)); log_error("Read from %s failed", dev_name(dev));
@ -673,7 +673,7 @@ int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
*/ */
/* FIXME pre-extend the file */ /* FIXME pre-extend the file */
int dev_append(struct device *dev, size_t len, void *buffer) int dev_append(struct device *dev, size_t len, char *buffer)
{ {
int r; int r;

View File

@ -83,9 +83,9 @@ const char *dev_name(const struct device *dev);
int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer); int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer);
int dev_read_circular(struct device *dev, uint64_t offset, size_t len, int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
uint64_t offset2, size_t len2, void *buf); uint64_t offset2, size_t len2, char *buf);
int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer); int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer);
int dev_append(struct device *dev, size_t len, void *buffer); int dev_append(struct device *dev, size_t len, char *buffer);
int dev_set(struct device *dev, uint64_t offset, size_t len, int value); int dev_set(struct device *dev, uint64_t offset, size_t len, int value);
void dev_flush(struct device *dev); void dev_flush(struct device *dev);

View File

@ -44,15 +44,24 @@ uint64_t units_to_bytes(const char *units, char *unit_type)
{ {
char *ptr = NULL; char *ptr = NULL;
uint64_t v; uint64_t v;
double custom_value = 0;
uint64_t multiplier;
if (isdigit(*units)) { if (isdigit(*units)) {
v = (uint64_t) strtod(units, &ptr); custom_value = strtod(units, &ptr);
if (ptr == units) if (ptr == units)
return 0; return 0;
v = (uint64_t) strtoull(units, NULL, 10);
if ((double) v == custom_value)
custom_value = 0; /* Use integer arithmetic */
units = ptr; units = ptr;
} else } else
v = 1; v = 1;
/* Only one units char permitted. */
if (*(units + 1))
return 0;
if (v == 1) if (v == 1)
*unit_type = *units; *unit_type = *units;
else else
@ -61,65 +70,65 @@ uint64_t units_to_bytes(const char *units, char *unit_type)
switch (*units) { switch (*units) {
case 'h': case 'h':
case 'H': case 'H':
v = UINT64_C(1); multiplier = v = UINT64_C(1);
*unit_type = *units; *unit_type = *units;
break; break;
case 'b': case 'b':
case 'B': case 'B':
v *= UINT64_C(1); multiplier = UINT64_C(1);
break; break;
#define KILO UINT64_C(1024) #define KILO UINT64_C(1024)
case 's': case 's':
case 'S': case 'S':
v *= (KILO/2); multiplier = (KILO/2);
break; break;
case 'k': case 'k':
v *= KILO; multiplier = KILO;
break; break;
case 'm': case 'm':
v *= KILO * KILO; multiplier = KILO * KILO;
break; break;
case 'g': case 'g':
v *= KILO * KILO * KILO; multiplier = KILO * KILO * KILO;
break; break;
case 't': case 't':
v *= KILO * KILO * KILO * KILO; multiplier = KILO * KILO * KILO * KILO;
break; break;
case 'p': case 'p':
v *= KILO * KILO * KILO * KILO * KILO; multiplier = KILO * KILO * KILO * KILO * KILO;
break; break;
case 'e': case 'e':
v *= KILO * KILO * KILO * KILO * KILO * KILO; multiplier = KILO * KILO * KILO * KILO * KILO * KILO;
break; break;
#undef KILO #undef KILO
#define KILO UINT64_C(1000) #define KILO UINT64_C(1000)
case 'K': case 'K':
v *= KILO; multiplier = KILO;
break; break;
case 'M': case 'M':
v *= KILO * KILO; multiplier = KILO * KILO;
break; break;
case 'G': case 'G':
v *= KILO * KILO * KILO; multiplier = KILO * KILO * KILO;
break; break;
case 'T': case 'T':
v *= KILO * KILO * KILO * KILO; multiplier = KILO * KILO * KILO * KILO;
break; break;
case 'P': case 'P':
v *= KILO * KILO * KILO * KILO * KILO; multiplier = KILO * KILO * KILO * KILO * KILO;
break; break;
case 'E': case 'E':
v *= KILO * KILO * KILO * KILO * KILO * KILO; multiplier = KILO * KILO * KILO * KILO * KILO * KILO;
break; break;
#undef KILO #undef KILO
default: default:
return 0; return 0;
} }
if (*(units + 1)) if (custom_value)
return 0; return (uint64_t) (custom_value * multiplier);
else
return v; return v * multiplier;
} }
const char alloc_policy_char(alloc_policy_t alloc) const char alloc_policy_char(alloc_policy_t alloc)

View File

@ -141,11 +141,11 @@ static struct cmd_data _cmd_data_v4[] = {
# define DM_EXISTS_FLAG 0x00000004 # define DM_EXISTS_FLAG 0x00000004
#endif #endif
static void *_align(void *ptr, unsigned int a) static char *_align(char *ptr, unsigned int a)
{ {
register unsigned long agn = --a; register unsigned long agn = --a;
return (void *) (((unsigned long) ptr + agn) & ~agn); return (char *) (((unsigned long) ptr + agn) & ~agn);
} }
static int _uname(void) static int _uname(void)
@ -608,9 +608,9 @@ static struct dm_names *_dm_task_get_names_v1(struct dm_task *dmt)
dmt->dmi.v1->data_start); dmt->dmi.v1->data_start);
} }
static void *_add_target_v1(struct target *t, void *out, void *end) static char *_add_target_v1(struct target *t, char *out, char *end)
{ {
void *out_sp = out; char *out_sp = out;
struct dm_target_spec_v1 sp; struct dm_target_spec_v1 sp;
size_t sp_size = sizeof(struct dm_target_spec_v1); size_t sp_size = sizeof(struct dm_target_spec_v1);
int len; int len;
@ -629,7 +629,7 @@ static void *_add_target_v1(struct target *t, void *out, void *end)
if ((out + len + 1) >= end) if ((out + len + 1) >= end)
return_NULL; return_NULL;
strcpy((char *) out, t->params); strcpy(out, t->params);
out += len + 1; out += len + 1;
/* align next block */ /* align next block */
@ -650,7 +650,7 @@ static struct dm_ioctl_v1 *_flatten_v1(struct dm_task *dmt)
struct dm_ioctl_v1 *dmi; struct dm_ioctl_v1 *dmi;
struct target *t; struct target *t;
size_t len = sizeof(struct dm_ioctl_v1); size_t len = sizeof(struct dm_ioctl_v1);
void *b, *e; char *b, *e;
int count = 0; int count = 0;
for (t = dmt->head; t; t = t->next) { for (t = dmt->head; t; t = t->next) {
@ -710,8 +710,8 @@ static struct dm_ioctl_v1 *_flatten_v1(struct dm_task *dmt)
dmi->target_count = count; dmi->target_count = count;
b = (void *) (dmi + 1); b = (char *) (dmi + 1);
e = (void *) ((char *) dmi + len); e = (char *) dmi + len;
for (t = dmt->head; t; t = t->next) for (t = dmt->head; t; t = t->next)
if (!(b = _add_target_v1(t, b, e))) { if (!(b = _add_target_v1(t, b, e))) {
@ -773,7 +773,7 @@ static int _dm_names_v1(struct dm_ioctl_v1 *dmi)
names->dev = (uint64_t) buf.st_rdev; names->dev = (uint64_t) buf.st_rdev;
names->next = 0; names->next = 0;
len = strlen(name); len = strlen(name);
if (((void *) (names + 1) + len + 1) >= end) { if (((char *) (names + 1) + len + 1) >= end) {
log_error("Insufficient buffer space for device list"); log_error("Insufficient buffer space for device list");
r = 0; r = 0;
break; break;
@ -782,7 +782,7 @@ static int _dm_names_v1(struct dm_ioctl_v1 *dmi)
strcpy(names->name, name); strcpy(names->name, name);
old_names = names; old_names = names;
names = _align((void *) ++names + len + 1, ALIGNMENT); names = _align((char *) ++names + len + 1, ALIGNMENT);
} }
if (closedir(d)) if (closedir(d))
@ -1341,9 +1341,9 @@ struct target *create_target(uint64_t start, uint64_t len, const char *type,
return NULL; return NULL;
} }
static void *_add_target(struct target *t, void *out, void *end) static char *_add_target(struct target *t, char *out, char *end)
{ {
void *out_sp = out; char *out_sp = out;
struct dm_target_spec sp; struct dm_target_spec sp;
size_t sp_size = sizeof(struct dm_target_spec); size_t sp_size = sizeof(struct dm_target_spec);
int len; int len;
@ -1362,7 +1362,7 @@ static void *_add_target(struct target *t, void *out, void *end)
if ((out + len + 1) >= end) if ((out + len + 1) >= end)
return_NULL; return_NULL;
strcpy((char *) out, t->params); strcpy(out, t->params);
out += len + 1; out += len + 1;
/* align next block */ /* align next block */
@ -1394,7 +1394,7 @@ static int _lookup_dev_name(uint64_t dev, char *buf, size_t len)
goto out; goto out;
do { do {
names = (void *) names + next; names = (struct dm_names *)((char *) names + next);
if (names->dev == dev) { if (names->dev == dev) {
strncpy(buf, names->name, len); strncpy(buf, names->name, len);
r = 1; r = 1;
@ -1417,7 +1417,7 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
struct target *t; struct target *t;
struct dm_target_msg *tmsg; struct dm_target_msg *tmsg;
size_t len = sizeof(struct dm_ioctl); size_t len = sizeof(struct dm_ioctl);
void *b, *e; char *b, *e;
int count = 0; int count = 0;
for (t = dmt->head; t; t = t->next) { for (t = dmt->head; t; t = t->next) {
@ -1565,8 +1565,8 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
dmi->target_count = count; dmi->target_count = count;
dmi->event_nr = dmt->event_nr; dmi->event_nr = dmt->event_nr;
b = (void *) (dmi + 1); b = (char *) (dmi + 1);
e = (void *) ((char *) dmi + len); e = (char *) dmi + len;
for (t = dmt->head; t; t = t->next) for (t = dmt->head; t; t = t->next)
if (!(b = _add_target(t, b, e))) { if (!(b = _add_target(t, b, e))) {
@ -1652,7 +1652,7 @@ static int _process_all_v4(struct dm_task *dmt)
goto out; goto out;
do { do {
names = (void *) names + next; names = (struct dm_names *)((char *) names + next);
if (!dm_task_set_name(dmt, names->name)) { if (!dm_task_set_name(dmt, names->name)) {
r = 0; r = 0;
goto out; goto out;

View File

@ -675,15 +675,15 @@ int dm_report_set_output_field_name_prefix(struct dm_report *rh, const char *out
/* /*
* Create a row of data for an object * Create a row of data for an object
*/ */
static void * _report_get_field_data(struct dm_report *rh, static void *_report_get_field_data(struct dm_report *rh,
struct field_properties *fp, void *object) struct field_properties *fp, void *object)
{ {
void *ret = fp->type->data_fn(object); char *ret = fp->type->data_fn(object);
if (!ret) if (!ret)
return NULL; return NULL;
return ret + rh->fields[fp->field_num].offset; return (void *)(ret + rh->fields[fp->field_num].offset);
} }
int dm_report_object(struct dm_report *rh, void *object) int dm_report_object(struct dm_report *rh, void *object)

View File

@ -111,9 +111,9 @@ INSTALL_SCRIPT = $(INSTALL) -p $(M_INSTALL_PROGRAM)
.SUFFIXES: .c .d .o .so .a .po .pot .mo .dylib .SUFFIXES: .c .d .o .so .a .po .pot .mo .dylib
CFLAGS += -fPIC -Wall -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -Wmissing-noreturn -Wformat-security -Wredundant-decls CFLAGS += -fPIC -Wall -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -Wmissing-noreturn -Wformat-security -Wredundant-decls -Wpointer-arith
#CFLAGS += -W -Wconversion -Wpointer-arith -Wbad-function-cast -Wcast-qual #CFLAGS += -W -Wconversion -Wbad-function-cast -Wcast-qual
#CFLAGS += -pedantic -std=gnu99 #CFLAGS += -pedantic -std=gnu99
#CFLAGS += -DDEBUG_CRC32 #CFLAGS += -DDEBUG_CRC32