From: EvgeniyRogov Date: Fri, 1 Mar 2024 11:13:11 +0000 (+0300) Subject: - Fixed report error code in blockdev. X-Git-Tag: v2.42-start~492^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b3e9aadce221fef040e8a059650e351234c8a762;p=thirdparty%2Futil-linux.git - Fixed report error code in blockdev. - Minor: Added a period at the end of "--rereadpt" description. --- diff --git a/disk-utils/blockdev.8.adoc b/disk-utils/blockdev.8.adoc index 4eb3b3214..3c4178b63 100644 --- a/disk-utils/blockdev.8.adoc +++ b/disk-utils/blockdev.8.adoc @@ -97,7 +97,7 @@ Print logical sector size in bytes - usually 512. Get size in 512-byte sectors. *--rereadpt*:: -Reread partition table +Reread partition table. *--setbsz* _bytes_:: Set blocksize. Note that the block size is specific to the current file descriptor opening the block device, so the change of block size only persists for as long as *blockdev* has the device open, and is lost once *blockdev* exits. diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c index 4a1d4e726..55b47acf6 100644 --- a/disk-utils/blockdev.c +++ b/disk-utils/blockdev.c @@ -254,8 +254,8 @@ static int find_cmd(char *s) static void do_commands(int fd, char **argv, int d); static void report_header(void); -static void report_device(char *device, int quiet); -static void report_all_devices(void); +static int report_device(char *device, int quiet); +static int report_all_devices(void); int main(int argc, char **argv) { @@ -279,14 +279,15 @@ int main(int argc, char **argv) /* --report not together with other commands */ if (!strcmp(argv[1], "--report")) { + int rc = 0; report_header(); if (argc > 2) { for (d = 2; d < argc; d++) - report_device(argv[d], 0); + rc += report_device(argv[d], 0); } else { - report_all_devices(); + rc = report_all_devices(); } - return EXIT_SUCCESS; + return rc ? EXIT_FAILURE : EXIT_SUCCESS; } /* do each of the commands on each of the devices */ @@ -453,13 +454,14 @@ static void do_commands(int fd, char **argv, int d) } } -static void report_all_devices(void) +static int report_all_devices(void) { FILE *procpt; char line[200]; char ptname[200 + 1]; char device[210]; int ma, mi, sz; + int rc = 0; procpt = fopen(_PATH_PROC_PARTITIONS, "r"); if (!procpt) @@ -471,16 +473,18 @@ static void report_all_devices(void) continue; snprintf(device, sizeof(device), "/dev/%s", ptname); - report_device(device, 1); + rc += report_device(device, 1); } fclose(procpt); + return rc; } -static void report_device(char *device, int quiet) +static int report_device(char *device, int quiet) { int fd; int ro, ssz, bsz; + int rc = 0; long ra; unsigned long long bytes; uint64_t start = 0; @@ -491,7 +495,7 @@ static void report_device(char *device, int quiet) if (fd < 0) { if (!quiet) warn(_("cannot open %s"), device); - return; + return 1; } ro = ssz = bsz = 0; @@ -524,9 +528,11 @@ static void report_device(char *device, int quiet) } else { if (!quiet) warnx(_("ioctl error on %s"), device); + rc = 1; } close(fd); + return rc; } static void report_header(void)