From 86339e7ef903f93dcf1e6fc2e63f296be9b3d606 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Mon, 25 Nov 2019 16:00:38 +0100
Subject: [PATCH] <sys/types.h>: Separate dev_t (world) and udev_t (kernel) a
 bit better.

---
 sys/cpu/x86_64/include/stdint.h | 1 +
 sys/kern/syscalls.master        | 2 +-
 sys/sys/acct.h                  | 7 -------
 sys/sys/conf.h                  | 2 +-
 sys/sys/kinfo.h                 | 2 +-
 sys/sys/stat.h                  | 8 --------
 sys/sys/sysproto.h              | 2 +-
 sys/sys/types.h                 | 9 ++-------
 sys/sys/vfscache.h              | 2 +-
 sys/sys/vnioctl.h               | 2 +-
 sys/vfs/hammer/hammer.h         | 2 +-
 sys/vfs/tmpfs/tmpfs.h           | 2 +-
 sys/vm/vm_param.h               | 2 +-
 usr.bin/fstat/fstat.h           | 4 ++--
 14 files changed, 14 insertions(+), 33 deletions(-)

diff --git a/sys/cpu/x86_64/include/stdint.h b/sys/cpu/x86_64/include/stdint.h
index 51c3d15942..2529f2d841 100644
--- a/sys/cpu/x86_64/include/stdint.h
+++ b/sys/cpu/x86_64/include/stdint.h
@@ -135,5 +135,6 @@ typedef __int32_t	__sig_atomic_t;	/* XXX */
 typedef __uint32_t	__socklen_t;
 typedef volatile int	__atomic_intr_t;
 typedef __int64_t	__rlim_t;
+typedef	__uint32_t	__dev_t;
 
 #endif /* _CPU_STDINT_H_ */
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index 1fe464f819..3d990f5b15 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -705,7 +705,7 @@
 524	STD	{ int mkdirat(int fd, char *path, mode_t mode); }
 525	STD	{ int mkfifoat(int fd, char *path, mode_t mode); }
 526	STD	{ int mknodat(int fd, char *path, mode_t mode, \
-				  dev_t dev); }
+				  __dev_t dev); }
 527	STD	{ int readlinkat(int fd, char *path, char *buf, \
 				  size_t bufsize); }
 528	STD	{ int symlinkat(char *path1, int fd, char *path2); }
diff --git a/sys/sys/acct.h b/sys/sys/acct.h
index bb6f8a80e3..00120af212 100644
--- a/sys/sys/acct.h
+++ b/sys/sys/acct.h
@@ -50,12 +50,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 */
@@ -76,7 +70,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..b3323a9b6f 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/kinfo.h b/sys/sys/kinfo.h
index 104110e66c..4f19e94ccc 100644
--- a/sys/sys/kinfo.h
+++ b/sys/sys/kinfo.h
@@ -188,7 +188,7 @@ struct kinfo_proc {
 	pid_t		kp_sid;		/* session id */
 	char		kp_login[roundup(MAXLOGNAME, sizeof(long))];
 					/* setlogin() name */
-	dev_t		kp_tdev;	/* controlling tty dev */
+	__dev_t		kp_tdev;	/* controlling tty dev */
 	pid_t		kp_tpgid;	/* tty process group id */
 	pid_t		kp_tsid;	/* tty session id */
 
diff --git a/sys/sys/stat.h b/sys/sys/stat.h
index c6db2fc66f..d46d59b454 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:
  *
@@ -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/sysproto.h b/sys/sys/sysproto.h
index 337dd2bf58..4af1811eaf 100644
--- a/sys/sys/sysproto.h
+++ b/sys/sys/sysproto.h
@@ -2168,7 +2168,7 @@ struct	mknodat_args {
 	int	fd;	char fd_[PAD_(int)];
 	char *	path;	char path_[PAD_(char *)];
 	mode_t	mode;	char mode_[PAD_(mode_t)];
-	dev_t	dev;	char dev_[PAD_(dev_t)];
+	__dev_t	dev;	char dev_[PAD_(__dev_t)];
 };
 struct	readlinkat_args {
 #ifdef _KERNEL
diff --git a/sys/sys/types.h b/sys/sys/types.h
index 29158798ff..40f6245202 100644
--- a/sys/sys/types.h
+++ b/sys/sys/types.h
@@ -141,17 +141,12 @@ typedef	__uint32_t	useconds_t;	/* microseconds (unsigned) */
 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
 struct cdev;
 typedef	struct cdev	*cdev_t;
-typedef	u_int32_t	udev_t;		/* device number */
+typedef	__dev_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
+typedef	__dev_t		dev_t;		/* device number */
 
 #if __BSD_VISIBLE
 /*
diff --git a/sys/sys/vfscache.h b/sys/sys/vfscache.h
index c0b9ee512d..226d759e52 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/sys/vnioctl.h b/sys/sys/vnioctl.h
index ee23edc16c..3deff74a10 100644
--- a/sys/sys/vnioctl.h
+++ b/sys/sys/vnioctl.h
@@ -79,7 +79,7 @@ struct vn_user {
         char    	vnu_file[PATH_MAX];	/* vn description */
 #define _VN_USER_SWAP	"swap"			/* indicates swap-backed vn */
 	union {
-	        dev_t   	dev;		/* vn device */
+	        __dev_t   	dev;		/* vn device */
 		u_int64_t	size;		/* size per vnu_secsize */
 	} data1;
 	union {
diff --git a/sys/vfs/hammer/hammer.h b/sys/vfs/hammer/hammer.h
index e7f6df151a..95ac9873b8 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;
 
diff --git a/sys/vfs/tmpfs/tmpfs.h b/sys/vfs/tmpfs/tmpfs.h
index b24e39d1b2..90e9288368 100644
--- a/sys/vfs/tmpfs/tmpfs.h
+++ b/sys/vfs/tmpfs/tmpfs.h
@@ -215,7 +215,7 @@ struct tmpfs_node {
 	/* misc data field for different tn_type node */
 	union {
 		/* Valid when tn_type == VBLK || tn_type == VCHR. */
-		dev_t			tn_rdev; /*int32_t ?*/
+		__dev_t			tn_rdev; /*int32_t ?*/
 
 		/* Valid when tn_type == VDIR. */
 		struct tn_dir {
diff --git a/sys/vm/vm_param.h b/sys/vm/vm_param.h
index f93c0d88d3..00acd1b4b3 100644
--- a/sys/vm/vm_param.h
+++ b/sys/vm/vm_param.h
@@ -115,7 +115,7 @@ struct xswdev {
 	size_t	xsw_size;
 	int	xsw_version;
 	int	xsw_flags;
-	dev_t	xsw_dev;
+	__dev_t	xsw_dev;
 	size_t	xsw_blksize;
 	size_t	xsw_nblks;
 	size_t	xsw_used;
diff --git a/usr.bin/fstat/fstat.h b/usr.bin/fstat/fstat.h
index 963a3fc3d7..cf701aa2b3 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(void *);
+dev_t makeudev(int, int);
 
 /* Additional filesystem types */
 int ext2fs_filestat(struct vnode *, struct filestat *);
-- 
2.23.0

