<p>The disk_read function reads sector(s) from the storage device.</p>
<pre>
DRESULT disk_read (
BYTE <spanclass="arg">pdrv</span>, <spanclass="c">/* [IN] Physical drive number */</span>
BYTE* <spanclass="arg">buff</span>, <spanclass="c">/* [OUT] Pointer to the read data buffer */</span>
DWORD <spanclass="arg">sector</span>, <spanclass="c">/* [IN] Start sector number */</span>
UINT <spanclass="arg">count</span><spanclass="c">/* [IN] Number of sectros to read */</span>
);
</pre>
</div>
<divclass="para arg">
<h4>Parameters</h4>
<dlclass="par">
<dt>pdrv</dt>
<dd>Physical drive number to identify the target device.</dd>
<dt>buff</dt>
<dd>Pointer to the <em>byte array</em> to store the read data.</dd>
<dt>sector</dt>
<dd>Start sector number in logical block address (LBA).</dd>
<dt>count</dt>
<dd>Number of sectors to read. FatFs specifis it in range of from 1 to 128.</dd>
</dl>
</div>
<divclass="para ret">
<h4>Return Value</h4>
<dlclass="ret">
<dt>RES_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>RES_ERROR</dt>
<dd>Any hard error occured during the read operation and could not recover it.</dd>
<dt>RES_PARERR</dt>
<dd>Invalid parameter.</dd>
<dt>RES_NOTRDY</dt>
<dd>The device has not been initialized.</dd>
</dl>
</div>
<divclass="para desc">
<h4>Description</h4>
<p>The memory address specified by <ttclass="arg">buff</tt> is not that always aligned to word boundary because the type of argument is defined as <tt>BYTE*</tt>. The misaligned read/write request can occure at <ahref="appnote.html#fs1">direct transfer</a>. If the bus architecture, especially DMA controller, does not allow misaligned memory access, it should be solved in this function. There are some workarounds described below to avoid this issue.</p>
<ul>
<li>Convert word transfer to byte transfer in this function. - Recommended.</li>
<li>For <tt>f_read()</tt>, avoid long read request that includes a whole of sector. - Direct transfer will never occure.</li>
<li>For <tt>f_read(fp, buff, btr, &br)</tt>, make sure that <tt>(((UINT)buff & 3) == (f_tell(fp) & 3))</tt> is true. - Word aligned direct transfer is guaranteed.</li>
</ul>
<p>Generally, a multiple sector transfer request must not be split into single sector transactions to the storage device, or you will not get good read throughput.</p>