git: 40f022975df9 - stable/13 - Rewrite function definitions with identifier lists.

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Thu, 30 Mar 2023 04:32:40 UTC
The branch stable/13 has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=40f022975df948c071f8bd1736ba9078df8ef6b8

commit 40f022975df948c071f8bd1736ba9078df8ef6b8
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2023-03-22 22:57:26 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2023-03-30 04:32:32 +0000

    Rewrite function definitions with identifier lists.
    
    A few functions snuck in with K&R style definitions.
    
    Also add some missing memory frees.
    
    (cherry picked from commit e5d0d1c5fbbc0ce44fdc720a35b499056fe60b06)
---
 sbin/dump/tape.c                 | 54 +++++++++++++++++++++++++---------------
 sbin/fsck_ffs/dir.c              |  5 ++++
 sbin/fsck_ffs/fsutil.c           |  6 ++---
 sbin/fsck_ffs/inode.c            | 20 +++++----------
 sbin/fsck_ffs/pass2.c            |  1 +
 sbin/fsck_ffs/suj.c              |  4 +--
 tools/diag/prtblknos/main.c      |  4 +--
 tools/diag/prtblknos/prtblknos.c | 26 +++++--------------
 8 files changed, 57 insertions(+), 63 deletions(-)

diff --git a/sbin/dump/tape.c b/sbin/dump/tape.c
index 45ad0ee50487..c123f7fa9404 100644
--- a/sbin/dump/tape.c
+++ b/sbin/dump/tape.c
@@ -74,7 +74,8 @@ static	long blocksthisvol;	/* number of blocks on current output file */
 static	char *nexttape;
 static	FILE *popenfp = NULL;
 
-static	int atomic(ssize_t (*)(), int, char *, int);
+static	int atomic_read(int, void *, int);
+static	int atomic_write(int, const void *, int);
 static	void worker(int, int);
 static	void create_workers(void);
 static	void flushtape(void);
@@ -236,7 +237,7 @@ flushtape(void)
 
 	wp->req[trecno].count = 0;			/* Sentinel */
 
-	if (atomic(write, wp->fd, (char *)wp->req, siz) != siz)
+	if (atomic_write(wp->fd, (const void *)wp->req, siz) != siz)
 		quit("error writing command pipe: %s\n", strerror(errno));
 	wp->sent = 1; /* we sent a request, read the response later */
 
@@ -247,7 +248,7 @@ flushtape(void)
 
 	/* Read results back from next worker */
 	if (wp->sent) {
-		if (atomic(read, wp->fd, (char *)&got, sizeof got)
+		if (atomic_read(wp->fd, (void *)&got, sizeof got)
 		    != sizeof got) {
 			perror("  DUMP: error reading command pipe in master");
 			dumpabort(0);
@@ -264,8 +265,8 @@ flushtape(void)
 			 */
 			for (i = 0; i < WORKERS; i++) {
 				if (workers[i].sent) {
-					if (atomic(read, workers[i].fd,
-					    (char *)&got, sizeof got)
+					if (atomic_read(workers[i].fd,
+					    (void *)&got, sizeof got)
 					    != sizeof got) {
 						perror("  DUMP: error reading command pipe in master");
 						dumpabort(0);
@@ -322,7 +323,7 @@ trewind(void)
 		 * fixme: punt for now.
 		 */
 		if (workers[f].sent) {
-			if (atomic(read, workers[f].fd, (char *)&got, sizeof got)
+			if (atomic_read(workers[f].fd, (void *)&got, sizeof got)
 			    != sizeof got) {
 				perror("  DUMP: error reading command pipe in master");
 				dumpabort(0);
@@ -446,7 +447,7 @@ rollforward(void)
 			lastspclrec = savedtapea - 1;
 		}
 		size = (char *)ntb - (char *)q;
-		if (atomic(write, wp->fd, (char *)q, size) != size) {
+		if (atomic_write(wp->fd, (const void *)q, size) != size) {
 			perror("  DUMP: error writing command pipe");
 			dumpabort(0);
 		}
@@ -486,7 +487,7 @@ rollforward(void)
 	 * worked ok, otherwise the tape is much too short!
 	 */
 	if (wp->sent) {
-		if (atomic(read, wp->fd, (char *)&got, sizeof got)
+		if (atomic_read(wp->fd, (void *)&got, sizeof got)
 		    != sizeof got) {
 			perror("  DUMP: error reading command pipe in master");
 			dumpabort(0);
@@ -676,8 +677,7 @@ dumpabort(int signo __unused)
 }
 
 void
-Exit(status)
-	int status;
+Exit(int status)
 {
 
 #ifdef TDEBUG
@@ -735,8 +735,8 @@ create_workers(void)
 	}
 
 	for (i = 0; i < WORKERS; i++)
-		(void) atomic(write, workers[i].fd,
-			      (char *) &workers[(i + 1) % WORKERS].pid,
+		(void) atomic_write(workers[i].fd,
+			      (const void *) &workers[(i + 1) % WORKERS].pid,
 		              sizeof workers[0].pid);
 
 	master = 0;
@@ -777,7 +777,7 @@ worker(int cmd, int worker_number)
 	/*
 	 * Need the pid of the next worker in the loop...
 	 */
-	if ((nread = atomic(read, cmd, (char *)&nextworker, sizeof nextworker))
+	if ((nread = atomic_read(cmd, (void *)&nextworker, sizeof nextworker))
 	    != sizeof nextworker) {
 		quit("master/worker protocol botched - didn't get pid of next worker.\n");
 	}
@@ -785,7 +785,7 @@ worker(int cmd, int worker_number)
 	/*
 	 * Get list of blocks to dump, read the blocks into tape buffer
 	 */
-	while ((nread = atomic(read, cmd, (char *)wp->req, reqsiz)) == reqsiz) {
+	while ((nread = atomic_read(cmd, (void *)wp->req, reqsiz)) == reqsiz) {
 		struct req *p = wp->req;
 
 		for (trecno = 0; trecno < ntrec;
@@ -794,8 +794,8 @@ worker(int cmd, int worker_number)
 				blkread(p->dblk, wp->tblock[trecno],
 					p->count * TP_BSIZE);
 			} else {
-				if (p->count != 1 || atomic(read, cmd,
-				    (char *)wp->tblock[trecno],
+				if (p->count != 1 || atomic_read(cmd,
+				    (void *)wp->tblock[trecno],
 				    TP_BSIZE) != TP_BSIZE)
 				       quit("master/worker protocol botched.\n");
 			}
@@ -858,7 +858,8 @@ worker(int cmd, int worker_number)
 			 * pass size of write back to master
 			 * (for EOT handling)
 			 */
-			(void) atomic(write, cmd, (char *)&size, sizeof size);
+			(void)atomic_write(cmd, (const void *)&size,
+			    sizeof size);
 		}
 
 		/*
@@ -873,15 +874,28 @@ worker(int cmd, int worker_number)
 
 /*
  * Since a read from a pipe may not return all we asked for,
- * or a write may not write all we ask if we get a signal,
  * loop until the count is satisfied (or error).
  */
 static int
-atomic(ssize_t (*func)(), int fd, char *buf, int count)
+atomic_read(int fd, void *buf, int count)
 {
 	int got, need = count;
 
-	while ((got = (*func)(fd, buf, need)) > 0 && (need -= got) > 0)
+	while ((got = read(fd, buf, need)) > 0 && (need -= got) > 0)
+		buf += got;
+	return (got < 0 ? got : count - need);
+}
+
+/*
+ * Since a write to a pipe may not write all we ask if we get a signal,
+ * loop until the count is satisfied (or error).
+ */
+static int
+atomic_write(int fd, const void *buf, int count)
+{
+	int got, need = count;
+
+	while ((got = write(fd, buf, need)) > 0 && (need -= got) > 0)
 		buf += got;
 	return (got < 0 ? got : count - need);
 }
diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c
index 18229ab96fb6..64e477c66ed8 100644
--- a/sbin/fsck_ffs/dir.c
+++ b/sbin/fsck_ffs/dir.c
@@ -525,6 +525,7 @@ linkup(ino_t orphan, ino_t parentdir, char *name)
 			}
 		}
 		irelse(&ip);
+		free(idesc.id_name);
 		if (lfdir == 0) {
 			pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY");
 			printf("\n\n");
@@ -621,6 +622,7 @@ changeino(ino_t dir, const char *name, ino_t newnum)
 	idesc.id_parent = newnum;	/* new value for name */
 	ginode(dir, &ip);
 	error = ckinode(ip.i_dp, &idesc);
+	free(idesc.id_name);
 	irelse(&ip);
 	return (error);
 }
@@ -655,15 +657,18 @@ makeentry(ino_t parent, ino_t ino, const char *name)
 	}
 	if ((ckinode(dp, &idesc) & ALTERED) != 0) {
 		irelse(&ip);
+		free(idesc.id_name);
 		return (1);
 	}
 	getpathname(pathbuf, parent, parent);
 	if (expanddir(&ip, pathbuf) == 0) {
 		irelse(&ip);
+		free(idesc.id_name);
 		return (0);
 	}
 	retval = ckinode(dp, &idesc) & ALTERED;
 	irelse(&ip);
+	free(idesc.id_name);
 	return (retval);
 }
 
diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c
index d8842e7d41f2..44b3e50da012 100644
--- a/sbin/fsck_ffs/fsutil.c
+++ b/sbin/fsck_ffs/fsutil.c
@@ -1162,9 +1162,7 @@ allocblk(long startcg, long frags,
 }
 
 ufs2_daddr_t
-std_checkblkavail(blkno, frags)
-	ufs2_daddr_t blkno;
-	long frags;
+std_checkblkavail(ufs2_daddr_t blkno, long frags)
 {
 	struct bufarea *cgbp;
 	struct cg *cgp;
@@ -1278,9 +1276,11 @@ getpathname(char *namebuf, ino_t curdir, ino_t ino)
 		ginode(ino, &ip);
 		if ((ckinode(ip.i_dp, &idesc) & FOUND) == 0) {
 			irelse(&ip);
+			free(idesc.id_name);
 			break;
 		}
 		irelse(&ip);
+		free(idesc.id_name);
 	namelookup:
 		idesc.id_number = idesc.id_parent;
 		idesc.id_parent = ino;
diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c
index 057d49a1ea18..947e5e0cbc08 100644
--- a/sbin/fsck_ffs/inode.c
+++ b/sbin/fsck_ffs/inode.c
@@ -798,12 +798,8 @@ snapclean(struct inodesc *idesc)
  * must always have been allocated from a BLK_NOCOPY location.
  */
 int
-snapblkfree(fs, bno, size, inum, checkblkavail)
-	struct fs *fs;
-	ufs2_daddr_t bno;
-	long size;
-	ino_t inum;
-	ufs2_daddr_t (*checkblkavail)(ufs2_daddr_t blkno, long frags);
+snapblkfree(struct fs *fs, ufs2_daddr_t bno, long size, ino_t inum,
+	ufs2_daddr_t (*checkblkavail)(ufs2_daddr_t blkno, long frags))
 {
 	union dinode *dp;
 	struct inode ip;
@@ -930,10 +926,8 @@ snapblkfree(fs, bno, size, inum, checkblkavail)
  * block. Here we need to check each block in the buffer.
  */
 void
-copyonwrite(fs, bp, checkblkavail)
-	struct fs *fs;
-	struct bufarea *bp;
-	ufs2_daddr_t (*checkblkavail)(ufs2_daddr_t blkno, long frags);
+copyonwrite(struct fs *fs, struct bufarea *bp,
+	ufs2_daddr_t (*checkblkavail)(ufs2_daddr_t blkno, long frags))
 {
 	ufs2_daddr_t copyblkno;
 	long i, numblks;
@@ -953,10 +947,8 @@ copyonwrite(fs, bp, checkblkavail)
 }
 
 static void
-chkcopyonwrite(fs, copyblkno, checkblkavail)
-	struct fs *fs;
-	ufs2_daddr_t copyblkno;
-	ufs2_daddr_t (*checkblkavail)(ufs2_daddr_t blkno, long frags);
+chkcopyonwrite(struct fs *fs, ufs2_daddr_t copyblkno,
+	ufs2_daddr_t (*checkblkavail)(ufs2_daddr_t blkno, long frags))
 {
 	struct inode ip;
 	union dinode *dp;
diff --git a/sbin/fsck_ffs/pass2.c b/sbin/fsck_ffs/pass2.c
index 4e17863ef04c..abe14549e6f4 100644
--- a/sbin/fsck_ffs/pass2.c
+++ b/sbin/fsck_ffs/pass2.c
@@ -602,6 +602,7 @@ fix_extraneous(struct inoinfo *inp, struct inodesc *idesc)
 		if ((ckinode(ip.i_dp, &dotdesc) & FOUND))
 			inp->i_dotdot = dotdesc.id_parent;
 		irelse(&ip);
+		free(dotdesc.id_name);
 	}
 	/*
 	 * We have the previously found old name (inp->i_parent) and the
diff --git a/sbin/fsck_ffs/suj.c b/sbin/fsck_ffs/suj.c
index e9f5bbd421b1..a1d624392fcf 100644
--- a/sbin/fsck_ffs/suj.c
+++ b/sbin/fsck_ffs/suj.c
@@ -382,9 +382,7 @@ blk_isindir(ufs2_daddr_t blk, ino_t ino, ufs_lbn_t lbn)
  * they will only have usable blocks in them.
  */
 ufs2_daddr_t
-suj_checkblkavail(blkno, frags)
-	ufs2_daddr_t blkno;
-	long frags;
+suj_checkblkavail(ufs2_daddr_t blkno, long frags)
 {
 	struct bufarea *cgbp;
 	struct cg *cgp;
diff --git a/tools/diag/prtblknos/main.c b/tools/diag/prtblknos/main.c
index 25a717760922..1535755ea52e 100644
--- a/tools/diag/prtblknos/main.c
+++ b/tools/diag/prtblknos/main.c
@@ -44,9 +44,7 @@ void prtblknos(struct fs *fs, union dinode *dp);
 struct uufsd disk;
 
 int
-main(argc, argv)
-	int argc;
-	char *argv[];
+main(int argc, char *argv[])
 {
 	union dinodep dp;
 	struct fs *fs;
diff --git a/tools/diag/prtblknos/prtblknos.c b/tools/diag/prtblknos/prtblknos.c
index ae53471156a6..d6135f70eb46 100644
--- a/tools/diag/prtblknos/prtblknos.c
+++ b/tools/diag/prtblknos/prtblknos.c
@@ -53,9 +53,7 @@ static void  indirprt(struct fs *, int, ufs_lbn_t, ufs_lbn_t, ufs2_daddr_t,
 		ufs_lbn_t);
 
 void
-prtblknos(fs, dp)
-	struct fs *fs;
-	union dinode *dp;
+prtblknos(struct fs *fs, union dinode *dp)
 {
 	int i, mode, frags;
 	ufs_lbn_t lbn, lastlbn, len, blksperindir;
@@ -154,13 +152,8 @@ prtblknos(fs, dp)
 }
 
 static void
-indirprt(fs, level, blksperindir, lbn, blkno, lastlbn)
-	struct fs *fs;
-	int level;
-	ufs_lbn_t blksperindir;
-	ufs_lbn_t lbn;
-	ufs2_daddr_t blkno;
-	ufs_lbn_t lastlbn;
+indirprt(struct fs *fs, int level, ufs_lbn_t blksperindir, ufs_lbn_t lbn,
+	ufs2_daddr_t blkno, ufs_lbn_t lastlbn)
 {
 	char indir[MAXBSIZE];
 	ufs_lbn_t i, last;
@@ -209,10 +202,7 @@ indirprt(fs, level, blksperindir, lbn, blkno, lastlbn)
 }
 
 static const char *
-distance(fs, lastblk, firstblk)
-	struct fs *fs;
-	ufs2_daddr_t lastblk;
-	ufs2_daddr_t firstblk;
+distance(struct fs *fs, ufs2_daddr_t lastblk, ufs2_daddr_t firstblk)
 {
 	ufs2_daddr_t delta;
 	int firstcg, lastcg;
@@ -237,12 +227,8 @@ distance(fs, lastblk, firstblk)
 static const char *indirname[UFS_NIADDR] = { "First", "Second", "Third" };
 
 static void
-printblk(fs, lbn, blkno, numfrags, lastlbn)
-	struct fs *fs;
-	ufs_lbn_t lbn;
-	ufs2_daddr_t blkno;
-	int numfrags;
-	ufs_lbn_t lastlbn;
+printblk(struct fs *fs, ufs_lbn_t lbn, ufs2_daddr_t blkno, int numfrags,
+	ufs_lbn_t lastlbn)
 {
 	static int seq;
 	static ufs2_daddr_t totfrags, lastindirblk, lastblk, firstblk;