freebsd-dev/sys/fs/nfsclient
Bruce Evans ab35e1c71b Fix the encoding of major and minor numbers in 64-bit dev_t by restoring
the old encodings for the lower 16 and 32 bits and only using the
higher 32 bits for unusually large major and minor numbers.  This
change breaks compatibility with the previous encoding (which was only
used in -current).

Fix truncation to (essentially) 16-bit dev_t in newnfs v3.

Any encoding of device numbers gives an ABI, so it can't be changed
without translations for compatibility.  Extra bits give the much
larger complication that the translations need to compress into fewer
bits.  Fortunately, more than 32 bits are rarely needed, so
compression is rarely needed except for 16-bit linux dev_t where it
was always needed but never done.

The previous encoding moved the major number into the top 32 bits.
Almost no translation code handled this, so the major number was blindly
truncated away in most 32-bit encodings.  E.g., for ffs, mknod(8) with
major = 1 and minor = 2 gave dev_t = 0x10000002; ffs cannot represent
this and blindly truncated it to 2.  But if this mknod was run on any
released version of FreeBSD, it gives dev_t = 0x102.  ffs can represent
this, but in the previous encoding it was not decoded, giving major = 0,
minor = 0x102.

The presence of bugs was most obvious for exporting dev_t's from an
old system to -current, since bugs in newnfs augment them.  I fixed
oldnfs to support 32-bit dev_t in 1996 (r16634), but this regressed
to 16-bit dev_t in newnfs, first to the old 16-bit encoding and then
further in -current.  E.g., old ad0 with major = 234, minor = 0x10002
had the correct (major, minor) number on the wire, but newnfs truncated
this to (234, 2) and then the previous encoding shifted the major
number into oblivion as seen by ffs or old applications.

I first tried to fix this by translating on every ABI/API boundary, but
there are too many boundaries and too many sloppy translations by blind
truncation.  So use the old encoding for the low 32 bits so that sloppy
translations work no worse than before provided the high 32 bits are
not set.  Add some error checking for when bits are lost.  Keep not
doing any error checking for translations for almost everything in
compat/linux.

compat/freebsd32/freebsd32_misc.c:
Optionally check for losing bits after possibly-truncating assignments as
before.

compat/linux/linux_stats.c:
Depend on the representation being compatible with Linux's (or just with
itself for local use) and spell some of the translations as assignments in
a macro that hides the details.

fs/nfsclient/nfs_clcomsubs.c:
Essentially the same fix as in 1996, except there is now no possible
truncation in makedev() itself.  Also fix nearby style bugs.

kern/vfs_syscalls.c:
As for freebsd32.  Also update the sysctl description to include file
numbers, and change it to describe device ids as device numbers.

sys/types.h:
Use inline functions (wrapped by macros) since the expressions are now
a bit too complicated for plain macros.  Describe the encoding and
some of the reasons for it.  16-bit compatibility didn't leave many
reasonable choices for the 32-bit encoding, and 32-bit compatibility
doesn't leave many reasonable choices for the 64-bit encoding.  My
choice is to put the 8 new minor bits in the low 8 bits of the top 32
bits.  This minimizes discontiguities.

Reviewed by:	kib (except for rewrite of the comment in linux_stats.c)
2018-06-13 12:22:00 +00:00
..
nfs_clbio.c sys: further adoption of SPDX licensing ID tags. 2017-11-20 19:43:44 +00:00
nfs_clcomsubs.c Fix the encoding of major and minor numbers in 64-bit dev_t by restoring 2018-06-13 12:22:00 +00:00
nfs_clkdtrace.c sys/fs: further adoption of SPDX licensing ID tags. 2017-11-27 15:15:37 +00:00
nfs_clkrpc.c sys: further adoption of SPDX licensing ID tags. 2017-11-20 19:43:44 +00:00
nfs_clnfsiod.c sys: further adoption of SPDX licensing ID tags. 2017-11-20 19:43:44 +00:00
nfs_clnode.c style: Remove remaining deprecated MALLOC/FREE macros 2018-01-25 22:25:13 +00:00
nfs_clport.c Merge the pNFS server code from projects/pnfs-planb-server into head. 2018-06-12 19:36:32 +00:00
nfs_clrpcops.c Merge the pNFS server code from projects/pnfs-planb-server into head. 2018-06-12 19:36:32 +00:00
nfs_clstate.c Merge the pNFS server code from projects/pnfs-planb-server into head. 2018-06-12 19:36:32 +00:00
nfs_clsubs.c style: Remove remaining deprecated MALLOC/FREE macros 2018-01-25 22:25:13 +00:00
nfs_clvfsops.c Merge the pNFS server code from projects/pnfs-planb-server into head. 2018-06-12 19:36:32 +00:00
nfs_clvnops.c style: Remove remaining deprecated MALLOC/FREE macros 2018-01-25 22:25:13 +00:00
nfs_kdtrace.h sys/fs: further adoption of SPDX licensing ID tags. 2017-11-27 15:15:37 +00:00
nfs.h sys: further adoption of SPDX licensing ID tags. 2017-11-20 19:43:44 +00:00
nfsmount.h Add a couple of safety belt checks to the NFSv4.1 client related to sessions. 2018-06-11 19:00:07 +00:00
nfsnode.h style: Remove remaining deprecated MALLOC/FREE macros 2018-01-25 22:25:13 +00:00
nlminfo.h sys/fs: further adoption of SPDX licensing ID tags. 2017-11-27 15:15:37 +00:00