<div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial">Think you !<div>Oh , I was wrong . How careless I was.</div><div>I have fixed it :</div><div>#define _IOC_NRMASK &nbsp; &nbsp; (((1 &lt;&lt; _IOC_NRBITS)-1) &lt;&lt; _IOC_NRSHIFT) &nbsp;// if the &nbsp;_IOC_NRBITS is 8 ,then the result is 0XFF<div><pre>#define&nbsp;_IOC_DIR(nr)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((nr&nbsp;&amp;&nbsp;&nbsp;_IOC_DIRMASK)&nbsp;&gt;&gt;&nbsp;_IOC_DIRSHIFT)&nbsp;&nbsp;//&nbsp;when&nbsp;decode , keep the same.</pre>Now I think this will spend more time than the kernel code when executed. It performs an extra operation "&gt;&gt;", but I think it better to understand.&nbsp;</div><div>&nbsp; &nbsp; &nbsp;_IOC_DIRMASK &nbsp; &nbsp; &nbsp; &nbsp; 0xC0000000</div><div>&nbsp; &nbsp; &nbsp;_IOC_TYPEMASK &nbsp; &nbsp; &nbsp;0x0000FF00</div><div>&nbsp; &nbsp; &nbsp;_IOC_NRMASK &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x000000FF</div><div>&nbsp; &nbsp; &nbsp;_IOC_SIZEMASK &nbsp; &nbsp; &nbsp; &nbsp;0x3FFF0000</div><div><br><div></div><div id="divNeteaseMailCard"></div><br><pre><br>At&nbsp;2013-03-30&nbsp;16:41:55,"Tobias&nbsp;Boege"&nbsp;&lt;tobias@gambas-buch.de&gt;&nbsp;wrote:
&gt;On&nbsp;Sat,&nbsp;30&nbsp;Mar&nbsp;2013,&nbsp;RS&nbsp;wrote:
&gt;&gt;&nbsp;it&nbsp;defines&nbsp;in&nbsp;the&nbsp;kernel:&nbsp;&nbsp;#define&nbsp;_IOC_NRMASK        ((1&nbsp;&lt;&lt;&nbsp;_IOC_NRBITS)-1)&nbsp;&nbsp;&nbsp;//define&nbsp;&nbsp;...&nbsp;&nbsp;#define&nbsp;_IOC_NRSHIFT        0&nbsp;&nbsp;...&nbsp;&nbsp;#define&nbsp;_IOC_DIR(nr)                (((nr)&nbsp;&gt;&gt;&nbsp;_IOC_DIRSHIFT)&nbsp;&amp;&nbsp;_IOC_DIRMASK)&nbsp;&nbsp;//when&nbsp;decode
&gt;&gt;&nbsp;
&gt;&gt;&nbsp;why&nbsp;not&nbsp;define&nbsp;it&nbsp;like&nbsp;this:
&gt;&gt;&nbsp;&nbsp;&nbsp;#define&nbsp;_IOC_NRSHIFT        0
&gt;&gt;&nbsp;&nbsp;&nbsp;...
&gt;&gt;&nbsp;&nbsp;&nbsp;#define&nbsp;_IOC_NRMASK&nbsp;((_IOC_NRSHIFT&nbsp;&gt;&gt;&nbsp;_IOC_NRBITS)&nbsp;-&nbsp;_IOC_NRSHIFT)&nbsp;&nbsp;&nbsp;//define
&gt;&gt;&nbsp;&nbsp;&nbsp;...
&gt;&gt;&nbsp;&nbsp;&nbsp;#define&nbsp;_IOC_DIR(nr)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((nr&nbsp;&amp;&nbsp;&nbsp;_IOC_DIRMASK)&nbsp;&gt;&gt;&nbsp;_IOC_DIRSHIFT)&nbsp;&nbsp;//&nbsp;when&nbsp;decode
&gt;&gt;&nbsp;
&gt;&gt;&nbsp;
&gt;&gt;&nbsp;I&nbsp;think&nbsp;it&nbsp;is&nbsp;better&nbsp;for&nbsp;the&nbsp;word&nbsp;"mask"&nbsp;.&nbsp;
&gt;&gt;&nbsp;
&gt;
&gt;It&nbsp;can't&nbsp;be&nbsp;better&nbsp;this&nbsp;way&nbsp;because&nbsp;it's&nbsp;wrong.&nbsp;Let's&nbsp;compute&nbsp;a&nbsp;bit:
&gt;
&gt;You&nbsp;are&nbsp;referring&nbsp;include/uapi/asm-generic/ioctl.h&nbsp;AFAICS:
&gt;
&gt;        #define&nbsp;_IOC_NRBITS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8
&gt;        #define&nbsp;_IOC_NRSHIFT&nbsp;&nbsp;&nbsp;&nbsp;0
&gt;        #define&nbsp;_IOC_NRMASK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((1&nbsp;&lt;&lt;&nbsp;_IOC_NRBITS)-1)
&gt;
&gt;This&nbsp;gives&nbsp;_IOC_NRMASK&nbsp;=&nbsp;((1&nbsp;&lt;&lt;&nbsp;8)&nbsp;-&nbsp;1)&nbsp;=&nbsp;0xff.&nbsp;But&nbsp;supposing&nbsp;your
&gt;
&gt;        _IOC_NRMASK        ((_IOC_NRSHIFT&nbsp;&gt;&gt;&nbsp;_IOC_NRBITS)&nbsp;-&nbsp;_IOC_NRSHIFT)
&gt;
&gt;it&nbsp;yields&nbsp;_IOC_NRMASK&nbsp;=&nbsp;((0&nbsp;&gt;&gt;&nbsp;8)&nbsp;-&nbsp;0)&nbsp;=&nbsp;0x00.
&gt;
&gt;You&nbsp;see?&nbsp;With&nbsp;your&nbsp;mask&nbsp;you'll&nbsp;never&nbsp;get&nbsp;any&nbsp;bits&nbsp;out&nbsp;of&nbsp;the&nbsp;ioctl&nbsp;number
&gt;because&nbsp;it's&nbsp;just&nbsp;wrong.
&gt;
&gt;The&nbsp;same&nbsp;applies&nbsp;to&nbsp;_IOC_DIR(nr).&nbsp;You&nbsp;can't&nbsp;just&nbsp;exchange&nbsp;bitwise&nbsp;ands&nbsp;and
&gt;shifts&nbsp;-&nbsp;you'd&nbsp;have&nbsp;to&nbsp;change&nbsp;the&nbsp;constants&nbsp;for&nbsp;this...&nbsp;and&nbsp;there&nbsp;is&nbsp;really
&gt;no&nbsp;point&nbsp;in&nbsp;it.
&gt;
&gt;Regards,
&gt;Tobi
&gt;
&gt;
&gt;_______________________________________________
&gt;Kernelnewbies&nbsp;mailing&nbsp;list
&gt;Kernelnewbies@kernelnewbies.org
&gt;http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
</pre></div></div></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>