<?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: An MFS function call ioctl using IO_IOCTL_FIND_FIRST_FILE results in structure misalignment</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/An-MFS-function-call-ioctl-using-IO-IOCTL-FIND-FIRST-FILE/m-p/707568#M17573</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your sharing.&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>Thu, 19 Oct 2017 02:59:42 GMT</pubDate>
    <dc:creator>danielchen</dc:creator>
    <dc:date>2017-10-19T02:59:42Z</dc:date>
    <item>
      <title>An MFS function call ioctl using IO_IOCTL_FIND_FIRST_FILE results in structure misalignment</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/An-MFS-function-call-ioctl-using-IO-IOCTL-FIND-FIRST-FILE/m-p/707566#M17571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;I’m trying to use the ioctl call to an sdcard to search for a filename and then delete it. When the function call returns it has an illegal ram address in the structure. After digging for several days I have collected some information on the problem.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;/* MFS part of the software */&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;MFS_SEARCH_DATA&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; search_data;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;MFS_SEARCH_PARAM&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; search;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;char&lt;/STRONG&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; filepath[46] = &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #2a00ff;"&gt;""&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;// used for the input filename wildcard&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;char&lt;/STRONG&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; filename_buffer[46];&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt; // returned filename&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;ATTRIBUTE&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; = MFS_SEARCH_LFN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;WILDCARD&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; = filepath;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; = &amp;amp;search_data;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;LFN_BUF&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; = filename_buffer;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;LFN_BUF_LEN&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; = &lt;/SPAN&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;sizeof&lt;/STRONG&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;(filename_buffer);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt; SEARCH_DATA_PTR-&amp;gt;ATTRIBUTE = &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;MFS_SEARCH_LFN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;LFN_BUF&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; = filename_buffer;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;LFN_BUF_LEN&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; = &lt;/SPAN&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;sizeof&lt;/STRONG&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;(filename_buffer);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: #3f7f5f;"&gt;// Check to see if this file exists. If so then delete it before creating a new one&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;sprintf(filepath, &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #2a00ff;"&gt;"snapshot%d_*.bin"&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;, file_index.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;intervention_snapshot_file&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;); &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #3f7f5f;"&gt;// &lt;SPAN style="text-decoration: underline;"&gt;wildcard&lt;/SPAN&gt; filename&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black; background: silver;"&gt;error_code = ioctl(a_fd, IO_IOCTL_FIND_FIRST_FILE, &amp;amp;search);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;if&lt;/STRONG&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;(error_code == MFS_NO_ERROR)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sprintf(int_snapshot_file_name, &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #2a00ff;"&gt;"%s"&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;, search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0; background: silver;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;LFN_BUF&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;while&lt;/STRONG&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;(error_code == MFS_NO_ERROR)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; error_code = ioctl(a_fd, IO_IOCTL_DELETE_FILE, &lt;SPAN style="text-decoration: underline;"&gt;int_snapshot_file_name&lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; error_code = ioctl(a_fd, IO_IOCTL_FIND_NEXT_FILE,search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0; background: silver;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;);&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #3f7f5f;"&gt; // Check if there are more&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;if&lt;/STRONG&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;(error_code == MFS_NO_ERROR)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sprintf(int_snapshot_file_name, &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #2a00ff;"&gt;"%s"&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;, search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0; background: silver;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;LFN_BUF&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: black; font-size: 10.0pt;"&gt;A look at the addresses of the structure before and after the function call&lt;/STRONG&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;: &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;Just before the call to &lt;SPAN style="text-decoration: underline;"&gt;error_code&lt;/SPAN&gt; = ioctl(a_fd, IO_IOCTL_FIND_FIRST_FILE, &amp;amp;search);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;(Had to create variables to read addresses because the Expressions window was giving a different value than when I did a mouse over). These values are from &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; background: silver;"&gt;MFS_SEARCH_PARAM&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;a = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;INTERNAL_SEARCH_DATA&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;WILDCARD&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;b = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;INTERNAL_SEARCH_DATA&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;ATTR_ONE_MASK&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;c = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;INTERNAL_SEARCH_DATA&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;ATTR_ZERO_MASK&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;d = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;INTERNAL_SEARCH_DATA&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;DIR_CHAIN_LOC&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;e = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;search.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;LFN_BUF&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&amp;nbsp; =&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;0x20012fc6&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="ioctl_call_addresses_before_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/31450i27D5DD311A72B561/image-size/large?v=v2&amp;amp;px=999" role="button" title="ioctl_call_addresses_before_1.png" alt="ioctl_call_addresses_before_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="ioctl_call_addresses_before_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/31481i95ACB1C9AC63AC72/image-size/large?v=v2&amp;amp;px=999" role="button" title="ioctl_call_addresses_before_2.png" alt="ioctl_call_addresses_before_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;After stepping into the file mfs_find.c and function &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;_mfs_error&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; &lt;STRONG style="background: silver;"&gt;MFS_find_init&lt;/STRONG&gt;(&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="text-decoration: underline;"&gt;MFS_DRIVE_STRUCT_PTR&lt;/SPAN&gt; drive_ptr,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: .5in; margin: 0in 0in .0001pt 2.0in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;MFS_SEARCH_PARAM_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; sp_ptr,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: .5in; margin: 0in 0in .0001pt 2.0in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;MFS_SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; sd_ptr):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;The sp_ptr pointer is pointing to the same address as "search" from above.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;a = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;sp_ptr-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;INTERNAL_SEARCH_DATA&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;WILDCARD&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;sp_ptr-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;INTERNAL_SEARCH_DATA&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;ATTR_ONE_MASK&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;sp_ptr-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;INTERNAL_SEARCH_DATA&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;ATTR_ZERO_MASK&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; d = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;sp_ptr-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;INTERNAL_SEARCH_DATA&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;DIR_CHAIN_LOC&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; e = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;)&amp;amp;sp_ptr-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;SEARCH_DATA_PTR&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;LFN_BUF&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="ioctl_call_addresses_after_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/31532i91FC3E83242C1453/image-size/large?v=v2&amp;amp;px=999" role="button" title="ioctl_call_addresses_after_1.png" alt="ioctl_call_addresses_after_1.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="ioctl_call_addresses_after_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/31579i70BD4B820770A529/image-size/large?v=v2&amp;amp;px=999" role="button" title="ioctl_call_addresses_after_2.png" alt="ioctl_call_addresses_after_2.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;In &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0070c0;"&gt;sp_ptr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;-&amp;gt;SEARCH_DATA_PTR-&amp;gt;INTERNAL_SEARCH_DATA.DIR_CHAIN_LOC you can see that address of this element of the structure &lt;SPAN style="background: silver;"&gt;MFS_SEARCH_PARAM&lt;/SPAN&gt; is two bytes different than in&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0070c0;"&gt;search&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;.SEARCH_DATA_PTR-&amp;gt;INTERNAL_SEARCH_DATA.DIR_CHAIN_LOC (0x20012f9e vs 0x2001fa0)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;When the line sd_ptr-&amp;gt;LFN_BUF = sp_ptr-&amp;gt;&lt;SPAN style="text-decoration: underline;"&gt;LFN_BUF&lt;/SPAN&gt;; is reached (in &lt;STRONG&gt;&lt;SPAN style="color: black; background: silver;"&gt;MFS_find_init&lt;/SPAN&gt;&lt;SPAN style="color: black;"&gt;()&lt;/SPAN&gt;&lt;/STRONG&gt;) it copies the filename to 0x20012fa0 and when it returns to the calling function the variable “search” looks for the filename in 0x20012f9e resulting in a shift of the contents of LFN_BUF.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="ioctl_call_addresses_after_3.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/31483iBABF585024FB7EC0/image-size/large?v=v2&amp;amp;px=999" role="button" title="ioctl_call_addresses_after_3.png" alt="ioctl_call_addresses_after_3.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Any ideas why this is happening?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Oct 2017 21:16:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/An-MFS-function-call-ioctl-using-IO-IOCTL-FIND-FIRST-FILE/m-p/707566#M17571</guid>
      <dc:creator>georgejoseph</dc:creator>
      <dc:date>2017-10-16T21:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: An MFS function call ioctl using IO_IOCTL_FIND_FIRST_FILE results in structure misalignment</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/An-MFS-function-call-ioctl-using-IO-IOCTL-FIND-FIRST-FILE/m-p/707567#M17572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: #3d3d3d;"&gt;Solution: I recently split my .h files into prototype.h and struct.h because I was having problems with circular references.&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;In my new struct.h file I added an #include for another .h file which contained a #pragma pack(1) directive.&amp;nbsp; This would have been ok except there was not corresponding #pragma pack() to turn off the packing so my new .h file inherited the pack command and the&amp;nbsp;&lt;SPAN style="font-size: 10.0pt; color: #005032; border: none windowtext 1.0pt; padding: 0in; background: white;"&gt;&lt;SPAN&gt;MFS_SEARCH_PARAM&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; color: black; border: none windowtext 1.0pt; padding: 0in; background: white;"&gt;&lt;SPAN&gt;&amp;nbsp;search and&amp;nbsp;&lt;SPAN style="font-size: 10.0pt; color: #005032; border: none windowtext 1.0pt; padding: 0in; background: white;"&gt;MFS_SEARCH_DATA&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;search_data were packed to a one byte alignment. Unfortunately the mfs.a library file had the default alignment, so this is what caused the alignment problem. I changed to using the #pragma pack(push, 1) coupled with a #pragma pack(pop). This cleared up the alignment problem.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2017 13:56:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/An-MFS-function-call-ioctl-using-IO-IOCTL-FIND-FIRST-FILE/m-p/707567#M17572</guid>
      <dc:creator>georgejoseph</dc:creator>
      <dc:date>2017-10-18T13:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: An MFS function call ioctl using IO_IOCTL_FIND_FIRST_FILE results in structure misalignment</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/An-MFS-function-call-ioctl-using-IO-IOCTL-FIND-FIRST-FILE/m-p/707568#M17573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your sharing.&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>Thu, 19 Oct 2017 02:59:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/An-MFS-function-call-ioctl-using-IO-IOCTL-FIND-FIRST-FILE/m-p/707568#M17573</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2017-10-19T02:59:42Z</dc:date>
    </item>
  </channel>
</rss>

