Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 00/17] wrap source code at 80 chars
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 This series wraps the *C-language* *.[ch] source files at 80 characters, as much as possible. Some lines are impossible to wrap: those are URLs. Considering files that contain such lines (URLs), we can form two classes: - in the first class of files, we still wrap some other lines, so those files are modified by this patch series, and the corresponding commit messages highlight the fact that the total widths of the affected source files remain above 80 characters; - in the second class of files, there is nothing else to wrap, so I'm listing those files only here: common/replacements/poll.c common/utils/utils.c filters/luks/luks-encryption.h plugins/file/winfile.c wrapper.c "It was painful to write and test, it should be painful to review (TM)" ?\_(?)_/? Cc: Nolan Leake <nolan at sigbus.net> Thanks! Laszlo Laszlo Ersek (17): common/utils/utils.h: wrap source code at 80 chars common/utils/windows-compat.h: wrap source code at 80 chars filters/cache: wrap source code at 80 chars filters/exportname: wrap source code at 80 chars filters/ext2: wrap source code at 80 chars filters/extentlist: wrap source code at 80 chars filters/noparallel: wrap source code at 80 chars filters/nozero: wrap source code at 80 chars filters/partition: wrap source code at 80 chars include/nbdkit-plugin.h: wrap source code at 80 chars plugins/floppy: wrap source code at 80 chars plugins/nbd: wrap source code at 80 chars plugins/perl: wrap source code at 80 chars plugins/ruby: wrap source code at 80 chars plugins/sh: wrap source code at 80 chars plugins/vddk: wrap source code at 80 chars server: wrap source code at 80 chars common/utils/utils.h | 3 +- common/utils/windows-compat.h | 11 +++--- filters/cache/cache.c | 3 +- filters/exportname/exportname.c | 17 ++++---- filters/ext2/ext2.c | 6 +-- filters/extentlist/extentlist.c | 13 ++++--- filters/noparallel/noparallel.c | 5 ++- filters/nozero/nozero.c | 5 ++- filters/partition/partition.c | 3 +- include/nbdkit-plugin.h | 3 +- plugins/floppy/directory-lfn.c | 13 +++++-- plugins/floppy/virtual-floppy.c | 19 ++++++--- plugins/nbd/nbd.c | 41 +++++++++++--------- plugins/perl/perl.c | 2 +- plugins/ruby/ruby.c | 3 +- plugins/sh/call.c | 2 +- plugins/vddk/vddk.c | 12 ++++-- server/filters.c | 2 +- server/internal.h | 7 +++- server/main.c | 6 ++- server/plugins.c | 2 +- 21 files changed, 108 insertions(+), 70 deletions(-) base-commit: 50f87e4995906bbcd00014932d1837ed16131b8e
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 01/17] common/utils/utils.h: wrap source code at 80 chars
Wrap the source code at 80 characters. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- common/utils/utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/utils/utils.h b/common/utils/utils.h index 31ae73f71d66..42288a5cd422 100644 --- a/common/utils/utils.h +++ b/common/utils/utils.h @@ -41,6 +41,7 @@ extern int set_nonblock (int fd); extern char **copy_environ (char **env, ...) __attribute__ ((__sentinel__)); extern char *make_temporary_directory (void); extern ssize_t full_pread (int fd, void *buf, size_t count, off_t offset); -extern ssize_t full_pwrite (int fd, const void *buf, size_t count, off_t offset); +extern ssize_t full_pwrite (int fd, const void *buf, size_t count, + off_t offset); #endif /* NBDKIT_UTILS_H */
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 02/17] common/utils/windows-compat.h: wrap source code at 80 chars
Wrap the source code at 80 characters. Align the backslashes in NOT_IMPLEMENTED_ON_WINDOWS(). Note: I can't even build-test this. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- common/utils/windows-compat.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/utils/windows-compat.h b/common/utils/windows-compat.h index c334256e3952..1111a1b5f4fc 100644 --- a/common/utils/windows-compat.h +++ b/common/utils/windows-compat.h @@ -132,12 +132,13 @@ extern int win_send (int fd, const void *buf, size_t len, int flags); * Note: Don't use this for things which can never work on Windows * (eg. Unix socket support). Those should just give regular errors. */ -#define NOT_IMPLEMENTED_ON_WINDOWS(feature) \ - do { \ +#define NOT_IMPLEMENTED_ON_WINDOWS(feature) \ + do { \ fprintf (stderr, "nbdkit: %s is not implemented for Windows.\n", feature); \ - fprintf (stderr, "You can help by contributing to the Windows port, see\n"); \ - fprintf (stderr, "nbdkit README in the source for how to contribute.\n"); \ - exit (EXIT_FAILURE); \ + fprintf (stderr, "You can help by contributing to the Windows port,\n"); \ + fprintf (stderr, "see nbdkit README in the source for how to\n"); \ + fprintf (stderr, "contribute.\n"); \ + exit (EXIT_FAILURE); \ } while (0) #else /* !WIN32 */
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 03/17] filters/cache: wrap source code at 80 chars
Wrap the source code at 80 characters. Tested with: $ nbdkit null --filter=cache cache-min-block-size=3> nbdkit: error: cache-min-block-size is not a power of 2, or is too small or too largeBugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- filters/cache/cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/filters/cache/cache.c b/filters/cache/cache.c index c379f1005754..b5486060b812 100644 --- a/filters/cache/cache.c +++ b/filters/cache/cache.c @@ -119,7 +119,8 @@ cache_config (nbdkit_next_config *next, nbdkit_backend *nxdata, if (r == -1) return -1; if (r < 4096 || !is_power_of_2 (r) || r > UINT_MAX) { - nbdkit_error ("cache-min-block-size is not a power of 2, or is too small or too large"); + nbdkit_error ("cache-min-block-size is not a power of 2, or is too small " + "or too large"); return -1; } min_block_size = r;
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 04/17] filters/exportname: wrap source code at 80 chars
Wrap the source code at 80 characters. Align the backslashes in "exportname_config_help". Tested with: $ nbdkit null --filter=exportname --help> [...] > default-export=<NAME> Canonical name for the "" default export. > exportname-list=<MODE> Which exports to advertise: keep (default), > error, empty, defaultonly, explicit. > exportname-strict=<BOOL> Limit clients to explicit exports (default > false). > exportname=<NAME> Add an explicit export name, may be > repeated. > exportdesc=<MODE> Set descriptions according to mode: keep > (default), none, fixed:STRING, > script:SCRIPT. > [...]Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- filters/exportname/exportname.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/filters/exportname/exportname.c b/filters/exportname/exportname.c index 4949de398d66..7e0d4c171d25 100644 --- a/filters/exportname/exportname.c +++ b/filters/exportname/exportname.c @@ -141,14 +141,17 @@ exportname_config (nbdkit_next_config *next, nbdkit_backend *nxdata, return next (nxdata, key, value); } -#define exportname_config_help \ +#define exportname_config_help \ "default-export=<NAME> Canonical name for the \"\" default export.\n" \ - "exportname-list=<MODE> Which exports to advertise: keep (default), error,\n" \ - " empty, defaultonly, explicit.\n" \ - "exportname-strict=<BOOL> Limit clients to explicit exports (default false).\n" \ - "exportname=<NAME> Add an explicit export name, may be repeated.\n" \ - "exportdesc=<MODE> Set descriptions according to mode: keep (default),\n" \ - " none, fixed:STRING, script:SCRIPT.\n" \ + "exportname-list=<MODE> Which exports to advertise: keep (default),\n" \ + " error, empty, defaultonly, explicit.\n" \ + "exportname-strict=<BOOL> Limit clients to explicit exports (default\n" \ + " false).\n" \ + "exportname=<NAME> Add an explicit export name, may be\n" \ + " repeated.\n" \ + "exportdesc=<MODE> Set descriptions according to mode: keep\n" \ + " (default), none, fixed:STRING,\n" \ + " script:SCRIPT.\n" \ static const char * get_desc (const char *name, const char *def)
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 05/17] filters/ext2: wrap source code at 80 chars
Wrap the source code at 80 characters. Align the backslashes in "ext2_config_help". Tested with: $ nbdkit null --filter=ext2 --help> [...] > ext2file=<FILENAME> (required) Absolute name of file to serve inside > the disk image, or 'exportname' for client choice. > [...]Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- filters/ext2/ext2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/filters/ext2/ext2.c b/filters/ext2/ext2.c index f9858ca40d15..cff5dad789d8 100644 --- a/filters/ext2/ext2.c +++ b/filters/ext2/ext2.c @@ -96,9 +96,9 @@ ext2_config_complete (nbdkit_next_config_complete *next, nbdkit_backend *nxdata) return next (nxdata); } -#define ext2_config_help \ - "ext2file=<FILENAME> (required) Absolute name of file to serve inside the\n" \ - " disk image, or 'exportname' for client choice." +#define ext2_config_help \ + "ext2file=<FILENAME> (required) Absolute name of file to serve inside\n" \ + " the disk image, or 'exportname' for client choice." /* The per-connection handle. */ struct handle {
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 06/17] filters/extentlist: wrap source code at 80 chars
Wrap the source code at 80 characters. Turn the "struct extent" compound literal into a local variable ("block scope, automatic storage duration object"), keeping the same initializer. Tested with "make check"; "tests/test-extentlist.sh" passes. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- filters/extentlist/extentlist.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/filters/extentlist/extentlist.c b/filters/extentlist/extentlist.c index bb5c29d579ef..cc09e2c970d0 100644 --- a/filters/extentlist/extentlist.c +++ b/filters/extentlist/extentlist.c @@ -226,15 +226,16 @@ parse_extentlist (void) */ 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, - (struct extent){.offset = end, - .length = extents.ptr[i+1].offset - end, - .type = HOLE}, - i+1) == -1) { + if (end < extents.ptr[i+1].offset) { + struct extent extent = { .offset = end, + .length = extents.ptr[i+1].offset - end, + .type = HOLE }; + + if (extent_list_insert (&extents, extent, i+1) == -1) { nbdkit_error ("realloc: %m"); exit (EXIT_FAILURE); } + } } /* If there's a gap at the end, insert a hole|zero extent. */
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 07/17] filters/noparallel: wrap source code at 80 chars
Wrap the source code at 80 characters. Align the backslashes in "noparallel_config_help". Tested with: $ nbdkit null --filter=noparallel --help> [...] > serialize=<MODE> 'requests' (default), 'all-requests', or > 'connections'. > [...]Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- filters/noparallel/noparallel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/filters/noparallel/noparallel.c b/filters/noparallel/noparallel.c index 9c871d37aa07..58b3d0a981ff 100644 --- a/filters/noparallel/noparallel.c +++ b/filters/noparallel/noparallel.c @@ -63,8 +63,9 @@ noparallel_config (nbdkit_next_config *next, nbdkit_backend *nxdata, return next (nxdata, key, value); } -#define noparallel_config_help \ - "serialize=<MODE> 'requests' (default), 'all-requests', or 'connections'.\n" \ +#define noparallel_config_help \ + "serialize=<MODE> 'requests' (default), 'all-requests', or\n" \ + " 'connections'.\n" \ /* Apply runtime reduction to thread model. */ static int
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 08/17] filters/nozero: wrap source code at 80 chars
Wrap the source code at 80 characters. Align the backslashes in "nozero_config_help". Tested with: $ nbdkit null --filter=nozero --help> [...] > zeromode=<MODE> One of 'none' (default), 'emulate', 'notrim', > 'plugin'. > fastzeromode=<MODE> One of 'default', 'none', 'slow', 'ignore'. > [...]Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- filters/nozero/nozero.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/filters/nozero/nozero.c b/filters/nozero/nozero.c index 09fd517f76f0..adcfa5a8ff01 100644 --- a/filters/nozero/nozero.c +++ b/filters/nozero/nozero.c @@ -98,8 +98,9 @@ nozero_config (nbdkit_next_config *next, nbdkit_backend *nxdata, return next (nxdata, key, value); } -#define nozero_config_help \ - "zeromode=<MODE> One of 'none' (default), 'emulate', 'notrim', 'plugin'.\n" \ +#define nozero_config_help \ + "zeromode=<MODE> One of 'none' (default), 'emulate', 'notrim',\n" \ + " 'plugin'.\n" \ "fastzeromode=<MODE> One of 'default', 'none', 'slow', 'ignore'.\n" /* Check that desired mode is supported by plugin. */
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 09/17] filters/partition: wrap source code at 80 chars
Wrap the source code at 80 characters. Tested with: $ nbdkit null --filter=partition> nbdkit: error: you must supply the partition parameter on the command lineBugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- filters/partition/partition.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/filters/partition/partition.c b/filters/partition/partition.c index b206f48c8670..c29b14bc327c 100644 --- a/filters/partition/partition.c +++ b/filters/partition/partition.c @@ -72,7 +72,8 @@ partition_config_complete (nbdkit_next_config_complete *next, nbdkit_backend *nxdata) { if (partnum == 0) { - nbdkit_error ("you must supply the partition parameter on the command line"); + nbdkit_error ("you must supply the partition parameter on the command " + "line"); return -1; }
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 10/17] include/nbdkit-plugin.h: wrap source code at 80 chars
Wrap the source code at 80 characters. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- include/nbdkit-plugin.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/nbdkit-plugin.h b/include/nbdkit-plugin.h index 87fa53263949..f09c188ab83f 100644 --- a/include/nbdkit-plugin.h +++ b/include/nbdkit-plugin.h @@ -87,7 +87,8 @@ struct nbdkit_plugin { #if NBDKIT_API_VERSION == 1 int (*pread) (void *handle, void *buf, uint32_t count, uint64_t offset); - int (*pwrite) (void *handle, const void *buf, uint32_t count, uint64_t offset); + int (*pwrite) (void *handle, const void *buf, uint32_t count, + uint64_t offset); int (*flush) (void *handle); int (*trim) (void *handle, uint32_t count, uint64_t offset); int (*zero) (void *handle, uint32_t count, uint64_t offset, int may_trim);
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 11/17] plugins/floppy: wrap source code at 80 chars
Wrap the source code at 80 characters. In the create_virtual_floppy() function, we have a complex calculation that is not really possible to squeeze under 80 characters in width, without extracting part of it to a local variable. The problem is *naming* the new variable, plus the *type* of the new variable. By inspecting the rest of the function, I decided that the expression being extracted, namely DIV_ROUND_UP ((data_size / CLUSTER_SIZE + 2) * 4, CLUSTER_SIZE) should be called "fat_clusters". The rest of the function calculates the same quantity, only in multiple steps; the result is then assigned to "floppy->fat_clusters". Regarding the type of the new local variable: "data_size" is "uint64_t", and everything else in the expression is "int", so the result is "uint64_t" as well, in practice. Shorten the original assignment by using compound assignment, as well. Note that this patch is untested. In "make check", "tests/test-floppy.sh" passes. However, that test does not seem to pass the "size=..." option to the plugin, and the code being modified in create_virtual_floppy() is related to "size=..." -- at least it originates from commit c6d6113fa1f3 ("floppy: support FAT FSes with unused space.", 2021-06-16). Cc: Nolan Leake <nolan at sigbus.net> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- Notes: context:-W plugins/floppy/directory-lfn.c | 13 +++++++++---- plugins/floppy/virtual-floppy.c | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/plugins/floppy/directory-lfn.c b/plugins/floppy/directory-lfn.c index aa9b38bac755..afa5e4cfef36 100644 --- a/plugins/floppy/directory-lfn.c +++ b/plugins/floppy/directory-lfn.c @@ -63,15 +63,20 @@ struct lfn { size_t lfn_size; /* Size *in bytes* of lfn. */ }; -static int add_volume_label (const char *label, size_t di, struct virtual_floppy *floppy); +static int add_volume_label (const char *label, size_t di, + struct virtual_floppy *floppy); static int add_dot_entries (size_t di, struct virtual_floppy *floppy); -static int add_directory_entry (const struct lfn *lfn, uint8_t attributes, uint32_t file_size, struct stat *statbuf, size_t di, struct virtual_floppy *floppy); +static int add_directory_entry (const struct lfn *lfn, uint8_t attributes, + uint32_t file_size, struct stat *statbuf, + size_t di, struct virtual_floppy *floppy); static uint8_t lfn_checksum (const struct lfn *lfn); static void set_times (const struct stat *statbuf, struct dir_entry *entry); static int convert_long_file_names (struct lfn *lfns, size_t n); -static int convert_to_utf16le (const char *name, char **out, size_t *output_len); +static int convert_to_utf16le (const char *name, char **out, + size_t *output_len); static void free_lfns (struct lfn *lfns, size_t n); -static ssize_t append_dir_table (size_t di, const struct dir_entry *entry, struct virtual_floppy *floppy); +static ssize_t append_dir_table (size_t di, const struct dir_entry *entry, + struct virtual_floppy *floppy); /* Create the on disk directory table for dirs[di]. */ int diff --git a/plugins/floppy/virtual-floppy.c b/plugins/floppy/virtual-floppy.c index 2a6871bce6be..6d2f49adb2f0 100644 --- a/plugins/floppy/virtual-floppy.c +++ b/plugins/floppy/virtual-floppy.c @@ -61,14 +61,20 @@ #define OEM_NAME "MSWIN4.1" static ssize_t visit (const char *dir, struct virtual_floppy *floppy); -static int visit_subdirectory (const char *dir, const char *name, const struct stat *statbuf, size_t di, struct virtual_floppy *floppy); -static int visit_file (const char *dir, const char *name, const struct stat *statbuf, size_t di, struct virtual_floppy *floppy); +static int visit_subdirectory (const char *dir, const char *name, + const struct stat *statbuf, size_t di, + struct virtual_floppy *floppy); +static int visit_file (const char *dir, const char *name, + const struct stat *statbuf, size_t di, + struct virtual_floppy *floppy); static int create_mbr (struct virtual_floppy *floppy); static void chs_too_large (uint8_t *out); -static int create_partition_boot_sector (const char *label, struct virtual_floppy *floppy); +static int create_partition_boot_sector (const char *label, + struct virtual_floppy *floppy); static int create_fsinfo (struct virtual_floppy *floppy); static int create_fat (struct virtual_floppy *floppy); -static void write_fat_file (uint32_t first_cluster, uint32_t nr_clusters, struct virtual_floppy *floppy); +static void write_fat_file (uint32_t first_cluster, uint32_t nr_clusters, + struct virtual_floppy *floppy); static int create_regions (struct virtual_floppy *floppy); void @@ -88,135 +94,136 @@ int create_virtual_floppy (const char *dir, const char *label, uint64_t size, struct virtual_floppy *floppy) { size_t i; uint64_t nr_bytes, nr_clusters; uint64_t data_used_size; uint32_t cluster; if (visit (dir, floppy) == -1) return -1; nbdkit_debug ("floppy: %zu directories and %zu files", floppy->dirs.len, floppy->files.len); /* Create the on disk directory tables. */ for (i = 0; i < floppy->dirs.len; ++i) { if (create_directory (i, label, floppy) == -1) return -1; } /* We now have a complete list of directories and files, and * directories have been converted to on disk directory tables. So * we can assign them to clusters and also precisely calculate the * size of the data region and hence the size of the FAT. * * The first cluster number is always 2 (0 and 1 are reserved), and * (in this implementation) always contains the root directory. */ data_used_size = 0; cluster = 2; for (i = 0; i < floppy->dirs.len; ++i) { floppy->dirs.ptr[i].first_cluster = cluster; nr_bytes 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; if (cluster + nr_clusters > UINT32_MAX) goto too_big; floppy->dirs.ptr[i].nr_clusters = nr_clusters; cluster += nr_clusters; } 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; nr_clusters = nr_bytes / CLUSTER_SIZE; if (cluster + nr_clusters > UINT32_MAX) goto too_big; floppy->files.ptr[i].nr_clusters = nr_clusters; cluster += nr_clusters; } if (size > 0) { uint64_t data_size = size - (2080 * SECTOR_SIZE); - data_size = data_size - 2 * DIV_ROUND_UP ((data_size / CLUSTER_SIZE + 2) * 4, - CLUSTER_SIZE) * CLUSTER_SIZE; + uint64_t fat_clusters = DIV_ROUND_UP ((data_size / CLUSTER_SIZE + 2) * 4, + CLUSTER_SIZE); + data_size -= 2 * fat_clusters * CLUSTER_SIZE; if (data_used_size > data_size) { nbdkit_error ("filesystem is larger than \"size\" bytes"); return -1; } floppy->data_size = data_size; } else { floppy->data_size = data_used_size; } floppy->data_clusters = floppy->data_size / CLUSTER_SIZE; floppy->data_used_clusters = data_used_size / CLUSTER_SIZE; /* Despite its name, FAT32 only allows 28 bit cluster numbers, so * give an error if we go beyond this. */ if (floppy->data_clusters >= 0x10000000) { too_big: nbdkit_error ("disk image is too large for the FAT32 disk format"); return -1; } nbdkit_debug ("floppy: %" PRIu64 " data clusters, " "largest cluster number %" PRIu32 ", " "%" PRIu64 " bytes", floppy->data_clusters, cluster-1, floppy->data_size); floppy->fat_entries = floppy->data_clusters + 2; floppy->fat_clusters = DIV_ROUND_UP (floppy->fat_entries * 4, CLUSTER_SIZE); nbdkit_debug ("floppy: %" PRIu64 " FAT entries", floppy->fat_entries); /* We can now decide where we will place the FATs and data region on disk. */ floppy->fat2_start_sector 2080 + floppy->fat_clusters * SECTORS_PER_CLUSTER; floppy->data_start_sector floppy->fat2_start_sector + floppy->fat_clusters * SECTORS_PER_CLUSTER; floppy->data_last_sector floppy->data_start_sector + floppy->data_clusters * SECTORS_PER_CLUSTER - 1; /* We now have to go back and update the cluster numbers in the * directory entries (which we didn't have available during * create_directory above). */ for (i = 0; i < floppy->dirs.len; ++i) { if (update_directory_first_cluster (i, floppy) == -1) return -1; } /* Create MBR. */ if (create_mbr (floppy) == -1) return -1; /* Create partition first sector. */ if (create_partition_boot_sector (label, floppy) == -1) return -1; /* Create filesystem information sector. */ if (create_fsinfo (floppy) == -1) return -1; /* Allocate and populate FAT. */ if (create_fat (floppy) == -1) return -1; /* Now we know how large everything is we can create the virtual * disk regions. */ if (create_regions (floppy) == -1) return -1; /* Check that if a size was specified, we ended up with it. */ if (size > 0) assert (virtual_size (&floppy->regions) == size); return 0; }
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 12/17] plugins/nbd: wrap source code at 80 chars
Wrap the source code at 80 characters. Align the backslashes in "nbdplug_config_help". Tested with: $ nbdkit nbd --help> [...] > [uri=]<URI> URI of an NBD socket to connect to (if > supported). > socket=<SOCKNAME> The Unix socket to connect to. > hostname=<HOST> The hostname for the TCP socket to connect to. > port=<PORT> TCP/VSOCK port or service name to use (default > 10809). > vsock=<CID> The cid for the VSOCK socket to connect to. > command=<COMMAND> Command to run. > arg=<ARG> Parameters for command. > socket-fd=<FD> Socket file descriptor to connect to. > export=<NAME> Export name to connect to (default ""). > dynamic-export=<BOOL> True to enable export name pass-through. > retry=<N> Retry connection up to N seconds (default 0). > shared=<BOOL> True to share one server connection among all > clients, rather than a connection per client > (default false). > tls=<MODE> How to use TLS; one of 'off', 'on', or > 'require'. > tls-certificates=<DIR> Directory containing files for X.509 > certificates. > tls-verify=<BOOL> True (default for X.509) to validate server. > tls-username=<NAME> Override username presented in X.509 TLS. > tls-psk=<FILE> File containing Pre-Shared Key for TLS.Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- plugins/nbd/nbd.c | 41 +++++++++++--------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/plugins/nbd/nbd.c b/plugins/nbd/nbd.c index 55a7f289ec24..febb985612e8 100644 --- a/plugins/nbd/nbd.c +++ b/plugins/nbd/nbd.c @@ -379,25 +379,30 @@ nbdplug_after_fork (void) return 0; } -#define nbdplug_config_help \ - "[uri=]<URI> URI of an NBD socket to connect to (if supported).\n" \ - "socket=<SOCKNAME> The Unix socket to connect to.\n" \ +#define nbdplug_config_help \ + "[uri=]<URI> URI of an NBD socket to connect to (if\n" \ + " supported).\n" \ + "socket=<SOCKNAME> The Unix socket to connect to.\n" \ "hostname=<HOST> The hostname for the TCP socket to connect to.\n" \ - "port=<PORT> TCP/VSOCK port or service name to use (default 10809).\n" \ - "vsock=<CID> The cid for the VSOCK socket to connect to.\n" \ - "command=<COMMAND> Command to run.\n" \ - "arg=<ARG> Parameters for command.\n" \ - "socket-fd=<FD> Socket file descriptor to connect to.\n" \ - "export=<NAME> Export name to connect to (default \"\").\n" \ - "dynamic-export=<BOOL> True to enable export name pass-through.\n" \ - "retry=<N> Retry connection up to N seconds (default 0).\n" \ - "shared=<BOOL> True to share one server connection among all clients,\n" \ - " rather than a connection per client (default false).\n" \ - "tls=<MODE> How to use TLS; one of 'off', 'on', or 'require'.\n" \ - "tls-certificates=<DIR> Directory containing files for X.509 certificates.\n" \ - "tls-verify=<BOOL> True (default for X.509) to validate server.\n" \ - "tls-username=<NAME> Override username presented in X.509 TLS.\n" \ - "tls-psk=<FILE> File containing Pre-Shared Key for TLS.\n" \ + "port=<PORT> TCP/VSOCK port or service name to use (default\n" \ + " 10809).\n" \ + "vsock=<CID> The cid for the VSOCK socket to connect to.\n" \ + "command=<COMMAND> Command to run.\n" \ + "arg=<ARG> Parameters for command.\n" \ + "socket-fd=<FD> Socket file descriptor to connect to.\n" \ + "export=<NAME> Export name to connect to (default \"\").\n" \ + "dynamic-export=<BOOL> True to enable export name pass-through.\n" \ + "retry=<N> Retry connection up to N seconds (default 0).\n" \ + "shared=<BOOL> True to share one server connection among all\n" \ + " clients, rather than a connection per client\n" \ + " (default false).\n" \ + "tls=<MODE> How to use TLS; one of 'off', 'on', or\n" \ + " 'require'.\n" \ + "tls-certificates=<DIR> Directory containing files for X.509\n" \ + " certificates.\n" \ + "tls-verify=<BOOL> True (default for X.509) to validate server.\n" \ + "tls-username=<NAME> Override username presented in X.509 TLS.\n" \ + "tls-psk=<FILE> File containing Pre-Shared Key for TLS.\n" \ static void nbdplug_dump_plugin (void)
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 13/17] plugins/perl: wrap source code at 80 chars
Wrap the source code at 80 characters. Truncate the blob hash in the overlong github.com link to 12 nibbles. Testing: (a) the truncated link leads to the same resource, (b) nbdkit still builds. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- plugins/perl/perl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/perl/perl.c b/plugins/perl/perl.c index cccf6836ccbf..d3b7cede28c0 100644 --- a/plugins/perl/perl.c +++ b/plugins/perl/perl.c @@ -171,7 +171,7 @@ xs_init (pTHX) /* This macro defines flags such as $Nbdkit::FLAG_MAY_TRIM * See also - * https://github.com/Perl/perl5/blob/5de22a40933c620b62e1f431457593777b99793d/os2/os2.c#L4563 + * https://github.com/Perl/perl5/blob/5de22a40933c/os2/os2.c#L4563 */ #define DEFINE_FLAG(n) \ gv = gv_fetchpv ("Nbdkit::" #n, TRUE, SVt_PV); \
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 14/17] plugins/ruby: wrap source code at 80 chars
Wrap the source code at 80 characters -- as widely as possible. We're still left with a stackoverflow link, embedded in a comment: https://stackoverflow.com/questions/11086549/how-to-rb-protect-everything-in-ruby that makes the total width of "plugins/ruby/ruby.c" 87 characters. (But that's just one line.) Tested with: $ nbdkit ruby> nbdkit: error: the first parameter must be script=/path/to/ruby/script.rbBugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- plugins/ruby/ruby.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/ruby/ruby.c b/plugins/ruby/ruby.c index 175a4cf6eed6..d37b6061ef4e 100644 --- a/plugins/ruby/ruby.c +++ b/plugins/ruby/ruby.c @@ -199,7 +199,8 @@ plugin_rb_config (const char *key, const char *value) int state; if (strcmp (key, "script") != 0) { - nbdkit_error ("the first parameter must be script=/path/to/ruby/script.rb"); + nbdkit_error ("the first parameter must be " + "script=/path/to/ruby/script.rb"); return -1; } script = value;
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 15/17] plugins/sh: wrap source code at 80 chars
Wrap the source code at 80 characters. Truncate the commit hash in the overlong github.com link to 12 nibbles. Testing: (a) the truncated link leads to the same resource, (b) nbdkit still builds. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- plugins/sh/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sh/call.c b/plugins/sh/call.c index a07935b92946..888c6459ae67 100644 --- a/plugins/sh/call.c +++ b/plugins/sh/call.c @@ -237,7 +237,7 @@ call3 (const char *wbuf, size_t wbuflen, /* sent to stdin (can be NULL) */ /* Note the assignment of environ avoids using execvpe which is a * GNU extension. See also: - * https://github.com/libguestfs/libnbd/commit/dc64ac5cdd0bc80ca4e18935ad0e8801d11a8644 + * https://github.com/libguestfs/libnbd/commit/dc64ac5cdd0b */ environ = env; execvp (argv[0], (char **) argv);
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 16/17] plugins/vddk: wrap source code at 80 chars
Wrap the source code at 80 characters -- as widely as possible. We're still left with a link, embedded in a comment: https://code.vmware.com/docs/11750/virtual-disk-development-kit-programming-guide/GUID-6BE903E8-DC70-46D9-98E4-E34A2002C2AD.html that makes the total width of "plugins/vddk/vddk.c" 131 characters. (But that's just one line.) Tested with: $ truncate -s 1G f (1) $ nbdkit vddk file=f> nbdkit: error: /usr/local/lib/vmware-vix-disklib/lib64/libvixDiskLib.so.8: cannot open shared object file: No such file or directory > > If 'lib64/libvixDiskLib.so.8' is located on a non-standard path you may need to > set libdir=/path/to/vmware-vix-disklib-distrib. > > See nbdkit-vddk-plugin(1) man page section "LIBRARY LOCATION" for details.(2) pushd $HOME/tmp/vddk-5.1.1/vmware-vix-disklib-distrib/lib64 ln -s libvixDiskLib.so.5 libvixDiskLib.so.8 popd nbdkit vddk file=f libdir=$HOME/tmp/vddk-5.1.1/vmware-vix-disklib-distrib> nbdkit: error: required VDDK symbol "VixDiskLib_Flush" is missing. VDDK version must be >= 6.5. See nbdkit-vddk-plugin(1) man page section "SUPPORTED VERSIONS OF VDDK". Original dlopen error: /home/lacos/tmp/vddk-5.1.1/vmware-vix-disklib-distrib/lib64/libvixDiskLib.so.8: undefined symbol: VixDiskLib_Flush(3) $ nbdkit vddk file=f create=true> nbdkit: error: if using create=true you must specify the size using the create-size parameter(4) $ nbdkit vddk file=f create=true create-size=1> nbdkit: error: create-size must be greater than zero and a multiple of 512Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- plugins/vddk/vddk.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c index 1233c84eed0f..df69059d4218 100644 --- a/plugins/vddk/vddk.c +++ b/plugins/vddk/vddk.c @@ -205,7 +205,8 @@ vddk_config (const char *key, const char *value) if (r64 == -1) return -1; if (r64 <= 0 || (r64 & 511) != 0) { - nbdkit_error ("create-size must be greater than zero and a multiple of 512"); + nbdkit_error ("create-size must be greater than zero and a multiple of " + "512"); return -1; } create_size = r64; @@ -361,7 +362,8 @@ vddk_config_complete (void) } if (create_size == 0) { - nbdkit_error ("if using create=true you must specify the size using the create-size parameter"); + nbdkit_error ("if using create=true you must specify the size using the " + "create-size parameter"); return -1; } } @@ -382,7 +384,8 @@ missing_required_symbol (const char *fn) { nbdkit_error ("required VDDK symbol \"%s\" is missing. " "VDDK version must be >= 6.5. " - "See nbdkit-vddk-plugin(1) man page section \"SUPPORTED VERSIONS OF VDDK\". " + "See nbdkit-vddk-plugin(1) man page " + "section \"SUPPORTED VERSIONS OF VDDK\". " "Original dlopen error: %s\n", fn, dlerror ()); exit (EXIT_FAILURE); @@ -455,7 +458,8 @@ load_library (bool load_error_is_fatal) nbdkit_error ("%s\n\n" "If '%s' is located on a non-standard path you may need to\n" "set libdir=/path/to/vmware-vix-disklib-distrib.\n\n" - "See nbdkit-vddk-plugin(1) man page section \"LIBRARY LOCATION\" for details.", + "See nbdkit-vddk-plugin(1) man page " + "section \"LIBRARY LOCATION\" for details.", orig_error ? : "(unknown error)", libs[0].soname); exit (EXIT_FAILURE); }
Laszlo Ersek
2023-Apr-13 14:03 UTC
[Libguestfs] [nbdkit PATCH 17/17] server: wrap source code at 80 chars
Wrap the source code at 80 characters. Extract typedefs "plugin_init_function" and "filter_init_function". Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- server/internal.h | 7 +++++-- server/filters.c | 2 +- server/main.c | 6 ++++-- server/plugins.c | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/server/internal.h b/server/internal.h index 4b6e29154e10..2aff4cfff91d 100644 --- a/server/internal.h +++ b/server/internal.h @@ -508,14 +508,17 @@ extern int backend_cache (struct context *c, __attribute__ ((__nonnull__ (1, 5))); /* plugins.c */ +typedef struct nbdkit_plugin *(*plugin_init_function) (void); extern struct backend *plugin_register (size_t index, const char *filename, - void *dl, struct nbdkit_plugin *(*plugin_init) (void)) + void *dl, + plugin_init_function plugin_init) __attribute__ ((__nonnull__ (2, 3, 4))); /* filters.c */ +typedef struct nbdkit_filter *(*filter_init_function) (void); extern struct backend *filter_register (struct backend *next, size_t index, const char *filename, void *dl, - struct nbdkit_filter *(*filter_init) (void)) + filter_init_function filter_init) __attribute__ ((__nonnull__ (1, 3, 4, 5))); /* locks.c */ diff --git a/server/filters.c b/server/filters.c index f32a9b46f6f2..b667754b217d 100644 --- a/server/filters.c +++ b/server/filters.c @@ -660,7 +660,7 @@ static struct backend filter_functions = { /* Register and load a filter. */ struct backend * filter_register (struct backend *next, size_t index, const char *filename, - void *dl, struct nbdkit_filter *(*filter_init) (void)) + void *dl, filter_init_function filter_init) { struct backend_filter *f; const struct nbdkit_filter *filter; diff --git a/server/main.c b/server/main.c index 631401b72712..c3b9bf3848ac 100644 --- a/server/main.c +++ b/server/main.c @@ -79,8 +79,10 @@ #endif static char *make_random_fifo (void); -static struct backend *open_plugin_so (size_t i, const char *filename, int short_name); -static struct backend *open_filter_so (struct backend *next, size_t i, const char *filename, int short_name); +static struct backend *open_plugin_so (size_t i, const char *filename, + int short_name); +static struct backend *open_filter_so (struct backend *next, size_t i, + const char *filename, int short_name); static void start_serving (void); static void write_pidfile (void); static bool is_config_key (const char *key, size_t len); diff --git a/server/plugins.c b/server/plugins.c index 1faac348045e..85eac76c45e7 100644 --- a/server/plugins.c +++ b/server/plugins.c @@ -908,7 +908,7 @@ static struct backend plugin_functions = { /* Register and load a plugin. */ struct backend * plugin_register (size_t index, const char *filename, - void *dl, struct nbdkit_plugin *(*plugin_init) (void)) + void *dl, plugin_init_function plugin_init) { struct backend_plugin *p; const struct nbdkit_plugin *plugin;