Re: svn commit: r335053 - in head/sys: compat/freebsd32 compat/linux fs/nfsclient kern sys

2018-06-14 Thread Bruce Evans

On Thu, 14 Jun 2018, Hans Petter Selasky wrote:


On 06/13/18 14:22, Bruce Evans wrote:

[... inlines for makedev(), etc.]


Can you use all macros here? This breaks OFED, because __makedev() is used to 
initialize variables.


See another reply.

I will change them to macros and fear breaking them with a gccism instead
of with with inlines.

I should have worried more about the inlines.  Plain inline is only in C99
or a gcc extension starting in gcc-2.mumble.  Portability of sys/types.h is
more important than for any other header in the system except sys/cdevs.h.
So it must compile with C90 compilers and should compile with K compilers.
For makedev(), etc., it spells inline as __inline so the inline feature
can be turned off easily (the functions then become static and repeated
every time sys/types.h is included, but this probably happens anyway with
-O0 and it works for any compiler).

Turning off the statement-expression feature needed to write safe
macros is not so easy.  In , this feature is only used in
mostly-kernel headers and in stdatomic.h.

Bruce
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r335053 - in head/sys: compat/freebsd32 compat/linux fs/nfsclient kern sys

2018-06-14 Thread Hans Petter Selasky

On 06/14/18 09:29, Hans Petter Selasky wrote:

On 06/13/18 14:22, Bruce Evans wrote:

+/*
+ * The major and minor numbers are encoded in dev_t as MMMmmmMm (where
+ * letters correspond to bytes).  The encoding of the lower 4 bytes is
+ * constrained by compatibility with 16-bit and 32-bit dev_t's.  The
+ * encoding of of the upper 4 bytes is the least unnatural one 
consistent
+ * with this and other constraints.  Also, the decoding of the m 
bytes by
+ * minor() is unnatural to maximize compatibility subject to not 
discarding
+ * bits.  The upper m byte is shifted into the position of the lower 
M byte
+ * instead of shifting 3 upper m bytes to close the gap.  
Compatibility for

+ * minor() is achieved iff the upper m byte is 0.
+ */
+#define    major(d)    __major(d)
+static __inline int
+__major(dev_t _d)
+{
+    return (((_d >> 32) & 0xff00) | ((_d >> 8) & 0xff));
+}
+#define    minor(d)    __minor(d)
+static __inline int
+__minor(dev_t _d)
+{
+    return (((_d >> 24) & 0xff00) | (_d & 0x00ff));
+}
+#define    makedev(M, m)    __makedev((M), (m))
+static __inline dev_t
+__makedev(int _M, int _m)
+{
+    return (((dev_t)(_M & 0xff00) << 32) | ((_M & 0xff) << 8) |
+    ((dev_t)(_m & 0xff00) << 24) | (_m & 0x00ff));
+}


Can you use all macros here? This breaks OFED, because __makedev() is 
used to initialize variables.


r335123 fixes this for OFED, but there might be other places where 
MAKDEV() is used to setup static and const variables.


--HPS
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r335053 - in head/sys: compat/freebsd32 compat/linux fs/nfsclient kern sys

2018-06-14 Thread Hans Petter Selasky

On 06/13/18 14:22, Bruce Evans wrote:

+/*
+ * The major and minor numbers are encoded in dev_t as MMMmmmMm (where
+ * letters correspond to bytes).  The encoding of the lower 4 bytes is
+ * constrained by compatibility with 16-bit and 32-bit dev_t's.  The
+ * encoding of of the upper 4 bytes is the least unnatural one consistent
+ * with this and other constraints.  Also, the decoding of the m bytes by
+ * minor() is unnatural to maximize compatibility subject to not discarding
+ * bits.  The upper m byte is shifted into the position of the lower M byte
+ * instead of shifting 3 upper m bytes to close the gap.  Compatibility for
+ * minor() is achieved iff the upper m byte is 0.
+ */
+#definemajor(d)__major(d)
+static __inline int
+__major(dev_t _d)
+{
+   return (((_d >> 32) & 0xff00) | ((_d >> 8) & 0xff));
+}
+#defineminor(d)__minor(d)
+static __inline int
+__minor(dev_t _d)
+{
+   return (((_d >> 24) & 0xff00) | (_d & 0x00ff));
+}
+#definemakedev(M, m)   __makedev((M), (m))
+static __inline dev_t
+__makedev(int _M, int _m)
+{
+   return (((dev_t)(_M & 0xff00) << 32) | ((_M & 0xff) << 8) |
+   ((dev_t)(_m & 0xff00) << 24) | (_m & 0x00ff));
+}


Can you use all macros here? This breaks OFED, because __makedev() is 
used to initialize variables.


--HPS
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"