FatFs - disk_read

## disk_read

The disk_read function is called to read data from the sector(s) of storage device.

    DRESULT disk_read (
      BYTE pdrv,     /* [IN] Physical drive number */
      BYTE* buff,    /* [OUT] Pointer to the read data buffer */
      DWORD sector,  /* [IN] Start sector number */
      UINT count     /* [IN] Number of sectros to read */
    );

#### Parameters

pdrv
  Physical drive number to identify the target device.
buff
  Pointer to the first item of the byte array to store read data.
sector
  Start sector number in 32-bit LBA.
count
  Number of sectors to read.

#### Return Value

RES_OK (0)
  The function succeeded.
RES_ERROR
  A hard error occured during the read operation and could not recover it.
RES_PARERR
  Invalid parameter.
RES_NOTRDY
  The device has not been initialized.

#### Description

The data read/write operation to the storage devices is done in unit of sector. FatFs supports the sector size in range of from 512 to 4096 bytes. When FatFs is configured to fixed sector size (`_MIN_SS == MAX_SS`, this will be the most case), the read/write function must work at that sector size. When FatFs is configured to variable sector size (`_MIN_SS != MAX_SS`), sector size is inquired with `disk_ioctl` function following `disk_initialize` function.

The memory address specified by `buff` is not that always aligned to word boundary because the argument is defined as `BYTE*`. The unaligned read/write request can occure at direct transfer. 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.

- Convert word transfer to byte transfer in this function if needed. - Recommended.
- On the `f_read()` calls, avoid long read request that includes a whole of sector. - Any direct transfer never occures.
- On the `f_read(fp, data, btw, bw)` calls, make sure that `(((UINT)data & 3) == (f_tell(fp) & 3))` is true. - Word alignment of `buff` is guaranteed.

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.

Return