 -
 +			res = (sd_write_block(block_data, sector, SD_BLOCKSIZE) != 0) ?
 +				RES_ERROR : RES_OK;
++			data_written = 0;
  		}
  	} else {
 -
 -		// Send data to the disk
 -
 +		// Write data
-+		memcpy(block_ptr, buff, sc);
-+		block_ptr += sc;
++		memcpy(block_data+data_written, buff, ((sc >= SD_BLOCKSIZE)
++			? (SD_BLOCKSIZE-sc) : sc));
++		data_written += sc;
 +		res = RES_OK;
  	}
  
  	return res;
-diff -ENwbur petitfs_root/src/pffconf.h petitfs_root_mod/src/pffconf.h
+diff -ENwbur petitfs_root/src/pffconf.h petitfs_root_patched/src/pffconf.h
 --- petitfs_root/src/pffconf.h	2014-06-10 00:24:26.000000000 +0200
-+++ petitfs_root_mod/src/pffconf.h	2014-11-06 22:19:24.000000000 +0100
++++ petitfs_root_patched/src/pffconf.h	2014-11-10 18:06:17.000000000 +0100
 @@ -10,13 +10,13 @@
  /---------------------------------------------------------------------------*/
  

 
+	static uint32_t sector;
+
+	uint8_t block_data[SD_BLOCKSIZE];
+	uint8_t *block_ptr = block_data;
 
 	if (!buff) {
 		if (sc) {

diff -ENwbur petitfs_root/src/diskio.c petitfs_root_patched/src/diskio.c
--- petitfs_root/src/diskio.c	2014-06-10 00:24:26.000000000 +0200
+++ petitfs_root_patched/src/diskio.c	2014-11-10 18:09:50.000000000 +0100
@@ -2,6 +2,9 @@
 /* Low level disk I/O module skeleton for Petit FatFs (C)ChaN, 2014      */
 /*-----------------------------------------------------------------------*/
