]> cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/documents/doc/dread.html
Import fatfs R0.13b
[z180-stamp.git] / fatfs / documents / doc / dread.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <link rel="up" title="FatFs" href="../00index_e.html">
7 <link rel="alternate" hreflang="ja" title="Japanese" href="../ja/dread.html">
8 <link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
9 <title>FatFs - disk_read</title>
10 </head>
11
12 <body>
13
14 <div class="para func">
15 <h2>disk_read</h2>
16 <p>The disk_read function is called to read data from the sector(s) of storage device.</p>
17 <pre>
18 DRESULT disk_read (
19 BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
20 BYTE* <span class="arg">buff</span>, <span class="c">/* [OUT] Pointer to the read data buffer */</span>
21 DWORD <span class="arg">sector</span>, <span class="c">/* [IN] Start sector number */</span>
22 UINT <span class="arg">count</span> <span class="c">/* [IN] Number of sectros to read */</span>
23 );
24 </pre>
25 </div>
26
27 <div class="para arg">
28 <h4>Parameters</h4>
29 <dl class="par">
30 <dt>pdrv</dt>
31 <dd>Physical drive number to identify the target device.</dd>
32 <dt>buff</dt>
33 <dd>Pointer to the first item of the <em>byte array</em> to store read data. Size of read data will be the sector size * <tt class="arg">count</tt> bytes.</dd>
34 <dt>sector</dt>
35 <dd>Start sector number in 32-bit LBA.</dd>
36 <dt>count</dt>
37 <dd>Number of sectors to read.</dd>
38 </dl>
39 </div>
40
41
42 <div class="para ret">
43 <h4>Return Value</h4>
44 <dl class="ret">
45 <dt>RES_OK (0)</dt>
46 <dd>The function succeeded.</dd>
47 <dt>RES_ERROR</dt>
48 <dd>An unrecoverable hard error occured during the read operation.</dd>
49 <dt>RES_PARERR</dt>
50 <dd>Invalid parameter.</dd>
51 <dt>RES_NOTRDY</dt>
52 <dd>The device has not been initialized.</dd>
53 </dl>
54 </div>
55
56
57 <div class="para desc">
58 <h4>Description</h4>
59 <p>Read/write operation to the generic storage devices, such as memory card, hadddisk and optical disk, is done in unit of block of data bytes called <em>sector</em>. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (<tt>FF_MIN_SS == FF_MAX_SS</tt>, this is the most case), the read/write function must work at that sector size. When FatFs is configured for variable sector size (<tt>FF_MIN_SS &lt; FF_MAX_SS</tt>), the sector size of medium is inquired with <tt>disk_ioctl</tt> function immediately following <tt>disk_initialize</tt> function succeeded.</p>
60 <p>The memory address specified by <tt class="arg">buff</tt> is not that always aligned to word boundary because the argument is defined as <tt>BYTE*</tt>. The unaligned read/write request can occure at <a href="appnote.html#fs1">direct transfer</a>. If the bus architecture, especially DMA controller, does not allow unaligned memory access, it should be solved in this function. There are some workarounds described below to avoid this issue.</p>
61 <ul>
62 <li>Convert word transfer to byte transfer in this function if needed. - Recommended.</li>
63 <li>On the <tt>f_read()</tt> calls, avoid long read request that includes a whole of sector. - Any direct transfer never occures.</li>
64 <li>On the <tt>f_read(fp, dat, btw, bw)</tt> calls, make sure that <tt>(((UINT)dat &amp; 3) == (f_tell(fp) &amp; 3))</tt> is true. - Word alignment of <tt class="arg">buff</tt> is guaranteed no matter dat is not word aligned.</li>
65 </ul>
66 <p>Generally, a multiple sector read request must not be split into single sector transactions to the storage device, or read throughput gets worse.</p>
67 </div>
68
69
70 <p class="foot"><a href="../00index_e.html">Return</a></p>
71 </body>
72 </html>