Mykola Ivanets
2020-Feb-11 21:51 UTC
[Libguestfs] [PATCH 0/1] tools: add '--blocksize' option for C-based tools
From: Nikolay Ivanets <stenavin@gmail.com> This patch depends on changes in 'common' sub-module posted here: https://www.redhat.com/archives/libguestfs/2020-February/msg00096.html Nikolay Ivanets (1): tools: add '--blocksize' option for C-based tools align/scan.c | 8 ++++++++ align/virt-alignment-scan.pod | 12 ++++++++++++ cat/cat.c | 8 ++++++++ cat/filesystems.c | 8 ++++++++ cat/log.c | 8 ++++++++ cat/ls.c | 8 ++++++++ cat/tail.c | 8 ++++++++ cat/virt-cat.pod | 12 ++++++++++++ cat/virt-filesystems.pod | 12 ++++++++++++ cat/virt-log.pod | 12 ++++++++++++ cat/virt-ls.pod | 12 ++++++++++++ cat/virt-tail.pod | 12 ++++++++++++ df/main.c | 8 ++++++++ df/virt-df.pod | 12 ++++++++++++ diff/diff.c | 8 ++++++++ diff/virt-diff.pod | 12 ++++++++++++ edit/edit.c | 8 ++++++++ edit/virt-edit.pod | 12 ++++++++++++ fish/fish.c | 8 ++++++++ fish/guestfish.pod | 11 +++++++++++ format/format.c | 8 ++++++++ format/virt-format.pod | 12 ++++++++++++ fuse/guestmount.c | 8 ++++++++ fuse/guestmount.pod | 12 ++++++++++++ inspector/inspector.c | 8 ++++++++ inspector/virt-inspector.pod | 12 ++++++++++++ rescue/rescue.c | 8 ++++++++ rescue/virt-rescue.pod | 12 ++++++++++++ 28 files changed, 279 insertions(+) -- 2.17.2
Mykola Ivanets
2020-Feb-11 21:51 UTC
[Libguestfs] [PATCH 1/1] tools: add '--blocksize' option for C-based tools
From: Nikolay Ivanets <stenavin@gmail.com> This patch adds '--blocksize' command line option for guestfish and other C-based tools. This option allows specifying disk sector size. --- align/scan.c | 8 ++++++++ align/virt-alignment-scan.pod | 12 ++++++++++++ cat/cat.c | 8 ++++++++ cat/filesystems.c | 8 ++++++++ cat/log.c | 8 ++++++++ cat/ls.c | 8 ++++++++ cat/tail.c | 8 ++++++++ cat/virt-cat.pod | 12 ++++++++++++ cat/virt-filesystems.pod | 12 ++++++++++++ cat/virt-log.pod | 12 ++++++++++++ cat/virt-ls.pod | 12 ++++++++++++ cat/virt-tail.pod | 12 ++++++++++++ df/main.c | 8 ++++++++ df/virt-df.pod | 12 ++++++++++++ diff/diff.c | 8 ++++++++ diff/virt-diff.pod | 12 ++++++++++++ edit/edit.c | 8 ++++++++ edit/virt-edit.pod | 12 ++++++++++++ fish/fish.c | 8 ++++++++ fish/guestfish.pod | 11 +++++++++++ format/format.c | 8 ++++++++ format/virt-format.pod | 12 ++++++++++++ fuse/guestmount.c | 8 ++++++++ fuse/guestmount.pod | 12 ++++++++++++ inspector/inspector.c | 8 ++++++++ inspector/virt-inspector.pod | 12 ++++++++++++ rescue/rescue.c | 8 ++++++++ rescue/virt-rescue.pod | 12 ++++++++++++ 28 files changed, 279 insertions(+) diff --git a/align/scan.c b/align/scan.c index b9f29868c..5a456d3d6 100644 --- a/align/scan.c +++ b/align/scan.c @@ -90,6 +90,8 @@ usage (int status) " -c|--connect uri Specify libvirt URI for -d option\n" " -d|--domain guest Add disks from libvirt guest\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " -P nr_threads Use at most nr_threads\n" " -q|--quiet No output, just exit code\n" @@ -119,6 +121,7 @@ main (int argc, char *argv[]) { "connect", 1, 0, 'c' }, { "domain", 1, 0, 'd' }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "long-options", 0, 0, 0 }, { "quiet", 0, 0, 'q' }, @@ -131,6 +134,8 @@ main (int argc, char *argv[]) struct drv *drvs = NULL; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; int exit_code; @@ -153,6 +158,8 @@ main (int argc, char *argv[]) display_short_options (options); else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "uuid")) { uuid = 1; } else @@ -215,6 +222,7 @@ main (int argc, char *argv[]) usage (EXIT_FAILURE); CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* virt-alignment-scan has two modes. If the user didn't specify * any drives, then we do the scan on every libvirt guest. That's diff --git a/align/virt-alignment-scan.pod b/align/virt-alignment-scan.pod index 19953546e..21b5339e0 100644 --- a/align/virt-alignment-scan.pod +++ b/align/virt-alignment-scan.pod @@ -162,6 +162,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + =item B<-P> nr_threads Since libguestfs 1.22, virt-alignment-scan is multithreaded and diff --git a/cat/cat.c b/cat/cat.c index 4f0d7035e..eb070877a 100644 --- a/cat/cat.c +++ b/cat/cat.c @@ -70,6 +70,8 @@ usage (int status) " -d|--domain guest Add disks from libvirt guest\n" " --echo-keys Don't turn off echo for passphrases\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " --key selector Specify a LUKS key\n" " --keys-from-stdin Read passphrases from stdin\n" @@ -101,6 +103,7 @@ main (int argc, char *argv[]) { "domain", 1, 0, 'd' }, { "echo-keys", 0, 0, 0 }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "key", 1, 0, 0 }, { "keys-from-stdin", 0, 0, 0 }, @@ -118,6 +121,8 @@ main (int argc, char *argv[]) char *p; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int r; int option_index; @@ -143,6 +148,8 @@ main (int argc, char *argv[]) echo_keys = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "key")) { OPTION_key; } else @@ -232,6 +239,7 @@ main (int argc, char *argv[]) usage (EXIT_FAILURE); CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* User must have specified some drives. */ if (drvs == NULL) { diff --git a/cat/filesystems.c b/cat/filesystems.c index 74e994169..447bccc6e 100644 --- a/cat/filesystems.c +++ b/cat/filesystems.c @@ -111,6 +111,8 @@ usage (int status) " --extra Display swap and data filesystems\n" " --filesystems Display mountable filesystems\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " -h|--human-readable Human-readable sizes in --long output\n" " --help Display brief help\n" " --keys-from-stdin Read passphrases from stdin\n" @@ -156,6 +158,7 @@ main (int argc, char *argv[]) { "extra", 0, 0, 0 }, { "filesystems", 0, 0, 0 }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "human-readable", 0, 0, 'h' }, { "keys-from-stdin", 0, 0, 0 }, @@ -183,6 +186,8 @@ main (int argc, char *argv[]) struct drv *drvs = NULL; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; int no_title = 0; /* --no-title */ @@ -210,6 +215,8 @@ main (int argc, char *argv[]) echo_keys = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "all")) { output = OUTPUT_ALL; } else if (STREQ (long_options[option_index].name, "blkdevs") || @@ -306,6 +313,7 @@ main (int argc, char *argv[]) } CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* -h and --csv doesn't make sense. Spreadsheets will corrupt these * fields. (RHBZ#600977). diff --git a/cat/log.c b/cat/log.c index f8a5c85f2..50cd50eb9 100644 --- a/cat/log.c +++ b/cat/log.c @@ -80,6 +80,8 @@ usage (int status) " -d|--domain guest Add disks from libvirt guest\n" " --echo-keys Don't turn off echo for passphrases\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " --key selector Specify a LUKS key\n" " --keys-from-stdin Read passphrases from stdin\n" @@ -109,6 +111,7 @@ main (int argc, char *argv[]) { "domain", 1, 0, 'd' }, { "echo-keys", 0, 0, 0 }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "key", 1, 0, 0 }, { "keys-from-stdin", 0, 0, 0 }, @@ -121,6 +124,8 @@ main (int argc, char *argv[]) struct drv *drvs = NULL; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int r; int option_index; @@ -146,6 +151,8 @@ main (int argc, char *argv[]) echo_keys = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "key")) { OPTION_key; } else @@ -204,6 +211,7 @@ main (int argc, char *argv[]) } CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* User must have specified some drives. */ if (drvs == NULL) { diff --git a/cat/ls.c b/cat/ls.c index 055939a80..b56f3a46b 100644 --- a/cat/ls.c +++ b/cat/ls.c @@ -111,6 +111,8 @@ usage (int status) " --echo-keys Don't turn off echo for passphrases\n" " --extra-stats Display extra stats\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " -h|--human-readable Human-readable sizes in output\n" " --key selector Specify a LUKS key\n" @@ -158,6 +160,7 @@ main (int argc, char *argv[]) { "extra-stat", 0, 0, 0 }, { "extra-stats", 0, 0, 0 }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "human-readable", 0, 0, 'h' }, { "key", 1, 0, 0 }, @@ -185,6 +188,8 @@ main (int argc, char *argv[]) char *p; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; #define MODE_LS_L 1 @@ -213,6 +218,8 @@ main (int argc, char *argv[]) echo_keys = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "checksum") || STREQ (long_options[option_index].name, "checksums")) { if (!optarg || STREQ (optarg, "")) @@ -338,6 +345,7 @@ main (int argc, char *argv[]) assert (live == 0); CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* Many flags only apply to -lR mode. */ if (mode != MODE_LS_LR && diff --git a/cat/tail.c b/cat/tail.c index 9e3af7c7d..c12b32631 100644 --- a/cat/tail.c +++ b/cat/tail.c @@ -78,6 +78,8 @@ usage (int status) " --echo-keys Don't turn off echo for passphrases\n" " -f|--follow Ignored for compatibility with tail\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " --key selector Specify a LUKS key\n" " --keys-from-stdin Read passphrases from stdin\n" @@ -110,6 +112,7 @@ main (int argc, char *argv[]) { "echo-keys", 0, 0, 0 }, { "follow", 0, 0, 'f' }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "key", 1, 0, 0 }, { "keys-from-stdin", 0, 0, 0 }, @@ -126,6 +129,8 @@ main (int argc, char *argv[]) char *p; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int r; int option_index; @@ -151,6 +156,8 @@ main (int argc, char *argv[]) echo_keys = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "key")) { OPTION_key; } else @@ -217,6 +224,7 @@ main (int argc, char *argv[]) } CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* User must have specified some drives. */ if (drvs == NULL) { diff --git a/cat/virt-cat.pod b/cat/virt-cat.pod index 0c4ce4b77..48556f380 100644 --- a/cat/virt-cat.pod +++ b/cat/virt-cat.pod @@ -121,6 +121,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + __INCLUDE:key-option.pod__ =item B<--keys-from-stdin> diff --git a/cat/virt-filesystems.pod b/cat/virt-filesystems.pod index a3a0fb29a..8183754d7 100644 --- a/cat/virt-filesystems.pod +++ b/cat/virt-filesystems.pod @@ -195,6 +195,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + =item B<-h> =item B<--human-readable> diff --git a/cat/virt-log.pod b/cat/virt-log.pod index a6b37662e..042f93a84 100644 --- a/cat/virt-log.pod +++ b/cat/virt-log.pod @@ -105,6 +105,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + __INCLUDE:key-option.pod__ =item B<--keys-from-stdin> diff --git a/cat/virt-ls.pod b/cat/virt-ls.pod index 53141b2c6..cae35c7b1 100644 --- a/cat/virt-ls.pod +++ b/cat/virt-ls.pod @@ -343,6 +343,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + =item B<-h> =item B<--human-readable> diff --git a/cat/virt-tail.pod b/cat/virt-tail.pod index 9f72ce3f7..3e41631a9 100644 --- a/cat/virt-tail.pod +++ b/cat/virt-tail.pod @@ -123,6 +123,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + __INCLUDE:key-option.pod__ =item B<--keys-from-stdin> diff --git a/df/main.c b/df/main.c index bbb2ddb61..fba2d57d1 100644 --- a/df/main.c +++ b/df/main.c @@ -83,6 +83,8 @@ usage (int status) " --csv Output as Comma-Separated Values\n" " -d|--domain guest Add disks from libvirt guest\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " -h|--human-readable Print sizes in human-readable format\n" " --help Display brief help\n" " -i|--inodes Display inodes\n" @@ -115,6 +117,7 @@ main (int argc, char *argv[]) { "csv", 0, 0, 0 }, { "domain", 1, 0, 'd' }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "human-readable", 0, 0, 'h' }, { "inodes", 0, 0, 'i' }, @@ -130,6 +133,8 @@ main (int argc, char *argv[]) struct drv *drv; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; size_t max_threads = 0; @@ -151,6 +156,8 @@ main (int argc, char *argv[]) display_short_options (options); else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "csv")) { csv = 1; } else if (STREQ (long_options[option_index].name, "one-per-guest")) { @@ -251,6 +258,7 @@ main (int argc, char *argv[]) usage (EXIT_FAILURE); CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* -h and --csv doesn't make sense. Spreadsheets will corrupt these * fields. (RHBZ#600977). diff --git a/df/virt-df.pod b/df/virt-df.pod index de6e6b4e5..a823e937d 100644 --- a/df/virt-df.pod +++ b/df/virt-df.pod @@ -140,6 +140,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + =item B<-h> =item B<--human-readable> diff --git a/diff/diff.c b/diff/diff.c index c04b5f185..f7ab93726 100644 --- a/diff/diff.c +++ b/diff/diff.c @@ -126,6 +126,8 @@ usage (int status) " --echo-keys Don't turn off echo for passphrases\n" " --extra-stats Display extra stats\n" " --format[=raw|..] Force disk format for -a or -A option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a or -A option\n" " --help Display brief help\n" " -h|--human-readable Human-readable sizes in output\n" " --key selector Specify a LUKS key\n" @@ -178,6 +180,7 @@ main (int argc, char *argv[]) { "extra-stat", 0, 0, 0 }, { "extra-stats", 0, 0, 0 }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "human-readable", 0, 0, 'h' }, { "long-options", 0, 0, 0 }, @@ -201,6 +204,8 @@ main (int argc, char *argv[]) struct drv *drvs2 = NULL; /* Second guest. */ const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; struct tree *tree1, *tree2; @@ -232,6 +237,8 @@ main (int argc, char *argv[]) echo_keys = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "all")) { enable_extra_stats = enable_times = enable_uids = enable_xattrs = 1; } else if (STREQ (long_options[option_index].name, "atime")) { @@ -366,6 +373,7 @@ main (int argc, char *argv[]) assert (live == 0); CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; unsigned errors = 0; diff --git a/diff/virt-diff.pod b/diff/virt-diff.pod index 0500598bd..c7f2ebcef 100644 --- a/diff/virt-diff.pod +++ b/diff/virt-diff.pod @@ -160,6 +160,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a>/I<-A> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + =item B<-h> =item B<--human-readable> diff --git a/edit/edit.c b/edit/edit.c index 4b9f1bed1..635995e0d 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -81,6 +81,8 @@ usage (int status) " --echo-keys Don't turn off echo for passphrases\n" " -e|--edit|--expr expr Non-interactive editing using Perl expr\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " --key selector Specify a LUKS key\n" " --keys-from-stdin Read passphrases from stdin\n" @@ -115,6 +117,7 @@ main (int argc, char *argv[]) { "edit", 1, 0, 'e' }, { "expr", 1, 0, 'e' }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "key", 1, 0, 0 }, { "keys-from-stdin", 0, 0, 0 }, @@ -132,6 +135,8 @@ main (int argc, char *argv[]) char *p; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; struct key_store *ks = NULL; @@ -156,6 +161,8 @@ main (int argc, char *argv[]) echo_keys = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "key")) { OPTION_key; } else @@ -257,6 +264,7 @@ main (int argc, char *argv[]) usage (EXIT_FAILURE); CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* User must have specified some drives. */ if (drvs == NULL) { diff --git a/edit/virt-edit.pod b/edit/virt-edit.pod index 4909a7df1..3be756638 100644 --- a/edit/virt-edit.pod +++ b/edit/virt-edit.pod @@ -153,6 +153,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + __INCLUDE:key-option.pod__ =item B<--keys-from-stdin> diff --git a/fish/fish.c b/fish/fish.c index 2070e370e..419e989df 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -130,6 +130,8 @@ usage (int status) " --echo-keys Don’t turn off echo for passphrases\n" " -f|--file file Read commands from file\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " -i|--inspector Automatically mount filesystems\n" " --key selector Specify a LUKS key\n" @@ -197,6 +199,7 @@ main (int argc, char *argv[]) { "echo-keys", 0, 0, 0 }, { "file", 1, 0, 'f' }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "inspector", 0, 0, 'i' }, { "key", 1, 0, 0 }, @@ -228,6 +231,8 @@ main (int argc, char *argv[]) char *p, *file = NULL; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; struct sigaction sa; @@ -285,6 +290,8 @@ main (int argc, char *argv[]) echo_keys = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "csh")) { remote_control_csh = 1; } else if (STREQ (long_options[option_index].name, "live")) { @@ -468,6 +475,7 @@ main (int argc, char *argv[]) } CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* If we've got drives to add, add them now. */ add_drives (drvs); diff --git a/fish/guestfish.pod b/fish/guestfish.pod index 1904b640c..2bc951f0f 100644 --- a/fish/guestfish.pod +++ b/fish/guestfish.pod @@ -249,6 +249,17 @@ this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). See also L</add>. +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also L</add>. + =item B<-i> =item B<--inspector> diff --git a/format/format.c b/format/format.c index 5453fc7e1..6176734cd 100644 --- a/format/format.c +++ b/format/format.c @@ -82,6 +82,8 @@ usage (int status) " -a|--add image Add image\n" " --filesystem=.. Create empty filesystem\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " --label=.. Set filesystem label\n" " --lvm=.. Create Linux LVM2 logical volume\n" @@ -114,6 +116,7 @@ main (int argc, char *argv[]) { "add", 1, 0, 'a' }, { "filesystem", 1, 0, 0 }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "label", 1, 0, 0 }, { "long-options", 0, 0, 0 }, @@ -128,6 +131,8 @@ main (int argc, char *argv[]) struct drv *drvs = NULL; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; int retry, retries; @@ -148,6 +153,8 @@ main (int argc, char *argv[]) display_short_options (options); else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "filesystem")) { if (STREQ (optarg, "none")) filesystem = NULL; @@ -233,6 +240,7 @@ main (int argc, char *argv[]) } CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* The user didn't specify any drives to format. */ if (drvs == NULL) { diff --git a/format/virt-format.pod b/format/virt-format.pod index 11b4409a7..5f491eee4 100644 --- a/format/virt-format.pod +++ b/format/virt-format.pod @@ -112,6 +112,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + =item B<--label=>LABEL Set the filesystem label. diff --git a/fuse/guestmount.c b/fuse/guestmount.c index 6c35bcca7..6588d0d48 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -116,6 +116,8 @@ usage (int status) " --echo-keys Don't turn off echo for passphrases\n" " --fd=FD Write to pipe FD when mountpoint is ready\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --fuse-help Display extra FUSE options\n" " -i|--inspector Automatically mount filesystems\n" " --help Display help message and exit\n" @@ -163,6 +165,7 @@ main (int argc, char *argv[]) { "echo-keys", 0, 0, 0 }, { "fd", 1, 0, 0 }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "fuse-help", 0, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "inspector", 0, 0, 'i' }, @@ -191,6 +194,8 @@ main (int argc, char *argv[]) char *p; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c, r; int option_index; struct sigaction sa; @@ -235,6 +240,8 @@ main (int argc, char *argv[]) /* nothing */ } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "keys-from-stdin")) { keys_from_stdin = 1; } else if (STREQ (long_options[option_index].name, "echo-keys")) { @@ -316,6 +323,7 @@ main (int argc, char *argv[]) } CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* Check we have the right options. */ if (!live) { diff --git a/fuse/guestmount.pod b/fuse/guestmount.pod index d4e12e641..664dcc037 100644 --- a/fuse/guestmount.pod +++ b/fuse/guestmount.pod @@ -230,6 +230,18 @@ this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). See also L<guestfs(3)/guestfs_add_drive_opts>. +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + =item B<--fuse-help> Display help on special FUSE options (see I<-o> below). diff --git a/inspector/inspector.c b/inspector/inspector.c index fa8e721ff..c6f52b90f 100644 --- a/inspector/inspector.c +++ b/inspector/inspector.c @@ -96,6 +96,8 @@ usage (int status) " -d|--domain guest Add disks from libvirt guest\n" " --echo-keys Don't turn off echo for passphrases\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " --key selector Specify a LUKS key\n" " --keys-from-stdin Read passphrases from stdin\n" @@ -128,6 +130,7 @@ main (int argc, char *argv[]) { "domain", 1, 0, 'd' }, { "echo-keys", 0, 0, 0 }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "key", 1, 0, 0 }, { "keys-from-stdin", 0, 0, 0 }, @@ -144,6 +147,8 @@ main (int argc, char *argv[]) struct drv *drv; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; struct key_store *ks = NULL; @@ -168,6 +173,8 @@ main (int argc, char *argv[]) echo_keys = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "xpath")) { xpath = optarg; } else if (STREQ (long_options[option_index].name, "no-applications")) { @@ -262,6 +269,7 @@ main (int argc, char *argv[]) } CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* XPath is modal: no drives should be specified. There must be * one extra parameter on the command line. diff --git a/inspector/virt-inspector.pod b/inspector/virt-inspector.pod index 24fbf2e08..48545970c 100644 --- a/inspector/virt-inspector.pod +++ b/inspector/virt-inspector.pod @@ -114,6 +114,18 @@ parameter is ignored. If working with untrusted raw-format guest disk images, you should ensure the format is always specified. +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + __INCLUDE:key-option.pod__ =item B<--keys-from-stdin> diff --git a/rescue/rescue.c b/rescue/rescue.c index 419242381..3865450fa 100644 --- a/rescue/rescue.c +++ b/rescue/rescue.c @@ -92,6 +92,8 @@ usage (int status) " -d|--domain guest Add disks from libvirt guest\n" " -e ^x|none Set or disable escape key (default ^])\n" " --format[=raw|..] Force disk format for -a option\n" + " --blocksize[=512|4096]\n" + " Set sector size of the disk for -a option\n" " --help Display brief help\n" " -i|--inspector Automatically mount filesystems\n" " -m|--mount dev[:mnt[:opts[:fstype]] Mount dev on mnt (if omitted, /)\n" @@ -130,6 +132,7 @@ main (int argc, char *argv[]) { "connect", 1, 0, 'c' }, { "domain", 1, 0, 'd' }, { "format", 2, 0, 0 }, + { "blocksize", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "inspector", 0, 0, 'i' }, { "long-options", 0, 0, 0 }, @@ -154,6 +157,8 @@ main (int argc, char *argv[]) char *p; const char *format = NULL; bool format_consumed = true; + int blocksize = 0; + bool blocksize_consumed = true; int c; int option_index; int network = 0; @@ -187,6 +192,8 @@ main (int argc, char *argv[]) network = 1; } else if (STREQ (long_options[option_index].name, "format")) { OPTION_format; + } else if (STREQ (long_options[option_index].name, "blocksize")) { + OPTION_blocksize; } else if (STREQ (long_options[option_index].name, "smp")) { if (sscanf (optarg, "%d", &smp) != 1) error (EXIT_FAILURE, 0, @@ -334,6 +341,7 @@ main (int argc, char *argv[]) } CHECK_OPTION_format_consumed; + CHECK_OPTION_blocksize_consumed; /* User must have specified some drives. */ if (drvs == NULL) { diff --git a/rescue/virt-rescue.pod b/rescue/virt-rescue.pod index c7be8b8af..a4896f432 100644 --- a/rescue/virt-rescue.pod +++ b/rescue/virt-rescue.pod @@ -176,6 +176,18 @@ If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851). +=item B<--blocksize=512> + +=item B<--blocksize=4096> + +=item B<--blocksize> + +This parameter sets the sector size of the disk image. Similar to +I<--format> option it affects all subsequent I<-a> options. Using +I<--blocksize> with no argument switches disk sector size to the +default value which usually 512 bytes. See also +L<guestfs(3)/guestfs_add_drive_opts>. + =item B<-i> =item B<--inspector> -- 2.17.2
Richard W.M. Jones
2020-Feb-13 09:43 UTC
Re: [Libguestfs] [PATCH 1/1] tools: add '--blocksize' option for C-based tools
On Tue, Feb 11, 2020 at 11:51:17PM +0200, Mykola Ivanets wrote:> diff --git a/align/scan.c b/align/scan.c > index b9f29868c..5a456d3d6 100644 > --- a/align/scan.c > +++ b/align/scan.c > @@ -90,6 +90,8 @@ usage (int status) > " -c|--connect uri Specify libvirt URI for -d option\n" > " -d|--domain guest Add disks from libvirt guest\n" > " --format[=raw|..] Force disk format for -a option\n" > + " --blocksize[=512|4096]\n" > + " Set sector size of the disk for -a option\n" > " --help Display brief help\n" > " -P nr_threads Use at most nr_threads\n" > " -q|--quiet No output, just exit code\n"These options need to be kept in alphabetical order.> @@ -119,6 +121,7 @@ main (int argc, char *argv[]) > { "connect", 1, 0, 'c' }, > { "domain", 1, 0, 'd' }, > { "format", 2, 0, 0 }, > + { "blocksize", 2, 0, 0 }, > { "help", 0, 0, HELP_OPTION }, > { "long-options", 0, 0, 0 }, > { "quiet", 0, 0, 'q' },And here.> diff --git a/align/virt-alignment-scan.pod b/align/virt-alignment-scan.pod > index 19953546e..21b5339e0 100644 > --- a/align/virt-alignment-scan.pod > +++ b/align/virt-alignment-scan.pod > @@ -162,6 +162,18 @@ If you have untrusted raw-format guest disk images, you should use > this option to specify the disk format. This avoids a possible > security problem with malicious guests (CVE-2010-3851). > > +=item B<--blocksize=512> > + > +=item B<--blocksize=4096> > + > +=item B<--blocksize> > + > +This parameter sets the sector size of the disk image. Similar to > +I<--format> option it affects all subsequent I<-a> options. Using > +I<--blocksize> with no argument switches disk sector size to the > +default value which usually 512 bytes. See also > +L<guestfs(3)/guestfs_add_drive_opts>. > + > =item B<-P> nr_threadsAnd here. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Reasonably Related Threads
- [PATCH v2 0/1] tools: add '--blocksize' option for C-based tools
- [PATCH v3 0/1] tools: add '--blocksize' option for C-based tools
- [common PATCH v3 0/1] options: add '--blocksize' option for C-based tools
- [common PATCH v2 0/1] options: add '--blocksize' option for C-based tools
- [PATCH v3 1/1] tools: add '--blocksize' option for C-based tools