diff --git a/kernel/fatfs.c b/kernel/fatfs.c
index 43d2d18..fb65cea 100644
--- a/kernel/fatfs.c
+++ b/kernel/fatfs.c
@@ -975,7 +975,7 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode)
 
     /* If someone did a seek, but no writes have occured, we will   */
     /* need to initialize the fnode.                                */
-    /*  (mode == XFR_WRITE) */
+    /*  (mode == XFR_WRITE) (or XFR_WRITE | XFR_DOS_EXTEND) */
     /* If there are no more free fat entries, then we are full! */
     cluster = extend(fnp);
     if (cluster == LONG_LAST_CLUSTER)
@@ -1020,21 +1020,23 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode)
       if (mode == XFR_READ)
         return DE_SEEK;
 
-      /* mode == XFR_WRITE */
+      /* mode == XFR_WRITE (or XFR_WRITE | XFR_DOS_EXTEND) */
       cluster = extend(fnp);
       if (cluster == LONG_LAST_CLUSTER)
         return DE_HNDLDSKFULL;
 
-      /* ecm: finally the right solution, only extend/modify
+      if (mode & XFR_DOS_EXTEND) {
+        /* ecm: finally the right solution, only extend/modify
                 file size after having just appended a cluster. */
-      fnp->f_dir.dir_size =
-        (((ULONG)fnp->f_cluster_offset + 2)
-        /* at 0 we will increment to 1, having allocated the second
+        fnp->f_dir.dir_size =
+          (((ULONG)fnp->f_cluster_offset + 2)
+          /* at 0 we will increment to 1, having allocated the second
                 cluster, so + 2 for the then-total size. */
-        * (ULONG)fnp->f_dpb->dpb_secsize)
-        <<
-        fnp->f_dpb->dpb_shftcnt;
-      merge_file_changes(fnp, FALSE);
+          * (ULONG)fnp->f_dpb->dpb_secsize)
+          <<
+          fnp->f_dpb->dpb_shftcnt;
+        merge_file_changes(fnp, FALSE);
+      }
     }
 
     fnp->f_cluster = cluster;
@@ -1075,7 +1077,7 @@ STATIC COUNT dos_extend(f_node_ptr fnp)
   while (count > 0)
 #endif
   {
-    if (map_cluster(fnp, XFR_WRITE) != SUCCESS)
+    if (map_cluster(fnp, XFR_WRITE | XFR_DOS_EXTEND) != SUCCESS)
       return DE_HNDLDSKFULL;
 
 #ifdef WRITEZEROS
@@ -1238,6 +1240,8 @@ long rwblock(COUNT fd, VOID FAR * buffer, UCOUNT count, int mode)
             if CX > 0000h then we want to write to the cluster
                 anyway, so extending to the cluster that starts at
                 the boundary is desired. */
+    /* ecm: at this point dos_extend has set the file size exactly,
+                if it was extended at all */
   }
   
   /* Test that we are really about to do a data transfer. If the  */
diff --git a/kernel/globals.h b/kernel/globals.h
index 14d0b5c..a50af1c 100644
--- a/kernel/globals.h
+++ b/kernel/globals.h
@@ -111,6 +111,7 @@ FAR * ASM DPBp;                      /* First drive Parameter Block          */
 #define XFR_FORCE_WRITE 3
 /* flag to update fcb_rndm field */
 #define XFR_FCB_RANDOM  4
+#define XFR_DOS_EXTEND  8
 
 #define RDONLY          0
 #define WRONLY          1
