From 7b4ddaeaa8dda27b5d63fc615c0cbecb870c9632 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Fri, 22 Nov 2019 22:32:20 +0100
Subject: [PATCH] <sys/types.h>: Get rid of udev_t.

In a time long long ago, dev_t was a pointer, which later became cdev_t
during the great cleanups, until it ended up being a uint32_t, just like
udev_t. See for example the definitions of __dev_t in <sys/stat.h>.

This commit cleans up further by removing the udev_t type, leaving just
the POSIX dev_t type for both kernel and userland. Put it inside a
_DEV_T_DECLARED to prepare for further cleanups in <sys/stat.h>.

Function names containing "udev" are not touched for now, as it will
require further inspection.
---
 sbin/sysctl/sysctl.8               |  8 ++++----
 sys/dev/disk/dm/dm.h               |  2 +-
 sys/dev/misc/snp/snp.c             |  2 +-
 sys/kern/kern_conf.c               | 16 ++++++++--------
 sys/kern/kern_proc.c               |  2 +-
 sys/kern/kern_shutdown.c           |  2 +-
 sys/kern/vfs_jops.c                |  2 +-
 sys/kern/vfs_journal.c             |  2 +-
 sys/sys/acct.h                     | 10 +---------
 sys/sys/conf.h                     |  2 +-
 sys/sys/devfs.h                    |  4 ++--
 sys/sys/param.h                    |  2 +-
 sys/sys/snoop.h                    | 10 ----------
 sys/sys/stat.h                     | 12 ++----------
 sys/sys/sysctl.h                   |  2 +-
 sys/sys/systm.h                    | 10 +++++-----
 sys/sys/types.h                    | 22 ++++++++--------------
 sys/sys/vfscache.h                 |  2 +-
 sys/vfs/devfs/devfs_core.c         |  8 ++++----
 sys/vfs/hammer/hammer.h            |  4 ++--
 sys/vfs/hammer/hammer_subs.c       |  4 ++--
 sys/vfs/isofs/cd9660/cd9660_node.h |  2 +-
 sys/vfs/nfs/nfs_serv.c             |  2 +-
 sys/vfs/nfs/nfs_subs.c             |  4 ++--
 sys/vfs/tmpfs/tmpfs_subr.c         |  2 +-
 usr.bin/fstat/fstat.c              | 16 ++++++++--------
 usr.bin/fstat/fstat.h              |  4 ++--
 usr.bin/fstat/hammer.c             |  4 ++--
 usr.bin/fstat/hammer2.c            |  4 ++--
 usr.bin/fstat/tmpfs.c              |  4 ++--
 30 files changed, 69 insertions(+), 101 deletions(-)

diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8
index 4775bd0b12..62b83b3ee5 100644
--- a/sbin/sysctl/sysctl.8
+++ b/sbin/sysctl/sysctl.8
@@ -28,7 +28,7 @@
 .\"	From: @(#)sysctl.8	8.1 (Berkeley) 6/6/93
 .\" $FreeBSD: src/sbin/sysctl/sysctl.8,v 1.23.2.17 2003/05/19 07:49:34 brueffer Exp $
 .\"
-.Dd October 18, 2019
+.Dd November 22, 2019
 .Dt SYSCTL 8
 .Os
 .Sh NAME
@@ -124,7 +124,7 @@ few bytes.
 The information available from
 .Nm
 consists of integers, strings, devices
-.Pq Vt udev_t ,
+.Pq Vt dev_t ,
 and opaque types.
 The
 .Nm
@@ -193,7 +193,7 @@ denote
 .It "kern.osreldate	string	no"
 .It "kern.bootfile	string	yes"
 .It "kern.corefile	string	yes"
-.It "kern.dumpdev	udev_t	yes"
+.It "kern.dumpdev	dev_t	yes"
 .It "kern.logsigexit	integer	yes"
 .It "vm.loadavg	struct	no"
 .It "hw.machine	string	no"
@@ -206,7 +206,7 @@ denote
 .It "hw.floatingpoint	integer	no"
 .It "hw.machine_arch	string	no"
 .It "hw.sensors.<xname>.<type><numt>	struct	no"
-.It "machdep.console_device	udev_t	no"
+.It "machdep.console_device	dev_t	no"
 .It "machdep.adjkerntz	integer	yes"
 .It "machdep.disable_rtc_set	integer	yes"
 .It "user.cs_path	string	no"
diff --git a/sys/dev/disk/dm/dm.h b/sys/dev/disk/dm/dm.h
index 2533905c5b..23674c21cd 100644
--- a/sys/dev/disk/dm/dm.h
+++ b/sys/dev/disk/dm/dm.h
@@ -113,7 +113,7 @@ typedef struct dm_table_head {
 typedef struct dm_pdev {
 	char name[DM_MAX_DEV_NAME];
 	char udev_name[DM_MAX_DEV_NAME];
-	udev_t udev;
+	dev_t udev;
 	struct partinfo pdev_pinfo; /* partinfo of the underlying device */
 
 	struct vnode *pdev_vnode;
diff --git a/sys/dev/misc/snp/snp.c b/sys/dev/misc/snp/snp.c
index 8c29e972fd..fbf4e2c420 100644
--- a/sys/dev/misc/snp/snp.c
+++ b/sys/dev/misc/snp/snp.c
@@ -538,7 +538,7 @@ snpioctl(struct dev_ioctl_args *ap)
 
 	switch (ap->a_cmd) {
 	case SNPSTTY:
-		tdev = udev2dev(*((udev_t *)ap->a_data), 0);
+		tdev = udev2dev(*((dev_t *)ap->a_data), 0);
 		if (tdev == NULL) {
 			lwkt_reltoken(&snp_token);
 			ret = snp_down(snp);
diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c
index f6efd1034b..40aaaed2f3 100644
--- a/sys/kern/kern_conf.c
+++ b/sys/kern/kern_conf.c
@@ -75,7 +75,7 @@ minor(cdev_t dev)
 }
 
 /*
- * Compatibility function with old udev_t format to convert the
+ * Compatibility function with old dev_t format to convert the
  * non-consecutive minor space into a consecutive minor space.
  */
 int
@@ -94,15 +94,15 @@ lminor(cdev_t dev)
 /*
  * Convert a device pointer to an old style device number.  Return NOUDEV
  * if the device is invalid or if the device (maj,min) cannot be converted
- * to an old style udev_t.
+ * to an old style dev_t.
  */
-udev_t
+dev_t
 dev2udev(cdev_t dev)
 {
 	if (dev == NULL)
 		return NOUDEV;
 
-	return (udev_t)dev->si_inode;
+	return (dev_t)dev->si_inode;
 }
 
 /*
@@ -115,7 +115,7 @@ dev2udev(cdev_t dev)
  * has not been registered.
  */
 cdev_t
-udev2dev(udev_t x, int b)
+udev2dev(dev_t x, int b)
 {
 	if (x == NOUDEV || b != 0)
 		return(NULL);
@@ -135,7 +135,7 @@ dev_is_good(cdev_t dev)
  * Various user device number extraction and conversion routines
  */
 int
-uminor(udev_t dev)
+uminor(dev_t dev)
 {
 	if (dev == NOUDEV)
 		return(-1);
@@ -143,14 +143,14 @@ uminor(udev_t dev)
 }
 
 int
-umajor(udev_t dev)
+umajor(dev_t dev)
 {
 	if (dev == NOUDEV)
 		return(-1);
 	return((dev & 0xff00) >> 8);
 }
 
-udev_t
+dev_t
 makeudev(int x, int y)
 {
 	if ((x & 0xffffff00) || (y & 0x0000ff00))
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 693b21a937..426b76fd83 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -1703,7 +1703,7 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
 				    p->p_session == NULL ||
 				    p->p_session->s_ttyp == NULL ||
 				    dev2udev(p->p_session->s_ttyp->t_dev) != 
-					(udev_t)name[0])
+					(dev_t)name[0])
 					continue;
 				break;
 
diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c
index 5bc6966f98..1deac33e51 100644
--- a/sys/kern/kern_shutdown.c
+++ b/sys/kern/kern_shutdown.c
@@ -715,7 +715,7 @@ static int
 sysctl_kern_dumpdev(SYSCTL_HANDLER_ARGS)
 {
 	int error;
-	udev_t ndumpdev;
+	dev_t ndumpdev;
 
 	ndumpdev = dev2udev(dumpdev);
 	error = sysctl_handle_opaque(oidp, &ndumpdev, sizeof ndumpdev, req);
diff --git a/sys/kern/vfs_jops.c b/sys/kern/vfs_jops.c
index 0c61c576e6..b730eddbfb 100644
--- a/sys/kern/vfs_jops.c
+++ b/sys/kern/vfs_jops.c
@@ -700,7 +700,7 @@ jrecord_undo_file(struct jrecord *jrec, struct vnode *vp, int jrflags,
 	if ((jrflags & JRUNDO_FLAGS) && attr.va_flags != VNOVAL)
 	    jrecord_leaf(jrec, JLEAF_FLAGS, &attr.va_flags, sizeof(attr.va_flags));
 	if ((jrflags & JRUNDO_UDEV) && attr.va_rmajor != VNOVAL) {
-	    udev_t rdev = makeudev(attr.va_rmajor, attr.va_rminor);
+	    dev_t rdev = makeudev(attr.va_rmajor, attr.va_rminor);
 	    jrecord_leaf(jrec, JLEAF_UDEV, &rdev, sizeof(rdev));
 	    jrecord_leaf(jrec, JLEAF_UMAJOR, &attr.va_rmajor, sizeof(attr.va_rmajor));
 	    jrecord_leaf(jrec, JLEAF_UMINOR, &attr.va_rminor, sizeof(attr.va_rminor));
diff --git a/sys/kern/vfs_journal.c b/sys/kern/vfs_journal.c
index 569f794abf..1381af561f 100644
--- a/sys/kern/vfs_journal.c
+++ b/sys/kern/vfs_journal.c
@@ -1302,7 +1302,7 @@ jrecord_write_vattr(struct jrecord *jrec, struct vattr *vat)
     if (vat->va_flags != VNOVAL)
 	jrecord_leaf(jrec, JLEAF_FLAGS, &vat->va_flags, sizeof(vat->va_flags));
     if (vat->va_rmajor != VNOVAL) {
-	udev_t rdev = makeudev(vat->va_rmajor, vat->va_rminor);
+	dev_t rdev = makeudev(vat->va_rmajor, vat->va_rminor);
 	jrecord_leaf(jrec, JLEAF_UDEV, &rdev, sizeof(rdev));
 	jrecord_leaf(jrec, JLEAF_UMAJOR, &vat->va_rmajor, sizeof(vat->va_rmajor));
 	jrecord_leaf(jrec, JLEAF_UMINOR, &vat->va_rminor, sizeof(vat->va_rminor));
diff --git a/sys/sys/acct.h b/sys/sys/acct.h
index bb6f8a80e3..8276068b44 100644
--- a/sys/sys/acct.h
+++ b/sys/sys/acct.h
@@ -33,7 +33,6 @@
  *
  *	@(#)acct.h	8.4 (Berkeley) 1/9/95
  * $FreeBSD: src/sys/sys/acct.h,v 1.12 1999/12/29 04:24:36 peter Exp $
- * $DragonFly: src/sys/sys/acct.h,v 1.4 2006/05/20 02:42:13 dillon Exp $
  */
 
 #ifndef _SYS_ACCT_H_
@@ -50,12 +49,6 @@
  */
 typedef u_int16_t comp_t;
 
-#ifdef _KERNEL
-#define __dev_t udev_t
-#else
-#define __dev_t dev_t
-#endif
-
 #define AC_COMM_LEN 16
 struct acct {
 	char	  ac_comm[AC_COMM_LEN];	/* command name */
@@ -67,7 +60,7 @@ struct acct {
 	gid_t	  ac_gid;		/* group id */
 	u_int16_t ac_mem;		/* average memory usage */
 	comp_t	  ac_io;		/* count of IO blocks */
-	__dev_t	  ac_tty;		/* controlling tty */
+	dev_t	  ac_tty;		/* controlling tty */
 
 #define	AFORK	0x01			/* forked but not exec'ed */
 #define	ASU	0x02			/* used super-user permissions */
@@ -76,7 +69,6 @@ struct acct {
 #define	AXSIG	0x10			/* killed by a signal */
 	u_int8_t  ac_flag;		/* accounting flags */
 };
-#undef __dev_t
 
 /*
  * 1/AHZ is the granularity of the data encoded in the comp_t fields.
diff --git a/sys/sys/conf.h b/sys/sys/conf.h
index 484198088d..f62130a117 100644
--- a/sys/sys/conf.h
+++ b/sys/sys/conf.h
@@ -176,7 +176,7 @@ void ldisc_deregister (int);
  * Swap device table
  */
 struct swdevt {
-	udev_t	sw_dev;			/* For quasibogus swapdev reporting */
+	dev_t	sw_dev;			/* For quasibogus swapdev reporting */
 	int	sw_flags;
 	int	sw_nblks;		/* Number of swap blocks on device */
 	int	sw_nused;		/* swap blocks used on device */
diff --git a/sys/sys/devfs.h b/sys/sys/devfs.h
index 5a01792407..d18566aaae 100644
--- a/sys/sys/devfs.h
+++ b/sys/sys/devfs.h
@@ -187,7 +187,7 @@ typedef struct devfs_msg {
 			void *resp;
 		} __m_resp;
 		struct {
-			udev_t	udev;
+			dev_t	udev;
 		} __m_udev;
 		struct {
 			cdev_t	cdev;
@@ -412,7 +412,7 @@ cdev_t devfs_new_cdev(struct dev_ops *, int, struct dev_ops *);
 void devfs_assume_knotes(cdev_t dev, struct kqinfo *kqi);
 
 cdev_t devfs_find_device_by_name(const char *, ...) __printf0like(1, 2);
-cdev_t devfs_find_device_by_udev(udev_t);
+cdev_t devfs_find_device_by_udev(dev_t);
 
 struct vnode *devfs_inode_to_vnode(struct mount *, ino_t);
 
diff --git a/sys/sys/param.h b/sys/sys/param.h
index a3f263cf25..dfdb638e6a 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -287,7 +287,7 @@
 
 #define CMASK	022		/* default file mask: S_IWGRP|S_IWOTH */
 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
-#define NOUDEV	(udev_t)(-1)	/* non-existent device */
+#define NOUDEV	(dev_t)(-1)	/* non-existent device */
 #define NOMAJ	256		/* non-existent device */
 #endif
 
diff --git a/sys/sys/snoop.h b/sys/sys/snoop.h
index f6dab9531f..a087ffd933 100644
--- a/sys/sys/snoop.h
+++ b/sys/sys/snoop.h
@@ -26,19 +26,9 @@
  * If ever type or  unit set to -1,snoop device
  * detached from its current tty.
  */
-
-#ifdef _KERNEL
-
-#define SNPSTTY       _IOW('T', 90, udev_t)
-#define SNPGTTY       _IOR('T', 89, udev_t)
-
-#else
-
 #define SNPSTTY       _IOW('T', 90, dev_t)
 #define SNPGTTY       _IOR('T', 89, dev_t)
 
-#endif
-
 /*
  * These values would be returned by FIONREAD ioctl
  * instead of number of characters in buffer in case
diff --git a/sys/sys/stat.h b/sys/sys/stat.h
index c6db2fc66f..44e40f0520 100644
--- a/sys/sys/stat.h
+++ b/sys/sys/stat.h
@@ -50,12 +50,6 @@
 #include <sys/_timespec.h>
 #endif
 
-#ifdef _KERNEL
-#define	__dev_t	udev_t
-#else
-#define	__dev_t	dev_t
-#endif
-
 /*
  * stat structure notes:
  *
@@ -64,12 +58,12 @@
 struct stat {
 	ino_t	  st_ino;		/* inode's number */
 	nlink_t	  st_nlink;		/* number of hard links */
-	__dev_t	  st_dev;		/* inode's device */
+	dev_t	  st_dev;		/* inode's device */
 	mode_t	  st_mode;		/* inode protection mode */
 	uint16_t  st_padding1;
 	uid_t	  st_uid;		/* user ID of the file's owner */
 	gid_t	  st_gid;		/* group ID of the file's group */
-	__dev_t	  st_rdev;		/* device type */
+	dev_t	  st_rdev;		/* device type */
 	struct	timespec st_atim;	/* time of last access */
 	struct	timespec st_mtim;	/* time of last data modification */
 	struct	timespec st_ctim;	/* time of last file status change */
@@ -86,8 +80,6 @@ struct stat {
 /*#define _ST_FSMID_PRESENT_*/
 #define	_ST_FLAGS_PRESENT_
 
-#undef __dev_t
-
 #define	st_atime st_atim.tv_sec
 #define	st_mtime st_mtim.tv_sec
 #define	st_ctime st_ctim.tv_sec
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index cb9bfc7ebc..7b3dd2e3b6 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -502,7 +502,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
 #define	KERN_BOOTFILE		26	/* string: name of booted kernel */
 #define	KERN_MAXFILESPERPROC	27	/* int: max open files per proc */
 #define	KERN_MAXPROCPERUID 	28	/* int: max processes per uid */
-#define KERN_DUMPDEV		29	/* udev_t: device to dump on */
+#define	KERN_DUMPDEV		29	/* dev_t: device to dump on */
 #define	KERN_IPC		30	/* node: anything related to IPC */
 #define	KERN_DUMMY		31	/* unused */
 #define	KERN_PS_STRINGS		32	/* int: address of PS_STRINGS */
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index be87a5d6ed..8e222a0de8 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -419,11 +419,11 @@ void	wakeup_end_delayed(void);
 
 int major(cdev_t x);
 int minor(cdev_t x);
-udev_t dev2udev(cdev_t x);
-cdev_t udev2dev(udev_t x, int b);
-int uminor(udev_t dev);
-int umajor(udev_t dev);
-udev_t makeudev(int x, int y);
+dev_t dev2udev(cdev_t x);
+cdev_t udev2dev(dev_t x, int b);
+int uminor(dev_t dev);
+int umajor(dev_t dev);
+dev_t makeudev(int x, int y);
 
 /*
  * Unit number allocation API. (kern/subr_unit.c)
diff --git a/sys/sys/types.h b/sys/sys/types.h
index b6576d17f3..152fade107 100644
--- a/sys/sys/types.h
+++ b/sys/sys/types.h
@@ -72,6 +72,10 @@ typedef	volatile char *	v_caddr_t;	/* core address, pointer to volatile */
 typedef	__int32_t	daddr_t;	/* disk address */
 typedef	__uint32_t	u_daddr_t;	/* unsigned disk address */
 typedef	__uint32_t	fixpt_t;	/* fixed point number */
+#ifndef _DEV_T_DECLARED
+typedef	__uint32_t	dev_t;		/* device number */
+#define	_DEV_T_DECLARED
+#endif
 #ifndef _FSBLKCNT_T_DECLARED
 typedef	__uint64_t	fsblkcnt_t;	/* filesystem block count */
 #define	_FSBLKCNT_T_DECLARED
@@ -135,25 +139,16 @@ typedef	__uint32_t	uid_t;		/* user id */
 typedef	__uint32_t	useconds_t;	/* microseconds (unsigned) */
 
 /*
- * The kernel now uses only udev_t or cdev_t.  Userland uses dev_t.
+ * The kernel uses dev_t or cdev_t.  Userland uses dev_t.
  * Virtual kernel builds needs dev_t in order to include userland headers.
  */
 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
 struct cdev;
 typedef	struct cdev	*cdev_t;
-typedef	u_int32_t	udev_t;		/* device number */
 typedef	u_int64_t	uoff_t;		/* uio offset */
-#endif /* _KERNEL) || _KERNEL_STRUCTURES */
-
-#ifdef _KERNEL
-typedef	udev_t		dev_t;		/* device number */
-#endif /* _KERNEL */
-
-#ifndef _KERNEL
-typedef	u_int32_t	dev_t;		/* device number */
-#define	udev_t dev_t
+#endif /* _KERNEL || _KERNEL_STRUCTURES */
 
-#if __BSD_VISIBLE
+#if __BSD_VISIBLE && !defined(_KERNEL)
 /*
  * minor() gives a cookie instead of an index since we don't want to
  * change the meanings of bits 0-15 or waste time and space shifting
@@ -162,8 +157,7 @@ typedef	u_int32_t	dev_t;		/* device number */
 #define	major(x)	((int)(((u_int)(x) >> 8)&0xff)) /* major number */
 #define	minor(x)	((int)((x)&0xffff00ff))         /* minor number */
 #define	makedev(x,y)	((dev_t)(((x) << 8) | (y)))     /* create dev_t */
-#endif /* __BSD_VISIBLE */
-#endif /* !_KERNEL */
+#endif /* __BSD_VISIBLE && !_KERNEL */
 
 #ifndef _CLOCK_T_DECLARED
 #define	_CLOCK_T_DECLARED
diff --git a/sys/sys/vfscache.h b/sys/sys/vfscache.h
index c0b9ee512d..7d1d6c434d 100644
--- a/sys/sys/vfscache.h
+++ b/sys/sys/vfscache.h
@@ -123,7 +123,7 @@ struct vattr {
 	u_short		va_mode;	/* files access mode and type */
 	uid_t		va_uid;		/* owner user id */
 	gid_t		va_gid;		/* owner group id */
-	udev_t		va_fsid;	/* file system id */
+	dev_t		va_fsid;	/* file system id */
 	ino_t		va_fileid;	/* file id */
 	u_quad_t	va_size;	/* file size in bytes */
 	long		va_blocksize;	/* blocksize preferred for i/o */
diff --git a/sys/vfs/devfs/devfs_core.c b/sys/vfs/devfs/devfs_core.c
index 9ffe7694dd..350ad82f5c 100644
--- a/sys/vfs/devfs/devfs_core.c
+++ b/sys/vfs/devfs/devfs_core.c
@@ -944,7 +944,7 @@ devfs_find_device_by_name(const char *fmt, ...)
  * the relevant details to the devfs core and returns the answer.
  */
 cdev_t
-devfs_find_device_by_udev(udev_t udev)
+devfs_find_device_by_udev(dev_t udev)
 {
 	cdev_t found = NULL;
 	devfs_msg_t msg;
@@ -1668,7 +1668,7 @@ devfs_find_device_by_udev_worker(devfs_msg_t devfs_msg)
 	cdev_t found = NULL;
 
 	TAILQ_FOREACH_MUTABLE(dev, &devfs_dev_list, link, dev1) {
-		if (((udev_t)dev->si_inode) == devfs_msg->mdv_udev) {
+		if (((dev_t)dev->si_inode) == devfs_msg->mdv_udev) {
 			found = dev;
 			break;
 		}
@@ -2768,11 +2768,11 @@ devfs_uninit(void)
 static int
 devfs_sysctl_devname_helper(SYSCTL_HANDLER_ARGS)
 {
-	udev_t 	udev;
+	dev_t 	udev;
 	cdev_t	found;
 	int		error;
 
-	if ((error = SYSCTL_IN(req, &udev, sizeof(udev_t))))
+	if ((error = SYSCTL_IN(req, &udev, sizeof(dev_t))))
 		return (error);
 
 	devfs_debug(DEVFS_DEBUG_DEBUG,
diff --git a/sys/vfs/hammer/hammer.h b/sys/vfs/hammer/hammer.h
index e7f6df151a..7ef27ffd49 100644
--- a/sys/vfs/hammer/hammer.h
+++ b/sys/vfs/hammer/hammer.h
@@ -238,7 +238,7 @@ typedef struct hammer_pseudofs_inmem {
 	uint32_t		localization;
 	hammer_tid_t		create_tid;
 	int			flags;
-	udev_t			fsid_udev;
+	dev_t			fsid_udev;
 	struct hammer_pseudofs_data pfsd;
 } *hammer_pseudofs_inmem_t;
 
@@ -1393,7 +1393,7 @@ int hammer_recover_stage2(hammer_mount_t hmp, hammer_volume_t rootvol);
 void hammer_recover_flush_buffers(hammer_mount_t hmp,
 			hammer_volume_t root_volume, int final);
 
-udev_t hammer_fsid_to_udev(hammer_uuid_t *uuid);
+dev_t hammer_fsid_to_udev(hammer_uuid_t *uuid);
 
 
 int hammer_blocksize(int64_t file_offset);
diff --git a/sys/vfs/hammer/hammer_subs.c b/sys/vfs/hammer/hammer_subs.c
index 1bae2d3d76..4d9f087cec 100644
--- a/sys/vfs/hammer/hammer_subs.c
+++ b/sys/vfs/hammer/hammer_subs.c
@@ -1128,12 +1128,12 @@ hammer_blockdemarc(int64_t file_offset1, int64_t file_offset2)
 	      (intmax_t)file_offset1, (intmax_t)file_offset2);
 }
 
-udev_t
+dev_t
 hammer_fsid_to_udev(hammer_uuid_t *uuid)
 {
 	uint32_t crc;
 
 	crc = crc32(uuid, sizeof(*uuid));
-	return((udev_t)crc);
+	return((dev_t)crc);
 }
 
diff --git a/sys/vfs/isofs/cd9660/cd9660_node.h b/sys/vfs/isofs/cd9660/cd9660_node.h
index 0348c55529..4843983c2a 100644
--- a/sys/vfs/isofs/cd9660/cd9660_node.h
+++ b/sys/vfs/isofs/cd9660/cd9660_node.h
@@ -54,7 +54,7 @@ typedef	struct	{
 	uid_t		iso_uid;	/* owner user id */
 	gid_t		iso_gid;	/* owner group id */
 	short		iso_links;	/* links of file */
-	udev_t		iso_rdev;	/* Major/Minor number for special */
+	dev_t		iso_rdev;	/* Major/Minor number for special */
 } ISO_RRIP_INODE;
 
 
diff --git a/sys/vfs/nfs/nfs_serv.c b/sys/vfs/nfs/nfs_serv.c
index 4e6bac22b4..1f0ff3ddbc 100644
--- a/sys/vfs/nfs/nfs_serv.c
+++ b/sys/vfs/nfs/nfs_serv.c
@@ -1600,7 +1600,7 @@ nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
 	u_int32_t *tl;
 	struct nlookupdata nd;
 	int error = 0, len, tsize, dirfor_ret = 1, diraft_ret = 1;
-	udev_t rdev = NOUDEV;
+	dev_t rdev = NOUDEV;
 	caddr_t cp;
 	int how, exclusive_flag = 0;
 	struct vnode *dirp;
diff --git a/sys/vfs/nfs/nfs_subs.c b/sys/vfs/nfs/nfs_subs.c
index 40206eff02..ea47c38c01 100644
--- a/sys/vfs/nfs/nfs_subs.c
+++ b/sys/vfs/nfs/nfs_subs.c
@@ -662,7 +662,7 @@ nfs_loadattrcache(struct vnode *vp, struct mbuf **mdp, caddr_t *dposp,
 	caddr_t cp2;
 	int error = 0;
 	int rmajor, rminor;
-	udev_t rdev;
+	dev_t rdev;
 	struct mbuf *md;
 	enum vtype vtyp;
 	u_short vmode;
@@ -712,7 +712,7 @@ nfs_loadattrcache(struct vnode *vp, struct mbuf **mdp, caddr_t *dposp,
 		/*
 		 * Really ugly NFSv2 kludge.
 		 */
-		if (vtyp == VCHR && rdev == (udev_t)0xffffffff)
+		if (vtyp == VCHR && rdev == (dev_t)0xffffffff)
 			vtyp = VFIFO;
 	}
 
diff --git a/sys/vfs/tmpfs/tmpfs_subr.c b/sys/vfs/tmpfs/tmpfs_subr.c
index 00dba615b9..8634762122 100644
--- a/sys/vfs/tmpfs/tmpfs_subr.c
+++ b/sys/vfs/tmpfs/tmpfs_subr.c
@@ -97,7 +97,7 @@ tmpfs_alloc_node(struct tmpfs_mount *tmp, enum vtype type,
 {
 	struct tmpfs_node *nnode;
 	struct timespec ts;
-	udev_t rdev;
+	dev_t rdev;
 
 	KKASSERT(IFF(type == VLNK, target != NULL));
 	KKASSERT(IFF(type == VBLK || type == VCHR, rmajor != VNOVAL));
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index c1af08631b..defdac1cf3 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -603,8 +603,8 @@ ufs_filestat(struct vnode *vp, struct filestat *fsp)
 		return 0;
 	}
 	/*
-	 * The st_dev from stat(2) is a udev_t. These kernel structures
-	 * contain dev_t structures. We need to convert to udev to make
+	 * The st_dev from stat(2) is a dev_t. These kernel structures
+	 * contain cdev_t structures. We need to convert to udev to make
 	 * comparisons
 	 */
 	fsp->fsid = fstat_dev2udev(inode.i_dev);
@@ -922,11 +922,11 @@ socktrans(struct socket *sock, int i)
 
 
 /*
- * Read the cdev structure in the kernel (as pointed to by a dev_t)
- * in order to work out the associated udev_t
+ * Read the cdev structure in the kernel (as pointed to by a cdev_t)
+ * in order to work out the associated dev_t
  */
-udev_t
-fstat_dev2udev(void *dev)
+dev_t
+fstat_dev2udev(cdev_t dev)
 {
 	struct cdev si;
 
@@ -937,12 +937,12 @@ fstat_dev2udev(void *dev)
 		}
 		return((si.si_umajor << 8) | si.si_uminor);
 	} else {
-		dprintf(stderr, "can't convert dev_t %p to a udev_t\n", dev);
+		dprintf(stderr, "can't convert cdev_t %p to a dev_t\n", dev);
 		return NOUDEV;
 	}
 }
 
-udev_t
+dev_t
 makeudev(int x, int y)
 {
         if ((x & 0xffffff00) || (y & 0x0000ff00))
diff --git a/usr.bin/fstat/fstat.h b/usr.bin/fstat/fstat.h
index 963a3fc3d7..a099fcfcf3 100644
--- a/usr.bin/fstat/fstat.h
+++ b/usr.bin/fstat/fstat.h
@@ -78,8 +78,8 @@ extern kvm_t *kd;
 extern int vflg;
 extern int Pid;
 
-udev_t fstat_dev2udev(void *);
-udev_t makeudev(int, int);
+dev_t fstat_dev2udev(cdev_t);
+dev_t makeudev(int, int);
 
 /* Additional filesystem types */
 int ext2fs_filestat(struct vnode *, struct filestat *);
diff --git a/usr.bin/fstat/hammer.c b/usr.bin/fstat/hammer.c
index 95c9f4a254..99efc4e82a 100644
--- a/usr.bin/fstat/hammer.c
+++ b/usr.bin/fstat/hammer.c
@@ -29,6 +29,8 @@
  * SUCH DAMAGE.
  */
 
+#define _KERNEL_STRUCTURES
+
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -36,12 +38,10 @@
 #include <kvm.h>
 #include <stdio.h>
 
-#define _KERNEL_STRUCTURES
 #include <sys/vnode.h>
 #include <sys/mount.h>
 #include <stddef.h>
 #include <vfs/hammer/hammer.h>
-#undef _KERNEL_STRUCTURES
 
 #include "fstat.h"
 
diff --git a/usr.bin/fstat/hammer2.c b/usr.bin/fstat/hammer2.c
index 26919777d4..7d31b22189 100644
--- a/usr.bin/fstat/hammer2.c
+++ b/usr.bin/fstat/hammer2.c
@@ -29,6 +29,8 @@
  * SUCH DAMAGE.
  */
 
+#define _KERNEL_STRUCTURES
+
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -36,13 +38,11 @@
 #include <kvm.h>
 #include <stdio.h>
 
-#define _KERNEL_STRUCTURES
 #include <sys/vnode.h>
 #include <sys/mount.h>
 #include <stddef.h>
 #include <vfs/hammer2/hammer2.h>
 #include <vfs/hammer2/hammer2_disk.h>
-#undef _KERNEL_STRUCTURES
 
 #include "fstat.h"
 
diff --git a/usr.bin/fstat/tmpfs.c b/usr.bin/fstat/tmpfs.c
index 6e8b60df56..0a08a15a27 100644
--- a/usr.bin/fstat/tmpfs.c
+++ b/usr.bin/fstat/tmpfs.c
@@ -29,6 +29,8 @@
  * SUCH DAMAGE.
  */
 
+#define _KERNEL_STRUCTURES
+
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -36,10 +38,8 @@
 #include <kvm.h>
 #include <stdio.h>
 
-#define _KERNEL_STRUCTURES
 #include <sys/vnode.h>
 #include <vfs/tmpfs/tmpfs.h>
-#undef _KERNEL_STRUCTURES
 
 #include "fstat.h"
 
-- 
2.23.0

