disk_writep

The disk_writep function writes data to the sector.

DRESULT disk_writep (
  BYTE* Buffer,       /* [IN] Pointer to the data to be written */
  DWORD SectorBytes,  /* [IN] Sector number or Number of bytes to wtite */
);

Parameters

Buffer
Pointer to the data to be sent to the sector. If a NULL is given, the function initiate/finalize the write operation.
SectorBytes
Specifies nubmer of bytes to send if Buffer is not a NULL. If Buffer is a NULL and SectorBytes is not a zero, the function initiates a write operation to the sector. If both parameters are zero, the function finalize the current sector write operation.

Return Value

RES_OK (0)
The function succeeded.
RES_ERROR
Any hard error occured during the disk write operation and could not recover it or the drive is write protected.
RES_PARERR
Invalid parameter.
RES_NOTRDY
The disk drive has not been initialized.

Description

The sector write operation is done in following sequence.

  1. disk_writep(0, sector_number); Initiate a sector write operation.
  2. disk_writep(data, byte_to_write); Start to send data to the sector.
  3. disk_writep(data, byte_to_write); And data can be sent upto 512 bytes with one or more calls.
  4. disk_writep(data, byte_to_write); ...
  5. disk_writep(0, 0); Finalize the write operation. If number of bytes sent is less than 512, left bytes in the sector is filled by zero.

If a write operation is in progress, disk_readp function will fail and disk_initialize function finalize the write operation.

Remarks

This funciton is not needed in read-only configuration.

Return