nbdkit/SOURCES/0022-common-utils-vector-Re...

1748 lines
65 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 1674e453d5652018c989059ea19eb79bed7e12c8 Mon Sep 17 00:00:00 2001
From: Nir Soffer <nsoffer@redhat.com>
Date: Sat, 6 Nov 2021 00:03:11 +0200
Subject: [PATCH] common/utils/vector: Rename `size` to `len`
The field `size` may be confusing with the size of the underlying array.
Rename to `len`, a common term for this concept.
Tested with "make check" as regular user, tests that need root or
external libraries (vddk) are not tested.
Ported from libnbd commit cc0567e9aed7e6b40a44bf8eac0a262ac7314fec.
(cherry picked from commit 0b0eece73f04963a66b9adc507e5cbaba608660b)
---
common/allocators/allocator.c | 2 +-
common/allocators/malloc.c | 2 +-
common/allocators/sparse.c | 6 +-
common/allocators/zstd.c | 6 +-
common/regions/regions.h | 6 +-
common/utils/environ.c | 2 +-
common/utils/test-vector.c | 2 +-
common/utils/vector.h | 52 ++++++------
filters/ddrescue/ddrescue.c | 2 +-
filters/exitwhen/exitwhen.c | 2 +-
filters/extentlist/extentlist.c | 14 ++--
filters/multi-conn/multi-conn.c | 16 ++--
plugins/cc/cc.c | 4 +-
plugins/data/data.c | 4 +-
plugins/data/format.c | 114 +++++++++++++--------------
plugins/eval/eval.c | 2 +-
plugins/floppy/directory-lfn.c | 24 +++---
plugins/floppy/floppy.c | 2 +-
plugins/floppy/virtual-floppy.c | 32 ++++----
plugins/iso/iso.c | 4 +-
plugins/nbd/nbd.c | 6 +-
plugins/partitioning/partition-mbr.c | 8 +-
plugins/partitioning/partitioning.c | 18 ++---
plugins/partitioning/virtual-disk.c | 12 +--
plugins/partitioning/virtual-disk.h | 2 +-
plugins/split/split.c | 14 ++--
plugins/ssh/ssh.c | 2 +-
plugins/vddk/reexec.c | 8 +-
plugins/vddk/stats.c | 4 +-
plugins/vddk/worker.c | 4 +-
server/exports.c | 6 +-
server/extents.c | 22 +++---
server/main.c | 2 +-
server/sockets.c | 8 +-
wrapper.c | 4 +-
35 files changed, 209 insertions(+), 209 deletions(-)
diff --git a/common/allocators/allocator.c b/common/allocators/allocator.c
index d306a842..019c68cd 100644
--- a/common/allocators/allocator.c
+++ b/common/allocators/allocator.c
@@ -137,7 +137,7 @@ create_allocator (const char *type, bool debug)
return NULL;
/* See if we can find the allocator. */
- for (i = 0; i < allocators.size; ++i) {
+ for (i = 0; i < allocators.len; ++i) {
if (strncmp (type, allocators.ptr[i]->type, type_len) == 0) {
ret = allocators.ptr[i]->create (&params);
break;
diff --git a/common/allocators/malloc.c b/common/allocators/malloc.c
index f7474465..eea44432 100644
--- a/common/allocators/malloc.c
+++ b/common/allocators/malloc.c
@@ -241,7 +241,7 @@ m_alloc_create (const void *paramsv)
size_t i;
/* Parse the optional mlock=true|false parameter. */
- for (i = 0; i < params->size; ++i) {
+ for (i = 0; i < params->len; ++i) {
if (strcmp (params->ptr[i].key, "mlock") == 0) {
int r = nbdkit_parse_bool (params->ptr[i].value);
if (r == -1) return NULL;
diff --git a/common/allocators/sparse.c b/common/allocators/sparse.c
index ca508c35..7c6d1636 100644
--- a/common/allocators/sparse.c
+++ b/common/allocators/sparse.c
@@ -150,7 +150,7 @@ sparse_array_free (struct allocator *a)
size_t i;
if (sa) {
- for (i = 0; i < sa->l1_dir.size; ++i)
+ for (i = 0; i < sa->l1_dir.len; ++i)
free_l2_dir (sa->l1_dir.ptr[i].l2_dir);
free (sa->l1_dir.ptr);
pthread_mutex_destroy (&sa->lock);
@@ -184,7 +184,7 @@ insert_l1_entry (struct sparse_array *sa, const struct l1_entry *entry)
{
size_t i;
- for (i = 0; i < sa->l1_dir.size; ++i) {
+ for (i = 0; i < sa->l1_dir.len; ++i) {
if (entry->offset < sa->l1_dir.ptr[i].offset) {
/* Insert new entry before i'th directory entry. */
if (l1_dir_insert (&sa->l1_dir, *entry, i) == -1) {
@@ -508,7 +508,7 @@ sparse_array_create (const void *paramsv)
const allocator_parameters *params = paramsv;
struct sparse_array *sa;
- if (params->size > 0) {
+ if (params->len > 0) {
nbdkit_error ("allocator=sparse does not take extra parameters");
return NULL;
}
diff --git a/common/allocators/zstd.c b/common/allocators/zstd.c
index 81fe4ed0..1675d21c 100644
--- a/common/allocators/zstd.c
+++ b/common/allocators/zstd.c
@@ -136,7 +136,7 @@ zstd_array_free (struct allocator *a)
ZSTD_freeCCtx (za->zcctx);
ZSTD_freeDStream (za->zdstrm);
- for (i = 0; i < za->l1_dir.size; ++i)
+ for (i = 0; i < za->l1_dir.len; ++i)
free_l2_dir (za->l1_dir.ptr[i].l2_dir);
free (za->l1_dir.ptr);
pthread_mutex_destroy (&za->lock);
@@ -170,7 +170,7 @@ insert_l1_entry (struct zstd_array *za, const struct l1_entry *entry)
{
size_t i;
- for (i = 0; i < za->l1_dir.size; ++i) {
+ for (i = 0; i < za->l1_dir.len; ++i) {
if (entry->offset < za->l1_dir.ptr[i].offset) {
/* Insert new entry before i'th directory entry. */
if (l1_dir_insert (&za->l1_dir, *entry, i) == -1) {
@@ -600,7 +600,7 @@ zstd_array_create (const void *paramsv)
const allocator_parameters *params = paramsv;
struct zstd_array *za;
- if (params->size > 0) {
+ if (params->len > 0) {
nbdkit_error ("allocator=zstd does not take extra parameters");
return NULL;
}
diff --git a/common/regions/regions.h b/common/regions/regions.h
index 6dfd5d88..3d562316 100644
--- a/common/regions/regions.h
+++ b/common/regions/regions.h
@@ -84,17 +84,17 @@ extern void free_regions (regions *regions)
static inline size_t __attribute__((__nonnull__ (1)))
nr_regions (regions *rs)
{
- return rs->size;
+ return rs->len;
}
/* Return the virtual size of the disk. */
static inline int64_t __attribute__((__nonnull__ (1)))
virtual_size (regions *rs)
{
- if (rs->size == 0)
+ if (rs->len == 0)
return 0;
else
- return rs->ptr[rs->size-1].end + 1;
+ return rs->ptr[rs->len-1].end + 1;
}
/* Look up the region corresponding to the given offset. If the
diff --git a/common/utils/environ.c b/common/utils/environ.c
index e70976cb..2ad996eb 100644
--- a/common/utils/environ.c
+++ b/common/utils/environ.c
@@ -82,7 +82,7 @@ copy_environ (char **env, ...)
/* Search for key in the existing environment. It's O(n^2) ... */
len = strlen (key);
- for (i = 0; i < ret.size; ++i) {
+ for (i = 0; i < ret.len; ++i) {
if (strncmp (key, ret.ptr[i], len) == 0 && ret.ptr[i][len] == '=') {
/* Replace the existing key. */
free (ret.ptr[i]);
diff --git a/common/utils/test-vector.c b/common/utils/test-vector.c
index 28af59b8..6d89a281 100644
--- a/common/utils/test-vector.c
+++ b/common/utils/test-vector.c
@@ -73,7 +73,7 @@ test_int64_vector (void)
assert (v.ptr[i] == i);
int64_vector_remove (&v, 1);
- assert (v.size == 9);
+ assert (v.len == 9);
assert (v.ptr[1] == 2);
tmp = 10;
diff --git a/common/utils/vector.h b/common/utils/vector.h
index 782dcba6..1d04f812 100644
--- a/common/utils/vector.h
+++ b/common/utils/vector.h
@@ -59,14 +59,14 @@
*
* string_vector names = empty_vector;
*
- * where names.ptr[] will be an array of strings and names.size
+ * where names.ptr[] will be an array of strings and names.len
* will be the number of strings. There are no get/set accessors. To
* iterate over the strings you can use the .ptr field directly:
*
- * for (size_t i = 0; i < names.size; ++i)
+ * for (size_t i = 0; i < names.len; ++i)
* printf ("%s\n", names.ptr[i]);
*
- * Initializing with empty_vector sets .ptr = NULL and .size = 0.
+ * Initializing with empty_vector sets .ptr = NULL and .len = 0.
*
* DEFINE_VECTOR_TYPE also defines utility functions. For the full
* list see the definition below, but useful functions include:
@@ -84,15 +84,15 @@
*/
#define DEFINE_VECTOR_TYPE(name, type) \
struct name { \
- type *ptr; /* Pointer to array of items. */ \
- size_t size; /* Number of valid items in the array. */ \
- size_t cap; /* Maximum number of items. */ \
+ type *ptr; /* Pointer to array of items. */ \
+ size_t len; /* Number of valid items in the array. */ \
+ size_t cap; /* Maximum number of items. */ \
}; \
typedef struct name name; \
\
/* Reserve n elements at the end of the vector. Note space is \
- * allocated but the vector size is not increased and the new \
- * elements are not initialized. \
+ * allocated and capacity is increased, but the vector length \
+ * is not increased and the new elements are not initialized. \
*/ \
static inline int \
name##_reserve (name *v, size_t n) \
@@ -101,17 +101,17 @@
sizeof (type)); \
} \
\
- /* Insert at i'th element. i=0 => beginning i=size => append */ \
+ /* Insert at i'th element. i=0 => beginning i=len => append */ \
static inline int \
name##_insert (name *v, type elem, size_t i) \
{ \
- assert (i <= v->size); \
- if (v->size >= v->cap) { \
+ assert (i <= v->len); \
+ if (v->len >= v->cap) { \
if (name##_reserve (v, 1) == -1) return -1; \
} \
- memmove (&v->ptr[i+1], &v->ptr[i], (v->size-i) * sizeof (elem)); \
+ memmove (&v->ptr[i+1], &v->ptr[i], (v->len-i) * sizeof (elem)); \
v->ptr[i] = elem; \
- v->size++; \
+ v->len++; \
return 0; \
} \
\
@@ -119,16 +119,16 @@
static inline int \
name##_append (name *v, type elem) \
{ \
- return name##_insert (v, elem, v->size); \
+ return name##_insert (v, elem, v->len); \
} \
\
- /* Remove i'th element. i=0 => beginning i=size-1 => end */ \
+ /* Remove i'th element. i=0 => beginning i=len-1 => end */ \
static inline void \
name##_remove (name *v, size_t i) \
{ \
- assert (i < v->size); \
- memmove (&v->ptr[i], &v->ptr[i+1], (v->size-i-1) * sizeof (type)); \
- v->size--; \
+ assert (i < v->len); \
+ memmove (&v->ptr[i], &v->ptr[i+1], (v->len-i-1) * sizeof (type)); \
+ v->len--; \
} \
\
/* Remove all elements and deallocate the vector. */ \
@@ -137,7 +137,7 @@
{ \
free (v->ptr); \
v->ptr = NULL; \
- v->size = v->cap = 0; \
+ v->len = v->cap = 0; \
} \
\
/* Iterate over the vector, calling f() on each element. */ \
@@ -145,7 +145,7 @@
name##_iter (name *v, void (*f) (type elem)) \
{ \
size_t i; \
- for (i = 0; i < v->size; ++i) \
+ for (i = 0; i < v->len; ++i) \
f (v->ptr[i]); \
} \
\
@@ -154,7 +154,7 @@
name##_sort (name *v, \
int (*compare) (const type *p1, const type *p2)) \
{ \
- qsort (v->ptr, v->size, sizeof (type), (void *) compare); \
+ qsort (v->ptr, v->len, sizeof (type), (void *) compare); \
} \
\
/* Search for an exactly matching element in the vector using a \
@@ -164,7 +164,7 @@
name##_search (const name *v, const void *key, \
int (*compare) (const void *key, const type *v)) \
{ \
- return bsearch (key, v->ptr, v->size, sizeof (type), \
+ return bsearch (key, v->ptr, v->len, sizeof (type), \
(void *) compare); \
} \
\
@@ -175,22 +175,22 @@
/* Note it's allowed for v and copy to be the same pointer. */ \
type *vptr = v->ptr; \
type *newptr; \
- size_t len = v->size * sizeof (type); \
+ size_t len = v->len * sizeof (type); \
\
newptr = malloc (len); \
if (newptr == NULL) return -1; \
memcpy (newptr, vptr, len); \
copy->ptr = newptr; \
- copy->size = copy->cap = v->size; \
+ copy->len = copy->cap = v->len; \
return 0; \
} \
\
-#define empty_vector { .ptr = NULL, .size = 0, .cap = 0 }
+#define empty_vector { .ptr = NULL, .len = 0, .cap = 0 }
struct generic_vector {
void *ptr;
- size_t size;
+ size_t len;
size_t cap;
};
diff --git a/filters/ddrescue/ddrescue.c b/filters/ddrescue/ddrescue.c
index 7b1c9c1e..218c8ee5 100644
--- a/filters/ddrescue/ddrescue.c
+++ b/filters/ddrescue/ddrescue.c
@@ -180,7 +180,7 @@ ddrescue_pread (nbdkit_next *next,
{
size_t i;
- for (i = 0; i < map.ranges.size; i++) {
+ for (i = 0; i < map.ranges.len; i++) {
if (map.ranges.ptr[i].status != '+')
continue;
if (offset >= map.ranges.ptr[i].start && offset <= map.ranges.ptr[i].end) {
diff --git a/filters/exitwhen/exitwhen.c b/filters/exitwhen/exitwhen.c
index 543af058..83e99953 100644
--- a/filters/exitwhen/exitwhen.c
+++ b/filters/exitwhen/exitwhen.c
@@ -143,7 +143,7 @@ check_for_event (void)
size_t i;
if (!exiting) {
- for (i = 0; i < events.size; ++i) {
+ for (i = 0; i < events.len; ++i) {
const struct event *event = &events.ptr[i];
switch (event->type) {
diff --git a/filters/extentlist/extentlist.c b/filters/extentlist/extentlist.c
index 7e6f1b78..c91fbfea 100644
--- a/filters/extentlist/extentlist.c
+++ b/filters/extentlist/extentlist.c
@@ -134,7 +134,7 @@ parse_extentlist (void)
assert (extentlist != NULL);
assert (extents.ptr == NULL);
- assert (extents.size == 0);
+ assert (extents.len == 0);
fp = fopen (extentlist, "r");
if (!fp) {
@@ -200,7 +200,7 @@ parse_extentlist (void)
/* There must not be overlaps at this point. */
end = 0;
- for (i = 0; i < extents.size; ++i) {
+ for (i = 0; i < extents.len; ++i) {
if (extents.ptr[i].offset < end ||
extents.ptr[i].offset + extents.ptr[i].length < extents.ptr[i].offset) {
nbdkit_error ("extents in the extent list are overlapping");
@@ -210,8 +210,8 @@ parse_extentlist (void)
}
/* If there's a gap at the beginning, insert a hole|zero extent. */
- if (extents.size == 0 || extents.ptr[0].offset > 0) {
- end = extents.size == 0 ? UINT64_MAX : extents.ptr[0].offset;
+ if (extents.len == 0 || extents.ptr[0].offset > 0) {
+ end = extents.len == 0 ? UINT64_MAX : extents.ptr[0].offset;
if (extent_list_insert (&extents,
(struct extent){.offset = 0, .length = end,
.type = HOLE},
@@ -224,7 +224,7 @@ parse_extentlist (void)
/* Now insert hole|zero extents after every extent where there
* is a gap between that extent and the next one.
*/
- for (i = 0; i < extents.size-1; ++i) {
+ for (i = 0; i < extents.len-1; ++i) {
end = extents.ptr[i].offset + extents.ptr[i].length;
if (end < extents.ptr[i+1].offset)
if (extent_list_insert (&extents,
@@ -238,7 +238,7 @@ parse_extentlist (void)
}
/* If there's a gap at the end, insert a hole|zero extent. */
- end = extents.ptr[extents.size-1].offset + extents.ptr[extents.size-1].length;
+ end = extents.ptr[extents.len-1].offset + extents.ptr[extents.len-1].length;
if (end < UINT64_MAX) {
if (extent_list_append (&extents,
(struct extent){.offset = end,
@@ -250,7 +250,7 @@ parse_extentlist (void)
}
/* Debug the final list. */
- for (i = 0; i < extents.size; ++i) {
+ for (i = 0; i < extents.len; ++i) {
nbdkit_debug ("extentlist: "
"extent[%zu] = %" PRIu64 "-%" PRIu64 " (length %" PRIu64 ")"
" type %" PRIu32,
diff --git a/filters/multi-conn/multi-conn.c b/filters/multi-conn/multi-conn.c
index a6a25ef9..c7421a39 100644
--- a/filters/multi-conn/multi-conn.c
+++ b/filters/multi-conn/multi-conn.c
@@ -207,14 +207,14 @@ multi_conn_prepare (nbdkit_next *next, void *handle, int readonly)
ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lock);
if (byname) {
g = NULL;
- for (i = 0; i < groups.size; i++)
+ for (i = 0; i < groups.len; i++)
if (strcmp (groups.ptr[i]->name, h->name) == 0) {
g = groups.ptr[i];
break;
}
}
else
- g = groups.size ? groups.ptr[0] : NULL;
+ g = groups.len ? groups.ptr[0] : NULL;
if (!g) {
g = calloc (1, sizeof *g);
@@ -230,7 +230,7 @@ multi_conn_prepare (nbdkit_next *next, void *handle, int readonly)
}
if (conns_vector_append (&g->conns, h) == -1) {
if (new_group) {
- group_vector_remove (&groups, groups.size - 1);
+ group_vector_remove (&groups, groups.len - 1);
free (g->name);
free (g);
}
@@ -251,14 +251,14 @@ multi_conn_finalize (nbdkit_next *next, void *handle)
assert (h->group);
/* XXX should we add a config param to flush if the client forgot? */
- for (i = 0; i < h->group->conns.size; i++) {
+ for (i = 0; i < h->group->conns.len; i++) {
if (h->group->conns.ptr[i] == h) {
conns_vector_remove (&h->group->conns, i);
break;
}
}
- if (h->group->conns.size == 0) {
- for (i = 0; i < groups.size; i++)
+ if (h->group->conns.len == 0) {
+ for (i = 0; i < groups.len; i++)
if (groups.ptr[i] == h->group) {
group_vector_remove (&groups, i);
free (h->group->name);
@@ -451,7 +451,7 @@ multi_conn_flush (nbdkit_next *next,
assert (h->group);
if (h->mode == EMULATE) {
ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lock);
- for (i = 0; i < h->group->conns.size; i++) {
+ for (i = 0; i < h->group->conns.len; i++) {
h2 = h->group->conns.ptr[i];
if (track == OFF || (h->group->dirty &&
(track == FAST || h2->dirty & READ)) ||
@@ -474,7 +474,7 @@ multi_conn_flush (nbdkit_next *next,
case CONN:
if (next->can_multi_conn (next) == 1) {
ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lock);
- for (i = 0; i < h->group->conns.size; i++)
+ for (i = 0; i < h->group->conns.len; i++)
h->group->conns.ptr[i]->dirty = 0;
h->group->dirty = 0;
}
diff --git a/plugins/cc/cc.c b/plugins/cc/cc.c
index 3251f312..c8c3c86b 100644
--- a/plugins/cc/cc.c
+++ b/plugins/cc/cc.c
@@ -292,12 +292,12 @@ cc_config_complete (void)
if (subplugin.load)
subplugin.load ();
if (subplugin.config) {
- for (i = 0; i < params.size; ++i) {
+ for (i = 0; i < params.len; ++i) {
if (subplugin.config (params.ptr[i].key, params.ptr[i].value) == -1)
return -1;
}
}
- else if (params.size > 0) {
+ else if (params.len > 0) {
/* Just print the first one in the error message. */
nbdkit_error ("unknown parameter: %s", params.ptr[0].key);
return -1;
diff --git a/plugins/data/data.c b/plugins/data/data.c
index 03bcc8a5..960cf97d 100644
--- a/plugins/data/data.c
+++ b/plugins/data/data.c
@@ -158,7 +158,7 @@ get_extra_param (const char *name)
{
size_t i;
- for (i = 0; i < params.size; ++i) {
+ for (i = 0; i < params.len; ++i) {
if (strcmp (params.ptr[i].key, name) == 0)
return params.ptr[i].value;
}
@@ -176,7 +176,7 @@ data_config_complete (void)
return -1;
}
- if (data_seen != DATA && params.size != 0) {
+ if (data_seen != DATA && params.len != 0) {
nbdkit_error ("extra parameters passed and not using data='...'");
return -1;
}
diff --git a/plugins/data/format.c b/plugins/data/format.c
index d351f79a..986a0f6e 100644
--- a/plugins/data/format.c
+++ b/plugins/data/format.c
@@ -83,7 +83,7 @@ substring (string s, size_t offset, size_t len)
string r = empty_vector;
for (i = 0; i < len; ++i) {
- assert (offset+i < s.size);
+ assert (offset+i < s.len);
if (string_append (&r, s.ptr[offset+i]) == -1) {
nbdkit_error ("realloc: %m");
exit (EXIT_FAILURE);
@@ -167,7 +167,7 @@ static expr_list expr_table;
static node_id
new_node (const expr_t e)
{
- if (expr_table.size == 0) {
+ if (expr_table.len == 0) {
static const expr_t enull = { .t = EXPR_NULL };
if (expr_list_append (&expr_table, enull) == -1)
goto out_of_memory;
@@ -179,14 +179,14 @@ new_node (const expr_t e)
nbdkit_error ("realloc");
exit (EXIT_FAILURE);
}
- return expr_table.size-1;
+ return expr_table.len-1;
}
/* Get an expression by node_id. */
static expr_t
get_node (node_id id)
{
- assert (id < expr_table.size);
+ assert (id < expr_table.len);
return expr_table.ptr[id];
}
@@ -196,7 +196,7 @@ free_expr_table (void)
size_t i;
expr_t e;
- for (i = 0; i < expr_table.size; ++i) {
+ for (i = 0; i < expr_table.len; ++i) {
e = get_node (i);
switch (e.t) {
case EXPR_LIST: free (e.list.ptr); break;
@@ -344,7 +344,7 @@ debug_expr (node_id id, int level)
break;
case EXPR_LIST:
nbdkit_debug ("%s(", debug_indent (level));
- for (i = 0; i < e.list.size; ++i)
+ for (i = 0; i < e.list.len; ++i)
debug_expr (e.list.ptr[i], level+1);
nbdkit_debug ("%s)", debug_indent (level));
break;
@@ -370,7 +370,7 @@ debug_expr (node_id id, int level)
CLEANUP_FREE_STRING string s = empty_vector;
static const char hex[] = "0123456789abcdef";
- for (i = 0; i < e.string.size; ++i) {
+ for (i = 0; i < e.string.len; ++i) {
char c = e.string.ptr[i];
if (ascii_isprint ((char) c))
string_append (&s, e.string.ptr[i]);
@@ -445,7 +445,7 @@ read_data_format (const char *value, struct allocator *a, uint64_t *size_rtn)
uint64_t offset = 0;
int r = -1;
- assert (expr_table.size == 0);
+ assert (expr_table.len == 0);
/* Run the parser across the entire string, returning the top level
* expression.
@@ -600,11 +600,11 @@ parser (int level, const char *value, size_t *start, size_t len,
case '*': /* expr*N */
i++;
- if (list.size == 0) {
+ if (list.len == 0) {
nbdkit_error ("*N must follow an expression");
return -1;
}
- if (! is_data_expr (get_node (list.ptr[list.size-1]))) {
+ if (! is_data_expr (get_node (list.ptr[list.len-1]))) {
nbdkit_error ("*N cannot be applied to this type of expression");
return -1;
}
@@ -619,18 +619,18 @@ parser (int level, const char *value, size_t *start, size_t len,
nbdkit_error ("*N not numeric");
return -1;
}
- id = list.ptr[list.size-1];
- list.size--;
+ id = list.ptr[list.len-1];
+ list.len--;
APPEND_EXPR (new_node (expr (EXPR_REPEAT, id, (uint64_t) i64)));
break;
case '[': /* expr[k:m] */
i++;
- if (list.size == 0) {
+ if (list.len == 0) {
nbdkit_error ("[N:M] must follow an expression");
return -1;
}
- if (! is_data_expr (get_node (list.ptr[list.size-1]))) {
+ if (! is_data_expr (get_node (list.ptr[list.len-1]))) {
nbdkit_error ("[N:M] cannot be applied to this type of expression");
return -1;
}
@@ -647,8 +647,8 @@ parser (int level, const char *value, size_t *start, size_t len,
nbdkit_error ("enclosed pattern (...)[N:M] not numeric");
return -1;
}
- id = list.ptr[list.size-1];
- list.size--;
+ id = list.ptr[list.len-1];
+ list.len--;
APPEND_EXPR (new_node (expr (EXPR_SLICE, id, i64, m)));
break;
@@ -720,11 +720,11 @@ parser (int level, const char *value, size_t *start, size_t len,
i++;
if (value[i] != '>') goto parse_error;
i++;
- if (list.size == 0) {
+ if (list.len == 0) {
nbdkit_error ("-> must follow an expression");
return -1;
}
- if (! is_data_expr (get_node (list.ptr[list.size-1]))) {
+ if (! is_data_expr (get_node (list.ptr[list.len-1]))) {
nbdkit_error ("-> cannot be applied to this type of expression");
return -1;
}
@@ -735,9 +735,9 @@ parser (int level, const char *value, size_t *start, size_t len,
nbdkit_error ("strndup: %m");
return -1;
}
- id = list.ptr[list.size-1];
+ id = list.ptr[list.len-1];
i += flen;
- list.size--;
+ list.len--;
APPEND_EXPR (new_node (expr (EXPR_ASSIGN, name, id)));
break;
}
@@ -1023,7 +1023,7 @@ parse_word (const char *value, size_t *start, size_t len, string *rtn)
}
memcpy (copy.ptr, &value[*start], n);
copy.ptr[n] = '\0';
- copy.size = n + 1;
+ copy.len = n + 1;
*start = i;
/* Reserve enough space in the return buffer for the longest
@@ -1036,22 +1036,22 @@ parse_word (const char *value, size_t *start, size_t len, string *rtn)
/* Parse the rest of {le|be}{16|32|64}: */
if (strncmp (copy.ptr, "le16:", 5) == 0) {
- endian = little; rtn->size = 2;
+ endian = little; rtn->len = 2;
}
else if (strncmp (copy.ptr, "le32:", 5) == 0) {
- endian = little; rtn->size = 4;
+ endian = little; rtn->len = 4;
}
else if (strncmp (copy.ptr, "le64:", 5) == 0) {
- endian = little; rtn->size = 8;
+ endian = little; rtn->len = 8;
}
else if (strncmp (copy.ptr, "be16:", 5) == 0) {
- endian = big; rtn->size = 2;
+ endian = big; rtn->len = 2;
}
else if (strncmp (copy.ptr, "be32:", 5) == 0) {
- endian = big; rtn->size = 4;
+ endian = big; rtn->len = 4;
}
else if (strncmp (copy.ptr, "be64:", 5) == 0) {
- endian = big; rtn->size = 8;
+ endian = big; rtn->len = 8;
}
else {
nbdkit_error ("data parameter: expected \"le16/32/64:\" "
@@ -1060,7 +1060,7 @@ parse_word (const char *value, size_t *start, size_t len, string *rtn)
}
/* Parse the word field into a host-order unsigned int. */
- switch (rtn->size) {
+ switch (rtn->len) {
case 2:
if (nbdkit_parse_uint16_t ("data", &copy.ptr[5], &u16) == -1)
return -1;
@@ -1081,7 +1081,7 @@ parse_word (const char *value, size_t *start, size_t len, string *rtn)
*/
switch (endian) {
case little:
- switch (rtn->size) {
+ switch (rtn->len) {
case 2: /* le16: */
*((uint16_t *) rtn->ptr) = htole16 (u16);
break;
@@ -1096,7 +1096,7 @@ parse_word (const char *value, size_t *start, size_t len, string *rtn)
break;
case big:
- switch (rtn->size) {
+ switch (rtn->len) {
case 2: /* be16: */
*((uint16_t *) rtn->ptr) = htobe16 (u16);
break;
@@ -1134,7 +1134,7 @@ optimize_ast (node_id root, node_id *root_rtn)
/* For convenience this makes a new list node. */
/* Optimize each element of the list. */
- for (i = 0; i < get_node (root).list.size; ++i) {
+ for (i = 0; i < get_node (root).list.len; ++i) {
id = get_node (root).list.ptr[i];
if (optimize_ast (id, &id) == -1)
return -1;
@@ -1148,7 +1148,7 @@ optimize_ast (node_id root, node_id *root_rtn)
* because flattening the list changes the scope.
*/
if (list_safe_to_inline (get_node (id).list)) {
- for (j = 0; j < get_node (id).list.size; ++j) {
+ for (j = 0; j < get_node (id).list.len; ++j) {
if (node_ids_append (&list, get_node (id).list.ptr[j]) == -1)
goto list_append_error;
}
@@ -1165,7 +1165,7 @@ optimize_ast (node_id root, node_id *root_rtn)
}
/* Combine adjacent pairs of elements if possible. */
- for (i = 1; i < list.size; ++i) {
+ for (i = 1; i < list.len; ++i) {
node_id id0, id1;
id0 = list.ptr[i-1];
@@ -1178,7 +1178,7 @@ optimize_ast (node_id root, node_id *root_rtn)
}
/* List of length 0 is replaced with null. */
- if (list.size == 0) {
+ if (list.len == 0) {
free (list.ptr);
*root_rtn = new_node (expr (EXPR_NULL));
return 0;
@@ -1187,7 +1187,7 @@ optimize_ast (node_id root, node_id *root_rtn)
/* List of length 1 is replaced with the first element, but as
* above avoid inlining if it is not a safe expression.
*/
- if (list.size == 1 && expr_safe_to_inline (get_node (list.ptr[0]))) {
+ if (list.len == 1 && expr_safe_to_inline (get_node (list.ptr[0]))) {
id = list.ptr[0];
free (list.ptr);
*root_rtn = id;
@@ -1242,13 +1242,13 @@ optimize_ast (node_id root, node_id *root_rtn)
*/
if (get_node (id).t == EXPR_STRING &&
get_node (root).r.n <= 4 &&
- get_node (id).string.size <= 512) {
+ get_node (id).string.len <= 512) {
string s = empty_vector;
size_t n = get_node (root).r.n;
const string sub = get_node (id).string;
for (i = 0; i < n; ++i) {
- for (j = 0; j < sub.size; ++j) {
+ for (j = 0; j < sub.len; ++j) {
if (string_append (&s, sub.ptr[j]) == -1) {
nbdkit_error ("realloc: %m");
return -1;
@@ -1307,7 +1307,7 @@ optimize_ast (node_id root, node_id *root_rtn)
}
break;
case EXPR_STRING: /* substring */
- len = get_node (id).string.size;
+ len = get_node (id).string.len;
if (m >= 0 && n <= m && m <= len) {
if (m-n == 1)
*root_rtn = new_node (expr (EXPR_BYTE, get_node (id).string.ptr[n]));
@@ -1355,23 +1355,23 @@ optimize_ast (node_id root, node_id *root_rtn)
case EXPR_STRING:
/* A zero length string can be replaced with null. */
- if (get_node (root).string.size == 0) {
+ if (get_node (root).string.len == 0) {
*root_rtn = new_node (expr (EXPR_NULL));
return 0;
}
/* Strings containing the same character can be replaced by a
* fill. These can be produced by other optimizations.
*/
- if (get_node (root).string.size > 1) {
+ if (get_node (root).string.len > 1) {
const string s = get_node (root).string;
uint8_t b = s.ptr[0];
- for (i = 1; i < s.size; ++i)
+ for (i = 1; i < s.len; ++i)
if (s.ptr[i] != b)
break;
- if (i == s.size) {
- *root_rtn = new_node (expr (EXPR_FILL, b, (uint64_t) s.size));
+ if (i == s.len) {
+ *root_rtn = new_node (expr (EXPR_FILL, b, (uint64_t) s.len));
return 0;
}
}
@@ -1442,7 +1442,7 @@ list_safe_to_inline (const node_ids list)
{
size_t i;
- for (i = 0; i < list.size; ++i) {
+ for (i = 0; i < list.len; ++i) {
if (!expr_safe_to_inline (get_node (list.ptr[i])))
return false;
}
@@ -1461,11 +1461,11 @@ expr_is_single_byte (const expr_t e, uint8_t *b)
if (b) *b = e.b;
return true;
case EXPR_LIST: /* A single element list if it is single byte */
- if (e.list.size != 1)
+ if (e.list.len != 1)
return false;
return expr_is_single_byte (get_node (e.list.ptr[0]), b);
case EXPR_STRING: /* A length-1 string. */
- if (e.string.size != 1)
+ if (e.string.len != 1)
return false;
if (b) *b = e.string.ptr[0];
return true;
@@ -1511,10 +1511,10 @@ exprs_can_combine (expr_t e0, expr_t e1, node_id *id_rtn)
}
return true;
case EXPR_STRING: /* byte string => string */
- len = e1.string.size;
+ len = e1.string.len;
if (string_reserve (&s, len+1) == -1)
goto out_of_memory;
- s.size = len+1;
+ s.len = len+1;
s.ptr[0] = e0.b;
memcpy (&s.ptr[1], e1.string.ptr, len);
*id_rtn = new_node (expr (EXPR_STRING, s));
@@ -1533,20 +1533,20 @@ exprs_can_combine (expr_t e0, expr_t e1, node_id *id_rtn)
case EXPR_STRING:
switch (e1.t) {
case EXPR_BYTE: /* string byte => string */
- len = e0.string.size;
+ len = e0.string.len;
if (string_reserve (&s, len+1) == -1)
goto out_of_memory;
- s.size = len+1;
+ s.len = len+1;
memcpy (s.ptr, e0.string.ptr, len);
s.ptr[len] = e1.b;
*id_rtn = new_node (expr (EXPR_STRING, s));
return true;
case EXPR_STRING: /* string string => string */
- len = e0.string.size;
- len1 = e1.string.size;
+ len = e0.string.len;
+ len1 = e1.string.len;
if (string_reserve (&s, len+len1) == -1)
goto out_of_memory;
- s.size = len+len1;
+ s.len = len+len1;
memcpy (s.ptr, e0.string.ptr, len);
memcpy (&s.ptr[len], e1.string.ptr, len1);
*id_rtn = new_node (expr (EXPR_STRING, s));
@@ -1618,11 +1618,11 @@ evaluate (const dict_t *dict, node_id root,
list = get_node (root).list;
}
else {
- list.size = 1;
+ list.len = 1;
list.ptr = &root;
}
- for (i = 0; i < list.size; ++i) {
+ for (i = 0; i < list.len; ++i) {
const expr_t e = get_node (list.ptr[i]);
switch (e.t) {
@@ -1667,9 +1667,9 @@ evaluate (const dict_t *dict, node_id root,
case EXPR_STRING:
/* Copy the string into the allocator. */
- if (a->f->write (a, e.string.ptr, e.string.size, *offset) == -1)
+ if (a->f->write (a, e.string.ptr, e.string.len, *offset) == -1)
return -1;
- *offset += e.string.size;
+ *offset += e.string.len;
break;
case EXPR_FILL:
diff --git a/plugins/eval/eval.c b/plugins/eval/eval.c
index fa1c23ff..b312a59c 100644
--- a/plugins/eval/eval.c
+++ b/plugins/eval/eval.c
@@ -114,7 +114,7 @@ insert_method_script (const char *method, char *script)
size_t i;
struct method_script new_entry = { .method = method, .script = script };
- for (i = 0; i < method_scripts.size; ++i) {
+ for (i = 0; i < method_scripts.len; ++i) {
r = compare_script (method, &method_scripts.ptr[i]);
/* This shouldn't happen. insert_method_script() must not be
* called if the method has already been added. Call get_script()
diff --git a/plugins/floppy/directory-lfn.c b/plugins/floppy/directory-lfn.c
index a87d376a..fe47e0b6 100644
--- a/plugins/floppy/directory-lfn.c
+++ b/plugins/floppy/directory-lfn.c
@@ -79,8 +79,8 @@ create_directory (size_t di, const char *label,
struct virtual_floppy *floppy)
{
size_t i;
- const size_t nr_subdirs = floppy->dirs.ptr[di].subdirs.size;
- const size_t nr_files = floppy->dirs.ptr[di].fileidxs.size;
+ const size_t nr_subdirs = floppy->dirs.ptr[di].subdirs.len;
+ const size_t nr_files = floppy->dirs.ptr[di].fileidxs.len;
struct lfn *lfns, *lfn;
const char *name;
uint8_t attributes;
@@ -109,14 +109,14 @@ create_directory (size_t di, const char *label,
}
for (i = 0; i < nr_subdirs; ++i) {
const size_t sdi = floppy->dirs.ptr[di].subdirs.ptr[i];
- assert (sdi < floppy->dirs.size);
+ assert (sdi < floppy->dirs.len);
name = floppy->dirs.ptr[sdi].name;
lfns[i].name = name;
}
for (i = 0; i < nr_files; ++i) {
const size_t fi = floppy->dirs.ptr[di].fileidxs.ptr[i];
- assert (fi < floppy->files.size);
+ assert (fi < floppy->files.len);
name = floppy->files.ptr[fi].name;
lfns[nr_subdirs+i].name = name;
@@ -132,7 +132,7 @@ create_directory (size_t di, const char *label,
file_size = 0;
for (i = 0; i < nr_subdirs; ++i) {
const size_t sdi = floppy->dirs.ptr[di].subdirs.ptr[i];
- assert (sdi < floppy->dirs.size);
+ assert (sdi < floppy->dirs.len);
lfn = &lfns[i];
statbuf = &floppy->dirs.ptr[sdi].statbuf;
@@ -148,7 +148,7 @@ create_directory (size_t di, const char *label,
attributes = DIR_ENTRY_ARCHIVE; /* Same as set by Linux kernel. */
for (i = 0; i < nr_files; ++i) {
const size_t fi = floppy->dirs.ptr[di].fileidxs.ptr[i];
- assert (fi < floppy->files.size);
+ assert (fi < floppy->files.len);
lfn = &lfns[nr_subdirs+i];
statbuf = &floppy->files.ptr[fi].statbuf;
@@ -532,7 +532,7 @@ append_dir_table (size_t di, const struct dir_entry *entry,
{
size_t i;
- i = floppy->dirs.ptr[di].table.size;
+ i = floppy->dirs.ptr[di].table.len;
if (dir_entries_append (&floppy->dirs.ptr[di].table, *entry) == -1) {
nbdkit_error ("realloc: %m");
return -1;
@@ -550,8 +550,8 @@ int
update_directory_first_cluster (size_t di, struct virtual_floppy *floppy)
{
size_t i, j, pdi;
- const size_t nr_subdirs = floppy->dirs.ptr[di].subdirs.size;
- const size_t nr_files = floppy->dirs.ptr[di].fileidxs.size;
+ const size_t nr_subdirs = floppy->dirs.ptr[di].subdirs.len;
+ const size_t nr_files = floppy->dirs.ptr[di].fileidxs.len;
uint32_t first_cluster;
struct dir_entry *entry;
@@ -561,7 +561,7 @@ update_directory_first_cluster (size_t di, struct virtual_floppy *floppy)
* table entries.
*/
i = 0;
- for (j = 0; j < floppy->dirs.ptr[di].table.size; ++j) {
+ for (j = 0; j < floppy->dirs.ptr[di].table.len; ++j) {
entry = &floppy->dirs.ptr[di].table.ptr[j];
/* Skip LFN entries. */
@@ -596,12 +596,12 @@ update_directory_first_cluster (size_t di, struct virtual_floppy *floppy)
*/
if (i < nr_subdirs) {
const size_t sdi = floppy->dirs.ptr[di].subdirs.ptr[i];
- assert (sdi < floppy->dirs.size);
+ assert (sdi < floppy->dirs.len);
first_cluster = floppy->dirs.ptr[sdi].first_cluster;
}
else if (i < nr_subdirs + nr_files) {
const size_t fi = floppy->dirs.ptr[di].fileidxs.ptr[i-nr_subdirs];
- assert (fi < floppy->files.size);
+ assert (fi < floppy->files.len);
first_cluster = floppy->files.ptr[fi].first_cluster;
}
else
diff --git a/plugins/floppy/floppy.c b/plugins/floppy/floppy.c
index 80f350af..938f5bec 100644
--- a/plugins/floppy/floppy.c
+++ b/plugins/floppy/floppy.c
@@ -172,7 +172,7 @@ floppy_pread (void *handle, void *buf, uint32_t count, uint64_t offset)
switch (region->type) {
case region_file:
i = region->u.i;
- assert (i < floppy.files.size);
+ assert (i < floppy.files.len);
host_path = floppy.files.ptr[i].host_path;
fd = open (host_path, O_RDONLY|O_CLOEXEC);
if (fd == -1) {
diff --git a/plugins/floppy/virtual-floppy.c b/plugins/floppy/virtual-floppy.c
index 6eae5600..b1546bd5 100644
--- a/plugins/floppy/virtual-floppy.c
+++ b/plugins/floppy/virtual-floppy.c
@@ -97,10 +97,10 @@ create_virtual_floppy (const char *dir, const char *label, uint64_t size,
return -1;
nbdkit_debug ("floppy: %zu directories and %zu files",
- floppy->dirs.size, floppy->files.size);
+ floppy->dirs.len, floppy->files.len);
/* Create the on disk directory tables. */
- for (i = 0; i < floppy->dirs.size; ++i) {
+ for (i = 0; i < floppy->dirs.len; ++i) {
if (create_directory (i, label, floppy) == -1)
return -1;
}
@@ -115,10 +115,10 @@ create_virtual_floppy (const char *dir, const char *label, uint64_t size,
*/
data_used_size = 0;
cluster = 2;
- for (i = 0; i < floppy->dirs.size; ++i) {
+ for (i = 0; i < floppy->dirs.len; ++i) {
floppy->dirs.ptr[i].first_cluster = cluster;
nr_bytes =
- ROUND_UP (floppy->dirs.ptr[i].table.size * sizeof (struct dir_entry),
+ ROUND_UP (floppy->dirs.ptr[i].table.len * sizeof (struct dir_entry),
CLUSTER_SIZE);
data_used_size += nr_bytes;
nr_clusters = nr_bytes / CLUSTER_SIZE;
@@ -127,7 +127,7 @@ create_virtual_floppy (const char *dir, const char *label, uint64_t size,
floppy->dirs.ptr[i].nr_clusters = nr_clusters;
cluster += nr_clusters;
}
- for (i = 0; i < floppy->files.size; ++i) {
+ for (i = 0; i < floppy->files.len; ++i) {
floppy->files.ptr[i].first_cluster = cluster;
nr_bytes = ROUND_UP (floppy->files.ptr[i].statbuf.st_size, CLUSTER_SIZE);
data_used_size += nr_bytes;
@@ -187,7 +187,7 @@ create_virtual_floppy (const char *dir, const char *label, uint64_t size,
* directory entries (which we didn't have available during
* create_directory above).
*/
- for (i = 0; i < floppy->dirs.size; ++i) {
+ for (i = 0; i < floppy->dirs.len; ++i) {
if (update_directory_first_cluster (i, floppy) == -1)
return -1;
}
@@ -230,13 +230,13 @@ free_virtual_floppy (struct virtual_floppy *floppy)
free (floppy->fat);
- for (i = 0; i < floppy->files.size; ++i) {
+ for (i = 0; i < floppy->files.len; ++i) {
free (floppy->files.ptr[i].name);
free (floppy->files.ptr[i].host_path);
}
free (floppy->files.ptr);
- for (i = 0; i < floppy->dirs.size; ++i) {
+ for (i = 0; i < floppy->dirs.len; ++i) {
free (floppy->dirs.ptr[i].name);
free (floppy->dirs.ptr[i].subdirs.ptr);
free (floppy->dirs.ptr[i].fileidxs.ptr);
@@ -266,7 +266,7 @@ visit (const char *dir, struct virtual_floppy *floppy)
* directory will always be at dirs[0].
*/
memset (&null_dir, 0, sizeof null_dir);
- di = floppy->dirs.size;
+ di = floppy->dirs.len;
if (dirs_append (&floppy->dirs, null_dir) == -1) {
nbdkit_error ("realloc: %m");
goto error0;
@@ -423,7 +423,7 @@ visit_file (const char *dir, const char *name,
}
new_file.host_path = host_path;
new_file.statbuf = *statbuf;
- fi = floppy->files.size;
+ fi = floppy->files.len;
if (files_append (&floppy->files, new_file) == -1) {
nbdkit_error ("realloc: %m");
free (host_path);
@@ -574,11 +574,11 @@ create_fat (struct virtual_floppy *floppy)
floppy->fat[0] = htole32 (0x0ffffff8);
floppy->fat[1] = htole32 (0x0fffffff);
- for (i = 0; i < floppy->dirs.size; ++i) {
+ for (i = 0; i < floppy->dirs.len; ++i) {
write_fat_file (floppy->dirs.ptr[i].first_cluster,
floppy->dirs.ptr[i].nr_clusters, floppy);
}
- for (i = 0; i < floppy->files.size; ++i) {
+ for (i = 0; i < floppy->files.len; ++i) {
write_fat_file (floppy->files.ptr[i].first_cluster,
floppy->files.ptr[i].nr_clusters, floppy);
}
@@ -676,15 +676,15 @@ create_regions (struct virtual_floppy *floppy)
/* Now we're into the data region. We add all directory tables
* first.
*/
- for (i = 0; i < floppy->dirs.size; ++i) {
+ for (i = 0; i < floppy->dirs.len; ++i) {
/* Directories can never be completely empty because of the volume
* label (root) or "." and ".." entries (non-root).
*/
- assert (floppy->dirs.ptr[i].table.size > 0);
+ assert (floppy->dirs.ptr[i].table.len > 0);
if (append_region_len (&floppy->regions,
i == 0 ? "root directory" : floppy->dirs.ptr[i].name,
- floppy->dirs.ptr[i].table.size *
+ floppy->dirs.ptr[i].table.len *
sizeof (struct dir_entry),
0, CLUSTER_SIZE,
region_data,
@@ -693,7 +693,7 @@ create_regions (struct virtual_floppy *floppy)
}
/* Add all files. */
- for (i = 0; i < floppy->files.size; ++i) {
+ for (i = 0; i < floppy->files.len; ++i) {
/* It's possible for a file to have zero size, in which case it
* doesn't occupy a region or cluster.
*/
diff --git a/plugins/iso/iso.c b/plugins/iso/iso.c
index cb621f41..e232175f 100644
--- a/plugins/iso/iso.c
+++ b/plugins/iso/iso.c
@@ -105,7 +105,7 @@ make_iso (void)
fprintf (fp, " -quiet");
if (params)
fprintf (fp, " %s", params);
- for (i = 0; i < dirs.size; ++i) {
+ for (i = 0; i < dirs.len; ++i) {
fputc (' ', fp);
shell_quote (dirs.ptr[i], fp);
}
@@ -169,7 +169,7 @@ iso_config (const char *key, const char *value)
static int
iso_config_complete (void)
{
- if (dirs.size == 0) {
+ if (dirs.len == 0) {
nbdkit_error ("you must supply the dir=<DIRECTORY> parameter "
"after the plugin name on the command line");
return -1;
diff --git a/plugins/nbd/nbd.c b/plugins/nbd/nbd.c
index 488eadb2..ae595ea7 100644
--- a/plugins/nbd/nbd.c
+++ b/plugins/nbd/nbd.c
@@ -244,7 +244,7 @@ static int
nbdplug_config_complete (void)
{
int c = !!sockname + !!hostname + !!uri +
- (command.size > 0) + (socket_fd >= 0) + !!raw_cid;
+ (command.len > 0) + (socket_fd >= 0) + !!raw_cid;
/* Check the user passed exactly one connection parameter. */
if (c > 1) {
@@ -303,7 +303,7 @@ nbdplug_config_complete (void)
return -1;
#endif
}
- else if (command.size > 0) {
+ else if (command.len > 0) {
/* Add NULL sentinel to the command. */
if (string_vector_append (&command, NULL) == -1) {
nbdkit_error ("realloc: %m");
@@ -574,7 +574,7 @@ nbdplug_connect (struct nbd_handle *nbd)
#else
return nbd_connect_vsock (nbd, cid, vport);
#endif
- else if (command.size > 0)
+ else if (command.len > 0)
return nbd_connect_systemd_socket_activation (nbd, (char **) command.ptr);
else if (socket_fd >= 0)
return nbd_connect_socket (nbd, socket_fd);
diff --git a/plugins/partitioning/partition-mbr.c b/plugins/partitioning/partition-mbr.c
index 9a1a043c..1f178dcb 100644
--- a/plugins/partitioning/partition-mbr.c
+++ b/plugins/partitioning/partition-mbr.c
@@ -62,9 +62,9 @@ create_mbr_layout (void)
primary[0x1fe] = 0x55;
primary[0x1ff] = 0xaa;
- if (the_files.size <= 4) {
+ if (the_files.len <= 4) {
/* Basic MBR with no extended partition. */
- for (i = 0; i < the_files.size; ++i) {
+ for (i = 0; i < the_files.len; ++i) {
const struct region *region = find_file_region (i, &j);
create_mbr_partition_table_entry (region, i == 0, the_files.ptr[i].mbr_id,
@@ -97,7 +97,7 @@ create_mbr_layout (void)
/* The remaining files are mapped to logical partitions living in
* the fourth extended partition.
*/
- for (i = 3; i < the_files.size; ++i) {
+ for (i = 3; i < the_files.len; ++i) {
if (i == 3)
eptr = eptr0;
else
@@ -117,7 +117,7 @@ create_mbr_layout (void)
create_mbr_partition_table_entry (&region, false, the_files.ptr[i].mbr_id,
&ebr[i-3][0x1be]);
- if (i < the_files.size-1) {
+ if (i < the_files.len-1) {
size_t j2 = j;
const struct region *enext = find_ebr_region (i+1, &j2);
const struct region *rnext = find_file_region (i+1, &j2);
diff --git a/plugins/partitioning/partitioning.c b/plugins/partitioning/partitioning.c
index 231b2d77..2301ba4e 100644
--- a/plugins/partitioning/partitioning.c
+++ b/plugins/partitioning/partitioning.c
@@ -104,7 +104,7 @@ partitioning_unload (void)
{
size_t i;
- for (i = 0; i < the_files.size; ++i)
+ for (i = 0; i < the_files.len; ++i)
close (the_files.ptr[i].fd);
free (the_files.ptr);
@@ -116,7 +116,7 @@ partitioning_unload (void)
free (primary);
free (secondary);
if (ebr) {
- for (i = 0; i < the_files.size-3; ++i)
+ for (i = 0; i < the_files.len-3; ++i)
free (ebr[i]);
free (ebr);
}
@@ -235,19 +235,19 @@ partitioning_config_complete (void)
bool needs_gpt;
/* Not enough / too many files? */
- if (the_files.size == 0) {
+ if (the_files.len == 0) {
nbdkit_error ("at least one file= parameter must be supplied");
return -1;
}
total_size = 0;
- for (i = 0; i < the_files.size; ++i)
+ for (i = 0; i < the_files.len; ++i)
total_size += the_files.ptr[i].statbuf.st_size;
needs_gpt = total_size > MAX_MBR_DISK_SIZE;
/* Choose default parttype if not set. */
if (parttype == PARTTYPE_UNSET) {
- if (needs_gpt || the_files.size > 4) {
+ if (needs_gpt || the_files.len > 4) {
parttype = PARTTYPE_GPT;
nbdkit_debug ("picking partition type GPT");
}
@@ -262,7 +262,7 @@ partitioning_config_complete (void)
"but you requested %zu partition(s) "
"and a total size of %" PRIu64 " bytes (> %" PRIu64 "). "
"Try using: partition-type=gpt",
- the_files.size, total_size, (uint64_t) MAX_MBR_DISK_SIZE);
+ the_files.len, total_size, (uint64_t) MAX_MBR_DISK_SIZE);
return -1;
}
@@ -327,7 +327,7 @@ partitioning_pread (void *handle, void *buf, uint32_t count, uint64_t offset)
switch (region->type) {
case region_file:
i = region->u.i;
- assert (i < the_files.size);
+ assert (i < the_files.len);
r = pread (the_files.ptr[i].fd, buf, len, offset - region->start);
if (r == -1) {
nbdkit_error ("pread: %s: %m", the_files.ptr[i].filename);
@@ -376,7 +376,7 @@ partitioning_pwrite (void *handle,
switch (region->type) {
case region_file:
i = region->u.i;
- assert (i < the_files.size);
+ assert (i < the_files.len);
r = pwrite (the_files.ptr[i].fd, buf, len, offset - region->start);
if (r == -1) {
nbdkit_error ("pwrite: %s: %m", the_files.ptr[i].filename);
@@ -418,7 +418,7 @@ partitioning_flush (void *handle)
{
size_t i;
- for (i = 0; i < the_files.size; ++i) {
+ for (i = 0; i < the_files.len; ++i) {
if (fdatasync (the_files.ptr[i].fd) == -1) {
nbdkit_error ("fdatasync: %m");
return -1;
diff --git a/plugins/partitioning/virtual-disk.c b/plugins/partitioning/virtual-disk.c
index 389a17b6..d46ca46a 100644
--- a/plugins/partitioning/virtual-disk.c
+++ b/plugins/partitioning/virtual-disk.c
@@ -56,7 +56,7 @@ create_virtual_disk_layout (void)
size_t i;
assert (nr_regions (&the_regions) == 0);
- assert (the_files.size > 0);
+ assert (the_files.len > 0);
assert (primary == NULL);
assert (secondary == NULL);
@@ -68,17 +68,17 @@ create_virtual_disk_layout (void)
return -1;
}
- if (the_files.size > 4) {
+ if (the_files.len > 4) {
/* The first 3 primary partitions will be real partitions, the
* 4th will be an extended partition, and so we need to store
* EBRs for the_files.size-3 logical partitions.
*/
- ebr = malloc (sizeof (unsigned char *) * (the_files.size-3));
+ ebr = malloc (sizeof (unsigned char *) * (the_files.len-3));
if (ebr == NULL) {
nbdkit_error ("malloc: %m");
return -1;
}
- for (i = 0; i < the_files.size-3; ++i) {
+ for (i = 0; i < the_files.len-3; ++i) {
ebr[i] = calloc (1, SECTOR_SIZE);
if (ebr[i] == NULL) {
nbdkit_error ("malloc: %m");
@@ -117,7 +117,7 @@ create_virtual_disk_layout (void)
}
/* The partitions. */
- for (i = 0; i < the_files.size; ++i) {
+ for (i = 0; i < the_files.len; ++i) {
uint64_t offset;
offset = virtual_size (&the_regions);
@@ -127,7 +127,7 @@ create_virtual_disk_layout (void)
assert (IS_ALIGNED (offset, SECTOR_SIZE));
/* Logical partitions are preceeded by an EBR. */
- if (parttype == PARTTYPE_MBR && the_files.size > 4 && i >= 3) {
+ if (parttype == PARTTYPE_MBR && the_files.len > 4 && i >= 3) {
if (append_region_len (&the_regions, "EBR",
SECTOR_SIZE, 0, 0,
region_data, ebr[i-3]) == -1)
diff --git a/plugins/partitioning/virtual-disk.h b/plugins/partitioning/virtual-disk.h
index 7032dfc8..d56c2b86 100644
--- a/plugins/partitioning/virtual-disk.h
+++ b/plugins/partitioning/virtual-disk.h
@@ -55,7 +55,7 @@
* 32 if the number of files is <= GPT_MIN_PARTITIONS, which is the
* normal case.
*/
-#define GPT_PTA_SIZE ROUND_UP (the_files.size, GPT_MIN_PARTITIONS)
+#define GPT_PTA_SIZE ROUND_UP (the_files.len, GPT_MIN_PARTITIONS)
#define GPT_PTA_LBAs (GPT_PTA_SIZE * GPT_PT_ENTRY_SIZE / SECTOR_SIZE)
/* Maximum possible and default alignment between partitions. */
diff --git a/plugins/split/split.c b/plugins/split/split.c
index c559a0cd..4c9790a6 100644
--- a/plugins/split/split.c
+++ b/plugins/split/split.c
@@ -121,13 +121,13 @@ split_open (int readonly)
return NULL;
}
- h->files = malloc (filenames.size * sizeof (struct file));
+ h->files = malloc (filenames.len * sizeof (struct file));
if (h->files == NULL) {
nbdkit_error ("malloc: %m");
free (h);
return NULL;
}
- for (i = 0; i < filenames.size; ++i)
+ for (i = 0; i < filenames.len; ++i)
h->files[i].fd = -1;
/* Open the files. */
@@ -137,7 +137,7 @@ split_open (int readonly)
else
flags |= O_RDWR;
- for (i = 0; i < filenames.size; ++i) {
+ for (i = 0; i < filenames.len; ++i) {
h->files[i].fd = open (filenames.ptr[i], flags);
if (h->files[i].fd == -1) {
nbdkit_error ("open: %s: %m", filenames.ptr[i]);
@@ -146,7 +146,7 @@ split_open (int readonly)
}
offset = 0;
- for (i = 0; i < filenames.size; ++i) {
+ for (i = 0; i < filenames.len; ++i) {
h->files[i].offset = offset;
if (fstat (h->files[i].fd, &statbuf) == -1) {
@@ -179,7 +179,7 @@ split_open (int readonly)
return h;
err:
- for (i = 0; i < filenames.size; ++i) {
+ for (i = 0; i < filenames.len; ++i) {
if (h->files[i].fd >= 0)
close (h->files[i].fd);
}
@@ -195,7 +195,7 @@ split_close (void *handle)
struct handle *h = handle;
size_t i;
- for (i = 0; i < filenames.size; ++i)
+ for (i = 0; i < filenames.len; ++i)
close (h->files[i].fd);
free (h->files);
free (h);
@@ -242,7 +242,7 @@ static struct file *
get_file (struct handle *h, uint64_t offset)
{
return bsearch (&offset, h->files,
- filenames.size, sizeof (struct file),
+ filenames.len, sizeof (struct file),
compare_offset);
}
diff --git a/plugins/ssh/ssh.c b/plugins/ssh/ssh.c
index 535caf1a..80623525 100644
--- a/plugins/ssh/ssh.c
+++ b/plugins/ssh/ssh.c
@@ -397,7 +397,7 @@ ssh_open (int readonly)
* as this file is rarely present.
*/
}
- for (i = 0; i < identities.size; ++i) {
+ for (i = 0; i < identities.len; ++i) {
r = ssh_options_set (h->session,
SSH_OPTIONS_ADD_IDENTITY, identities.ptr[i]);
if (r != SSH_OK) {
diff --git a/plugins/vddk/reexec.c b/plugins/vddk/reexec.c
index 9e87025e..4eae2221 100644
--- a/plugins/vddk/reexec.c
+++ b/plugins/vddk/reexec.c
@@ -116,20 +116,20 @@ perform_reexec (const char *env, const char *prepend)
nbdkit_error ("realloc: %m");
exit (EXIT_FAILURE);
}
- r = read (fd, buf.ptr + buf.size, buf.cap - buf.size);
+ r = read (fd, buf.ptr + buf.len, buf.cap - buf.len);
if (r == -1) {
nbdkit_error ("read: %s: %m", cmdline_file);
exit (EXIT_FAILURE);
}
if (r == 0)
break;
- buf.size += r;
+ buf.len += r;
}
close (fd);
- nbdkit_debug ("original command line occupies %zu bytes", buf.size);
+ nbdkit_debug ("original command line occupies %zu bytes", buf.len);
/* Split cmdline into argv, then append one more arg. */
- for (len = 0; len < buf.size; len += strlen (buf.ptr + len) + 1) {
+ for (len = 0; len < buf.len; len += strlen (buf.ptr + len) + 1) {
char *arg = buf.ptr + len; /* Next \0-terminated argument. */
/* See below for why we eat password parameter(s). */
diff --git a/plugins/vddk/stats.c b/plugins/vddk/stats.c
index 76e0c244..bb5401b1 100644
--- a/plugins/vddk/stats.c
+++ b/plugins/vddk/stats.c
@@ -94,12 +94,12 @@ display_stats (void)
#undef STUB
#undef OPTIONAL_STUB
- qsort (stats.ptr, stats.size, sizeof stats.ptr[0], stat_compare);
+ qsort (stats.ptr, stats.len, sizeof stats.ptr[0], stat_compare);
nbdkit_debug ("VDDK function stats (-D vddk.stats=1):");
nbdkit_debug ("%-24s %15s %5s %15s",
"VixDiskLib_...", "µs", "calls", "bytes");
- for (i = 0; i < stats.size; ++i) {
+ for (i = 0; i < stats.len; ++i) {
if (stats.ptr[i].usecs) {
if (stats.ptr[i].bytes > 0)
nbdkit_debug (" %-22s %15" PRIi64 " %5" PRIu64 " %15" PRIu64,
diff --git a/plugins/vddk/worker.c b/plugins/vddk/worker.c
index 2a1d4f26..c6e2fd22 100644
--- a/plugins/vddk/worker.c
+++ b/plugins/vddk/worker.c
@@ -82,7 +82,7 @@ send_command_and_wait (struct vddk_handle *h, struct command *cmd)
return -1;
/* Signal the caller if it could be sleeping on an empty queue. */
- if (h->commands.size == 1)
+ if (h->commands.len == 1)
pthread_cond_signal (&h->commands_cond);
/* This will be used to signal command completion back to us. */
@@ -497,7 +497,7 @@ vddk_worker_thread (void *handle)
/* Wait until we are sent at least one command. */
{
ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&h->commands_lock);
- while (h->commands.size == 0)
+ while (h->commands.len == 0)
pthread_cond_wait (&h->commands_cond, &h->commands_lock);
cmd = h->commands.ptr[0];
command_queue_remove (&h->commands, 0);
diff --git a/server/exports.c b/server/exports.c
index 7ce1eda9..12c8a879 100644
--- a/server/exports.c
+++ b/server/exports.c
@@ -90,13 +90,13 @@ nbdkit_exports_free (struct nbdkit_exports *exps)
NBDKIT_DLL_PUBLIC size_t
nbdkit_exports_count (const struct nbdkit_exports *exps)
{
- return exps->exports.size;
+ return exps->exports.len;
}
NBDKIT_DLL_PUBLIC const struct nbdkit_export
nbdkit_get_export (const struct nbdkit_exports *exps, size_t i)
{
- assert (i < exps->exports.size);
+ assert (i < exps->exports.len);
return exps->exports.ptr[i];
}
@@ -106,7 +106,7 @@ nbdkit_add_export (struct nbdkit_exports *exps,
{
struct nbdkit_export e = { NULL, NULL };
- if (exps->exports.size == MAX_EXPORTS) {
+ if (exps->exports.len == MAX_EXPORTS) {
nbdkit_error ("nbdkit_add_export: too many exports");
errno = EINVAL;
return -1;
diff --git a/server/extents.c b/server/extents.c
index 8da82cf1..e180e313 100644
--- a/server/extents.c
+++ b/server/extents.c
@@ -117,13 +117,13 @@ nbdkit_extents_free (struct nbdkit_extents *exts)
NBDKIT_DLL_PUBLIC size_t
nbdkit_extents_count (const struct nbdkit_extents *exts)
{
- return exts->extents.size;
+ return exts->extents.len;
}
NBDKIT_DLL_PUBLIC struct nbdkit_extent
nbdkit_get_extent (const struct nbdkit_extents *exts, size_t i)
{
- assert (i < exts->extents.size);
+ assert (i < exts->extents.len);
return exts->extents.ptr[i];
}
@@ -160,7 +160,7 @@ nbdkit_add_extent (struct nbdkit_extents *exts,
return 0;
/* Ignore extents beyond the end of the range, or if list is full. */
- if (offset >= exts->end || exts->extents.size >= MAX_EXTENTS)
+ if (offset >= exts->end || exts->extents.len >= MAX_EXTENTS)
return 0;
/* Shorten extents that overlap the end of the range. */
@@ -169,7 +169,7 @@ nbdkit_add_extent (struct nbdkit_extents *exts,
length -= overlap;
}
- if (exts->extents.size == 0) {
+ if (exts->extents.len == 0) {
/* If there are no existing extents, and the new extent is
* entirely before start, ignore it.
*/
@@ -196,10 +196,10 @@ nbdkit_add_extent (struct nbdkit_extents *exts,
}
/* If we get here we are going to either add or extend. */
- if (exts->extents.size > 0 &&
- exts->extents.ptr[exts->extents.size-1].type == type) {
+ if (exts->extents.len > 0 &&
+ exts->extents.ptr[exts->extents.len-1].type == type) {
/* Coalesce with the last extent. */
- exts->extents.ptr[exts->extents.size-1].length += length;
+ exts->extents.ptr[exts->extents.len-1].length += length;
return 0;
}
else {
@@ -226,13 +226,13 @@ nbdkit_extents_aligned (struct context *next_c,
/* Perform an initial query, then scan for the first unaligned extent. */
if (next->extents (next_c, count, offset, flags, exts, err) == -1)
return -1;
- for (i = 0; i < exts->extents.size; ++i) {
+ for (i = 0; i < exts->extents.len; ++i) {
e = &exts->extents.ptr[i];
if (!IS_ALIGNED(e->length, align)) {
/* If the unalignment is past align, just truncate and return early */
if (e->offset + e->length > offset + align) {
e->length = ROUND_DOWN (e->length, align);
- exts->extents.size = i + !!e->length;
+ exts->extents.len = i + !!e->length;
exts->next = e->offset + e->length;
break;
}
@@ -249,7 +249,7 @@ nbdkit_extents_aligned (struct context *next_c,
*/
assert (i == 0);
while (e->length < align) {
- if (exts->extents.size > 1) {
+ if (exts->extents.len > 1) {
e->length += exts->extents.ptr[1].length;
e->type &= exts->extents.ptr[1].type;
extents_remove (&exts->extents, 1);
@@ -284,7 +284,7 @@ nbdkit_extents_aligned (struct context *next_c,
}
}
e->length = align;
- exts->extents.size = 1;
+ exts->extents.len = 1;
exts->next = e->offset + e->length;
break;
}
diff --git a/server/main.c b/server/main.c
index 5fd8308f..225258de 100644
--- a/server/main.c
+++ b/server/main.c
@@ -940,7 +940,7 @@ start_serving (void)
r = sockets_append (&socks, s);
assert (r == 0);
}
- debug ("using socket activation, nr_socks = %zu", socks.size);
+ debug ("using socket activation, nr_socks = %zu", socks.len);
change_user ();
write_pidfile ();
top->after_fork (top);
diff --git a/server/sockets.c b/server/sockets.c
index 18b68f0a..15a26f69 100644
--- a/server/sockets.c
+++ b/server/sockets.c
@@ -246,14 +246,14 @@ bind_tcpip_socket (sockets *socks)
freeaddrinfo (ai);
- if (socks->size == 0 && addr_in_use) {
+ if (socks->len == 0 && addr_in_use) {
fprintf (stderr, "%s: unable to bind to any sockets: %s\n",
program_name, strerror (EADDRINUSE));
exit (EXIT_FAILURE);
}
debug ("bound to IP address %s:%s (%zu socket(s))",
- ipaddr ? ipaddr : "<any>", port, socks->size);
+ ipaddr ? ipaddr : "<any>", port, socks->len);
}
void
@@ -443,7 +443,7 @@ accept_connection (int listen_sock)
static void
check_sockets_and_quit_fd (const sockets *socks)
{
- const size_t nr_socks = socks->size;
+ const size_t nr_socks = socks->len;
size_t i;
int r;
@@ -552,7 +552,7 @@ accept_incoming_connections (const sockets *socks)
}
pthread_mutex_unlock (&count_mutex);
- for (i = 0; i < socks->size; ++i)
+ for (i = 0; i < socks->len; ++i)
closesocket (socks->ptr[i]);
free (socks->ptr);
}
diff --git a/wrapper.c b/wrapper.c
index 3bab2074..87e5a033 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -130,9 +130,9 @@ print_command (void)
{
size_t i;
- if (cmd.size > 0)
+ if (cmd.len > 0)
shell_quote (cmd.ptr[0], stderr);
- for (i = 1; i < cmd.size && cmd.ptr[i] != NULL; ++i) {
+ for (i = 1; i < cmd.len && cmd.ptr[i] != NULL; ++i) {
fputc (' ', stderr);
shell_quote (cmd.ptr[i], stderr);
}
--
2.31.1