Change clearerr prototype; Automatically flush the device on close.
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 2 Aug 2010 12:53:25 +0000 (12:53 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 2 Aug 2010 12:53:25 +0000 (12:53 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4117 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/drv/sd.c
bertos/io/kblock.h
bertos/io/kblock_ram.c

index 091a42bde073e3338ca2b15a65579a67c8b9e28f..c12d7592e6660332d57a430c1473e620057ae37a 100644 (file)
@@ -378,11 +378,10 @@ static int sd_error(KBlock *b)
        return sd->r1;
 }
 
-static int sd_clearerr(KBlock *b)
+static void sd_clearerr(KBlock *b)
 {
        Sd *sd = SD_CAST(b);
        sd->r1 = 0;
-       return 0;
 }
 
 static const KBlockVTable sd_unbuffered_vt =
index 7775d7b87f14f9f28df7c014b89f6f3e15fb2bda..8d30ffc386bd5ca6f56e0ab736c29fb8007eecca 100644 (file)
@@ -66,7 +66,7 @@ typedef int    (* kblock_load_t)        (struct KBlock *b, block_idx_t index);
 typedef int    (* kblock_store_t)       (struct KBlock *b, block_idx_t index);
 
 typedef int    (* kblock_error_t)       (struct KBlock *b);
-typedef int    (* kblock_clearerr_t)    (struct KBlock *b);
+typedef void   (* kblock_clearerr_t)    (struct KBlock *b);
 typedef int    (* kblock_close_t)       (struct KBlock *b);
 /* \} */
 
@@ -206,12 +206,24 @@ INLINE int kblock_error(struct KBlock *b)
  *
  * \sa kblock_error()
  */
-INLINE int kblock_clearerr(struct KBlock *b)
+INLINE void kblock_clearerr(struct KBlock *b)
 {
        KB_ASSERT_METHOD(b, clearerr);
-       return b->priv.vt->clearerr(b);
+       b->priv.vt->clearerr(b);
 }
 
+
+/**
+ * Flush the cache (if any) to the device.
+ *
+ * This function will write any pending modifications to the device.
+ * If the device does not have a cache, this function will do nothing.
+ *
+ * \return 0 if all is OK, EOF on errors.
+ * \sa kblock_read(), kblock_write(), kblock_buffered().
+ */
+int kblock_flush(struct KBlock *b);
+
 /**
  * Close the device.
  *
@@ -222,7 +234,7 @@ INLINE int kblock_clearerr(struct KBlock *b)
 INLINE int kblock_close(struct KBlock *b)
 {
        KB_ASSERT_METHOD(b, close);
-       return b->priv.vt->close(b);
+       return kblock_flush(b) | b->priv.vt->close(b);
 }
 
 /**
@@ -331,19 +343,6 @@ size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset,
  */
 size_t kblock_write(struct KBlock *b, block_idx_t idx, const void *buf, size_t offset, size_t size);
 
-
-/**
- * Flush the cache (if any) to the device.
- *
- * This function will write any pending modifications to the device.
- * If the device does not have a cache, this function will do nothing.
- *
- * \return 0 if all is OK, EOF on errors.
- * \sa kblock_read(), kblock_write(), kblock_buffered().
- */
-int kblock_flush(struct KBlock *b);
-
-
 /**
  * Copy one block to another.
  *
index e3780d7d92777a7b8fc3ba2aab7c6223e2d6c8d9..70899ce32a5bef92a4b63b28969eabe56cd66b31 100644 (file)
@@ -100,7 +100,7 @@ static const KBlockVTable kblockram_hwbuffered_vt =
        .store = kblockram_store,
 
        .error = kblockram_dummy,
-       .clearerr = kblockram_dummy,
+       .clearerr = (kblock_clearerr_t)kblockram_dummy,
        .close = kblockram_dummy,
 };
 
@@ -116,7 +116,7 @@ static const KBlockVTable kblockram_swbuffered_vt =
        .store = kblock_swStore,
 
        .error = kblockram_dummy,
-       .clearerr = kblockram_dummy,
+       .clearerr = (kblock_clearerr_t)kblockram_dummy,
        .close = kblockram_dummy,
 };
 
@@ -126,7 +126,7 @@ static const KBlockVTable kblockram_unbuffered_vt =
        .writeDirect = kblockram_writeDirect,
 
        .error = kblockram_dummy,
-       .clearerr = kblockram_dummy,
+       .clearerr = (kblock_clearerr_t)kblockram_dummy,
        .close = kblockram_dummy,
 };