CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 16:01:50 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: use consistent markup in usage message


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.8 src/usr.sbin/flashctl/flashctl.c:1.9
--- src/usr.sbin/flashctl/flashctl.c:1.8	Sun Jan  8 15:55:25 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 16:01:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.8 2023/01/08 15:55:25 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.9 2023/01/08 16:01:49 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: flashctl.c,v 1.8 2023/01/08 15:55:25 rillig Exp $");
+__RCSID("$NetBSD: flashctl.c,v 1.9 2023/01/08 16:01:49 rillig Exp $");
 
 #include 
 #include 
@@ -252,12 +252,12 @@ to_intmax(intmax_t *num, const char *str
 void
 usage(void)
 {
-	fprintf(stderr, "usage: %s device identify\n",
+	fprintf(stderr, "usage: %s  identify\n",
 	getprogname());
-	fprintf(stderr, "   %s device erase  |all\n",
+	fprintf(stderr, "   %s  erase  |all\n",
 	getprogname());
-	fprintf(stderr, "   %s device badblocks\n",
+	fprintf(stderr, "   %s  badblocks\n",
 	getprogname());
-	fprintf(stderr, "   %s device markbad \n",
+	fprintf(stderr, "   %s  markbad \n",
 	getprogname());
 }



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 16:01:50 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: use consistent markup in usage message


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:55:26 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: remove trailing whitespace

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.7 src/usr.sbin/flashctl/flashctl.c:1.8
--- src/usr.sbin/flashctl/flashctl.c:1.7	Sun Jan  8 15:52:30 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 15:55:25 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.7 2023/01/08 15:52:30 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.8 2023/01/08 15:55:25 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: flashctl.c,v 1.7 2023/01/08 15:52:30 rillig Exp $");
+__RCSID("$NetBSD: flashctl.c,v 1.8 2023/01/08 15:55:25 rillig Exp $");
 
 #include 
 #include 
@@ -140,7 +140,7 @@ main(int argc, char **argv)
 		printf("\n");
 
 		/* TODO: humanize */
-		printf("Capacity %jd Mbytes, %jd pages, %ju bytes/page\n", 
+		printf("Capacity %jd Mbytes, %jd pages, %ju bytes/page\n",
 		(intmax_t)ip.ip_flash_size / 1024 / 1024,
 		(intmax_t)ip.ip_flash_size / ip.ip_page_size,
 		(intmax_t)ip.ip_page_size);



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:55:26 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: remove trailing whitespace

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:52:30 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: unexport local functions, add CVS ID

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.6 src/usr.sbin/flashctl/flashctl.c:1.7
--- src/usr.sbin/flashctl/flashctl.c:1.6	Sun Jan  8 15:49:51 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 15:52:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.6 2023/01/08 15:49:51 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.7 2023/01/08 15:52:30 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -31,6 +31,9 @@
  * SUCH DAMAGE.
  */
 
+#include 
+__RCSID("$NetBSD: flashctl.c,v 1.7 2023/01/08 15:52:30 rillig Exp $");
+
 #include 
 #include 
 #include 
@@ -45,8 +48,8 @@
 #include 
 
 
-void usage(void);
-int to_intmax(intmax_t *, const char *);
+static void usage(void);
+static int to_intmax(intmax_t *, const char *);
 
 int
 main(int argc, char **argv)



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:52:30 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: unexport local functions, add CVS ID

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:49:51 UTC 2023

Modified Files:
src/usr.sbin/flashctl: Makefile flashctl.c

Log Message:
flashctl: enable lint's strict bool mode

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/flashctl/Makefile
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:49:51 UTC 2023

Modified Files:
src/usr.sbin/flashctl: Makefile flashctl.c

Log Message:
flashctl: enable lint's strict bool mode

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/flashctl/Makefile
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/flashctl/Makefile
diff -u src/usr.sbin/flashctl/Makefile:1.2 src/usr.sbin/flashctl/Makefile:1.3
--- src/usr.sbin/flashctl/Makefile:1.2	Sun Feb 27 17:51:45 2011
+++ src/usr.sbin/flashctl/Makefile	Sun Jan  8 15:49:51 2023
@@ -1,9 +1,10 @@
-# $NetBSD: Makefile,v 1.2 2011/02/27 17:51:45 ahoka Exp $
+# $NetBSD: Makefile,v 1.3 2023/01/08 15:49:51 rillig Exp $
 
 SRCS=		flashctl.c
 
 PROG=		flashctl
 MAN=		flashctl.8
+LINTFLAGS+=	-T		# strict bool mode
 
 WARNS=		4
 

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.5 src/usr.sbin/flashctl/flashctl.c:1.6
--- src/usr.sbin/flashctl/flashctl.c:1.5	Sun Jan  8 15:37:56 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 15:49:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.5 2023/01/08 15:37:56 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.6 2023/01/08 15:49:51 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -72,29 +72,29 @@ main(int argc, char **argv)
 		err(EXIT_FAILURE, "can't open flash device");
 	}
 
-	if (!strcmp("erase", command)) {
+	if (strcmp("erase", command) == 0) {
 		struct flash_info_params ip;
 		struct flash_erase_params ep;
 
 		error = ioctl(fd, FLASH_GET_INFO, );
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLASH_GET_INFO");
 			goto out;
 		}
 
 		if (argc == 2) {
 			error = to_intmax(, argv[0]);
-			if (error) {
+			if (error != 0) {
 warnx("%s", strerror(error));
 goto out;
 			}
 			ep.ep_addr = n;
 
-			if (!strcmp("all", argv[1])) {
+			if (strcmp("all", argv[1]) == 0) {
 ep.ep_len = ip.ip_flash_size;
 			} else {
 error = to_intmax(, argv[1]);
-if (error) {
+if (error != 0) {
 	warnx("%s", strerror(error));
 	goto out;
 }
@@ -105,20 +105,20 @@ main(int argc, char **argv)
 			error = 1;
 			goto out;
 		}
-		
+
 		printf("Erasing %jx bytes starting from %jx\n",
-		(uintmax_t )ep.ep_len, (uintmax_t )ep.ep_addr);
-		
+		(uintmax_t)ep.ep_len, (uintmax_t)ep.ep_addr);
+
 		error = ioctl(fd, FLASH_ERASE_BLOCK, );
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLASH_ERASE_BLOCK");
 			goto out;
 		}
-	} else if (!strcmp("identify", command)) {
+	} else if (strcmp("identify", command) == 0) {
 		struct flash_info_params ip;
-		
+
 		error = ioctl(fd, FLASH_GET_INFO, );
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLASH_GET_INFO");
 			goto out;
 		}
@@ -138,23 +138,23 @@ main(int argc, char **argv)
 
 		/* TODO: humanize */
 		printf("Capacity %jd Mbytes, %jd pages, %ju bytes/page\n", 
-		(intmax_t )ip.ip_flash_size / 1024 / 1024,
-		(intmax_t )ip.ip_flash_size / ip.ip_page_size,
-		(intmax_t )ip.ip_page_size);
+		(intmax_t)ip.ip_flash_size / 1024 / 1024,
+		(intmax_t)ip.ip_flash_size / ip.ip_page_size,
+		(intmax_t)ip.ip_page_size);
 
 		if (ip.ip_flash_type == FLASH_TYPE_NAND) {
 			printf("Block size %jd Kbytes, %jd pages/block\n",
-			(intmax_t )ip.ip_erase_size / 1024,
-			(intmax_t )ip.ip_erase_size / ip.ip_page_size);
+			(intmax_t)ip.ip_erase_size / 1024,
+			(intmax_t)ip.ip_erase_size / ip.ip_page_size);
 		}
-	} else if (!strcmp("badblocks", command)) {
+	} else if (strcmp("badblocks", command) == 0) {
 		struct flash_info_params ip;
 		struct flash_badblock_params bbp;
 		flash_off_t addr;
 		bool hasbad = false;
 
 		error = ioctl(fd, FLASH_GET_INFO, );
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLASH_GET_INFO");
 			goto out;
 		}
@@ -164,9 +164,9 @@ main(int argc, char **argv)
 		addr = 0;
 		while (addr < ip.ip_flash_size) {
 			bbp.bbp_addr = addr;
-			
+
 			error = ioctl(fd, FLASH_BLOCK_ISBAD, );
-			if (error) {
+			if (error != 0) {
 warn("ioctl: FLASH_BLOCK_ISBAD");
 goto out;
 			}
@@ -184,7 +184,7 @@ main(int argc, char **argv)
 		} else {
 			printf("No bad blocks found.\n");
 		}
-	} else if (!strcmp("markbad", command)) {
+	} else if (strcmp("markbad", command) == 0) {
 		flash_off_t address;
 
 		/* TODO: maybe we should let the user specify
@@ -195,26 +195,26 @@ main(int argc, char **argv)
 			error = 1;
 			goto out;
 		}
-		
+
 		error = to_intmax(, argv[0]);
-		if (error) {
+		if (error != 0) {
 			warnx("%s", strerror(error));
 			goto out;
 		}
 
 		address = n;
-		
+
 		printf("Marking block 0x%jx as bad.\n",
-		(intmax_t )address);
+		(intmax_t)address);
 
 		error = ioctl(fd, FLASH_BLOCK_MARKBAD, );
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLASH_BLOCK_MARKBAD");
 			goto 

CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:37:56 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: fix error handling of integer arguments

Previously, flashctl accepted the command 'erase 0x 0x' as valid, even
though the numbers are not valid hex numbers.

Pointed out by lint, which complained about the wrong type conversion
for tolower, isxdigit and isdigit.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.4 src/usr.sbin/flashctl/flashctl.c:1.5
--- src/usr.sbin/flashctl/flashctl.c:1.4	Tue May 24 13:01:53 2011
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 15:37:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.4 2011/05/24 13:01:53 joerg Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.5 2023/01/08 15:37:56 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -229,12 +229,12 @@ to_intmax(intmax_t *num, const char *str
 	char *endptr;
 
 	errno = 0;
-	if (str[0] == '0' && tolower((int )str[1]) == 'x') {
-		if (!isxdigit((int )str[0]))
+	if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
+		if (!isxdigit((unsigned char)str[2]))
 			return EINVAL;
 		*num = strtoimax(str, , 16);
 	} else {
-		if (!isdigit((int )str[0]))
+		if (!isdigit((unsigned char)str[0]))
 			return EINVAL;
 		*num = strtoimax(str, , 10);
 	}



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:37:56 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: fix error handling of integer arguments

Previously, flashctl accepted the command 'erase 0x 0x' as valid, even
though the numbers are not valid hex numbers.

Pointed out by lint, which complained about the wrong type conversion
for tolower, isxdigit and isdigit.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/flashctl/flashctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.