<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>MQX Software SolutionsのトピックRe: _io_part_mgr_write fails on large sector</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668922#M17332</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Adrain:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, you are right.&amp;nbsp; This is a bug in MQX for KSDK 1.3. unfortunately there will be no updates for MQX in KSDK.&lt;/P&gt;&lt;P&gt;Thank you very much for your input, it is very helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 Jun 2017 06:51:57 GMT</pubDate>
    <dc:creator>danielchen</dc:creator>
    <dc:date>2017-06-06T06:51:57Z</dc:date>
    <item>
      <title>_io_part_mgr_write fails on large sector</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668920#M17330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using KSDK 1.3.0 with MQX on the MK66 processor.&lt;/P&gt;&lt;P&gt;Problem 1:&lt;/P&gt;&lt;P&gt;I have found a problem where after a period of time of writing data to&amp;nbsp;an SD card it&amp;nbsp;would become unavailable. It would mount but any read / write / list would fail. I have tracked this down to a problem with the&amp;nbsp;_io_part_mgr_write function. It calls lseek, which returns the selected sector&amp;nbsp;as a int64_t value, but&amp;nbsp;puts the result into a int32_t variable and then checks if the result is greater than or equal to&amp;nbsp;0 before writing the data. The problem is when the returned sector number is greater than a int32_t can hold it wraps around to be a negative number so the check fails, even though the seek was successful.&lt;/P&gt;&lt;P&gt;I have now changed the call to put the result back in to the location variable then check that.&amp;nbsp;I can now continue to use cards that had previously become "corrupted".&lt;/P&gt;&lt;P&gt;Snippet from _io_part_mgr_write in part_mgr.c&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;// Adria Rockall:- return is a sector so put into location which is a int64_t else we get overflow&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp; result = lseek(pm_struct_ptr-&amp;gt;DEV_FILE_PTR, location, SEEK_SET);&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; location &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;lseek&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pm_struct_ptr&lt;SPAN class="operator token"&gt;-&amp;gt;&lt;/SPAN&gt;DEV_FILE_PTR&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; location&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; SEEK_SET&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;location &lt;SPAN class="operator token"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;write&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pm_struct_ptr&lt;SPAN class="operator token"&gt;-&amp;gt;&lt;/SPAN&gt;DEV_FILE_PTR&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; data_ptr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; num&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;// Adrian Rockall:- return -1 if the seek fails&lt;/SPAN&gt;
 &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp; errno &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MFS_ERROR_SEEK&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;error&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;error &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MFS_ERROR_SEEK&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&amp;nbsp; result &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem 2:&lt;/P&gt;&lt;P&gt;It appears the function has also been updated at some point to take a pointer to an error variable to pass back the error code. However the function itself still puts the error codes in the global errno variable at not in the passed in variable. As the calling function does not initialise the variable&amp;nbsp;that it&amp;nbsp;passes in and copies the value to errno if a failure is detected it results in a completely random error code being reported back to the calling functions. I have now changed the&amp;nbsp;declarations of the error variables in all the calling functions&amp;nbsp;to ensure they are initialised to 0, plus added code, like that shown in lines 11 to 14 above, to all places where errno is set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps anyone having this problem.&lt;/P&gt;&lt;P&gt;Adrian.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 May 2017 09:49:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668920#M17330</guid>
      <dc:creator>adyr</dc:creator>
      <dc:date>2017-05-31T09:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: _io_part_mgr_write fails on large sector</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668921#M17331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have just found the same problem exists in the _io_part_mgr_read function as well so I have applied the same change there.&lt;/P&gt;&lt;P&gt;Snippet from _io_part_mgr_read&amp;nbsp;in part_mgr.c:&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;/* Perform seek and data transfer */&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;// Adria Rockall:- return is a sector so put into location which is a int64_t else we get overflow&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp; result = _nio_lseek(pm_struct_ptr-&amp;gt;DEV_FILE_PTR, location, SEEK_SET, error);&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; location &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;_nio_lseek&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pm_struct_ptr&lt;SPAN class="operator token"&gt;-&amp;gt;&lt;/SPAN&gt;DEV_FILE_PTR&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; location&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; SEEK_SET&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; error&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;location &lt;SPAN class="operator token"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;_nio_read&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pm_struct_ptr&lt;SPAN class="operator token"&gt;-&amp;gt;&lt;/SPAN&gt;DEV_FILE_PTR&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; data_ptr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; num&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; error&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;// Adrian Rockall:- return -1 if the seek fails&lt;/SPAN&gt;
 &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;error&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;error &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MFS_ERROR_SEEK&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&amp;nbsp; result &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Also I am not sure why the read function calls _nio_lseek and the write function calls lseek. It seems a bit inconsistent and may be better if both call _nio_lseek&amp;nbsp;as lseek ends up calling that anyway. It would be one less call in the chain. It might even be more efficient if they both called _io_part_mgr_lseek directly as that is where both the other functions seem to end up. Or just set LOCATION directly as that is all that is happening at the end of the chain. If I get time I will investigate all that but if anyone else can see an immediate reason why it is not a good idea I would like to know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Adrian.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 06:25:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668921#M17331</guid>
      <dc:creator>adyr</dc:creator>
      <dc:date>2017-06-02T06:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: _io_part_mgr_write fails on large sector</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668922#M17332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Adrain:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, you are right.&amp;nbsp; This is a bug in MQX for KSDK 1.3. unfortunately there will be no updates for MQX in KSDK.&lt;/P&gt;&lt;P&gt;Thank you very much for your input, it is very helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jun 2017 06:51:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668922#M17332</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2017-06-06T06:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: _io_part_mgr_write fails on large sector</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668923#M17333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for posting this issue, Adrian.&amp;nbsp; We are using a 16 GB SD card and I am testing the solution by continuously writing 1 KB to a file.&amp;nbsp; I am trying to get the file location to pass over the 4GB boundary so it will pass the overflow issue in the _io_part_mgr_write() function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I started stepping through the debugger when the location gets to the value of 0x8000_0000.&amp;nbsp; Now, with the 64-bit variable I expect to return the location 0x8000_0000 when it calls lseek, but the value returned is 0xFFFF_FFFF_8000_0000, which is &amp;lt; 0, so the write fails.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The root cause of the this issue is the call of lseek.&amp;nbsp; lseek has a return value of off_t, which on my K64F system is defined as a long in the _types.h file in GNU tools 4.8 2014q3.&amp;nbsp; Also, the lseek argument "offset" is also an off_t type, so it is 32-bit as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I can solve this by calling _nio_lseek directly, which returns an _nio_off_t which is type defined in nio.h as an int64_t.&amp;nbsp; Also, the _nio_lseek argument "offset" is of type _nio_off_t as well, so it is 64 bits.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you tested your solution, did you test write by using lseek, or did you go directly to _nio_lseek?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2018 13:53:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668923#M17333</guid>
      <dc:creator>jschepler</dc:creator>
      <dc:date>2018-04-03T13:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: _io_part_mgr_write fails on large sector</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668924#M17334</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess you have an additional problem&amp;nbsp;with that type definition:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;The root cause of the this issue is the call of lseek.&amp;nbsp; lseek has a return value of off_t, which on my K64F system is defined as a long in the _types.h file in GNU tools 4.8 2014q3.&amp;nbsp; Also, the lseek argument "offset" is also an off_t type, so it is 32-bit as well.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using the IAR tools and off_t is define as int64_t in MyProject\SDK\rtos\mqx\mqx\source\psp\cortex_m\compiler\iar\comp.h so lseek is working OK for me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2018 14:22:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/io-part-mgr-write-fails-on-large-sector/m-p/668924#M17334</guid>
      <dc:creator>adyr</dc:creator>
      <dc:date>2018-04-03T14:22:57Z</dc:date>
    </item>
  </channel>
</rss>

