Demo apps refactoring
authorgkostka <kostka.grzegorz@gmail.com>
Mon, 21 Sep 2015 20:58:46 +0000 (22:58 +0200)
committergkostka <kostka.grzegorz@gmail.com>
Mon, 21 Sep 2015 22:19:51 +0000 (00:19 +0200)
24 files changed:
CMakeLists.txt
blockdev/CMakeLists.txt
blockdev/chibios/sdc_lwext4.c [new file with mode: 0644]
blockdev/chibios/sdc_lwext4.h [new file with mode: 0644]
blockdev/chibios/spi_lwext4.c [new file with mode: 0644]
blockdev/chibios/spi_lwext4.h [new file with mode: 0644]
blockdev/chibios/timings.c [new file with mode: 0644]
blockdev/filedev/ext4_filedev.c [deleted file]
blockdev/filedev/ext4_filedev.h [deleted file]
blockdev/filedev_win/io_raw.c [deleted file]
blockdev/filedev_win/io_raw.h [deleted file]
blockdev/linux/ext4_filedev.c [new file with mode: 0644]
blockdev/linux/ext4_filedev.h [new file with mode: 0644]
blockdev/test_lwext4.c [new file with mode: 0644]
blockdev/test_lwext4.h [new file with mode: 0644]
blockdev/windows/io_raw.c [new file with mode: 0644]
blockdev/windows/io_raw.h [new file with mode: 0644]
demos/generic/CMakeLists.txt
demos/generic/generic.c [new file with mode: 0644]
demos/generic/main.c [deleted file]
demos/stm32f429_disco/CMakeLists.txt
demos/stm32f429_disco/main.c
demos/stm32f429_disco/usb_msc_lwext4.c
demos/stm32f429_disco/usb_msc_lwext4.h

index baf5e40d6fd476212bc3b251e70a0b68428ebc93..1ae2c5ba34aa1d563e3a5af576dc8d21ca57cede 100644 (file)
@@ -6,6 +6,7 @@ include_directories(lwext4)
 include_directories(blockdev/filedev)\r
 include_directories(blockdev/filedev_win)\r
 \r
+set(BLOCKDEV_TYPE  none)\r
 \r
 #Examples\r
 if    (CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m0)\r
@@ -34,11 +35,13 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  msp430g2210)
     #...\r
 else()\r
     #Generic example target\r
-    add_subdirectory(blockdev)\r
+    set(BLOCKDEV_TYPE  linux)\r
     add_subdirectory(fs_test)\r
     add_subdirectory(demos/generic)\r
 endif()\r
 \r
+add_subdirectory(blockdev)\r
+\r
 #Library build\r
 add_subdirectory(lwext4)\r
 #Detect all possible warnings for lwext4 target\r
index 0f1f20ba8e842497d63855a8a899d28171d9ff82..2099d503a4484fad0fa6331fde4de53639622b41 100644 (file)
@@ -1,5 +1,15 @@
 #Blockdev library\r
-aux_source_directory(filedev BLOCKDEV_SRC)\r
-aux_source_directory(filedev_win BLOCKDEV_SRC)\r
+\r
+if    (BLOCKDEV_TYPE STREQUAL  linux)\r
+aux_source_directory(linux BLOCKDEV_SRC)\r
+elseif    (BLOCKDEV_TYPE STREQUAL  windows)\r
+aux_source_directory(windows BLOCKDEV_SRC)\r
+elseif    (BLOCKDEV_TYPE STREQUAL  chibios)\r
+aux_source_directory(chibios BLOCKDEV_SRC)\r
+else()\r
+endif()\r
+\r
+aux_source_directory(. BLOCKDEV_SRC)\r
+\r
 add_library(blockdev  ${BLOCKDEV_SRC})\r
 \r
diff --git a/blockdev/chibios/sdc_lwext4.c b/blockdev/chibios/sdc_lwext4.c
new file mode 100644 (file)
index 0000000..de2f5ae
--- /dev/null
@@ -0,0 +1,184 @@
+/*\r
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * - Redistributions of source code must retain the above copyright\r
+ *   notice, this list of conditions and the following disclaimer.\r
+ * - Redistributions in binary form must reproduce the above copyright\r
+ *   notice, this list of conditions and the following disclaimer in the\r
+ *   documentation and/or other materials provided with the distribution.\r
+ * - The name of the author may not be used to endorse or promote products\r
+ *   derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#include "../chibios/sdc_lwext4.h"\r
+\r
+#include <config.h>\r
+#include <ext4_config.h>\r
+#include <ext4_blockdev.h>\r
+#include <ext4_errno.h>\r
+#include <stdio.h>\r
+#include <stdbool.h>\r
+#include <string.h>\r
+#include <fcntl.h>\r
+\r
+#include <hal.h>\r
+#include <sdc.h>\r
+\r
+\r
+/**@brief   Block size.*/\r
+#define SDC_BLOCK_SIZE 512\r
+\r
+/**@brief   MBR_block ID*/\r
+#define MBR_BLOCK_ID 0\r
+#define MBR_PART_TABLE_OFF 446\r
+\r
+struct part_tab_entry {\r
+       uint8_t status;\r
+       uint8_t chs1[3];\r
+       uint8_t type;\r
+       uint8_t chs2[3];\r
+       uint32_t first_lba;\r
+       uint32_t sectors;\r
+} __attribute__((packed));\r
+\r
+/**@brief   Partition block offset*/\r
+static uint32_t part_offset;\r
+\r
+/**@brief IO timings*/\r
+struct sdc_io_timings {\r
+       uint64_t acc_bread;\r
+       uint64_t acc_bwrite;\r
+\r
+       uint32_t cnt_bread;\r
+       uint32_t cnt_bwrite;\r
+\r
+       uint32_t av_bread;\r
+       uint32_t av_bwrite;\r
+};\r
+\r
+static struct sdc_io_timings io_timings;\r
+\r
+void io_timings_clear(void)\r
+{\r
+       memset(&io_timings, 0, sizeof(struct sdc_io_timings));\r
+}\r
+\r
+const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms)\r
+{\r
+       static struct ext4_io_stats s;\r
+\r
+       s.io_read = (((float)io_timings.acc_bread * 100.0) / time_sum_ms);\r
+       s.io_read /= 1000.0;\r
+\r
+       s.io_write = (((float)io_timings.acc_bwrite * 100.0) / time_sum_ms);\r
+       s.io_write /= 1000.0;\r
+\r
+       s.cpu = 100.0 - s.io_read - s.io_write;\r
+\r
+       return &s;\r
+}\r
+\r
+/**********************BLOCKDEV INTERFACE**************************************/\r
+static int sdc_open(struct ext4_blockdev *bdev);\r
+static int sdc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,\r
+                    uint32_t blk_cnt);\r
+static int sdc_bwrite(struct ext4_blockdev *bdev, const void *buf,\r
+                     uint64_t blk_id, uint32_t blk_cnt);\r
+static int sdc_close(struct ext4_blockdev *bdev);\r
+\r
+/******************************************************************************/\r
+EXT4_BLOCKDEV_STATIC_INSTANCE(_sdc, SDC_BLOCK_SIZE, 0, sdc_open, sdc_bread,\r
+                             sdc_bwrite, sdc_close);\r
+\r
+/******************************************************************************/\r
+EXT4_BCACHE_STATIC_INSTANCE(_sdc_cache, CONFIG_BLOCK_DEV_CACHE_SIZE,\r
+                           EXT_LOGICAL_BLOCK_SIZE);\r
+\r
+/******************************************************************************/\r
+\r
+static int sdc_open(struct ext4_blockdev *bdev)\r
+{\r
+       (void)bdev;\r
+\r
+       static uint8_t mbr[512];\r
+       struct part_tab_entry *part0;\r
+\r
+       sdcStart(&SDCD1, NULL);\r
+\r
+       if (sdcConnect(&SDCD1) != HAL_SUCCESS)\r
+               return EIO;\r
+\r
+       if (sdcRead(&SDCD1, 0, mbr, 1) != HAL_SUCCESS)\r
+               return EIO;\r
+\r
+       part0 = (struct part_tab_entry *)(mbr + MBR_PART_TABLE_OFF);\r
+\r
+       part_offset = part0->first_lba;\r
+       _sdc.ph_bcnt = SDCD1.capacity * SDC_BLOCK_SIZE;\r
+\r
+       return EOK;\r
+}\r
+\r
+static int sdc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,\r
+                    uint32_t blk_cnt)\r
+{\r
+       (void)bdev;\r
+       bool status;\r
+       uint64_t v = tim_get_us();\r
+\r
+       status = sdcRead(&SDCD1, blk_id, buf, blk_cnt);\r
+       if (status != HAL_SUCCESS)\r
+               return EIO;\r
+\r
+       io_timings.acc_bread += tim_get_us() - v;\r
+       io_timings.cnt_bread++;\r
+       io_timings.av_bread = io_timings.acc_bread / io_timings.cnt_bread;\r
+\r
+       return EOK;\r
+}\r
+\r
+static int sdc_bwrite(struct ext4_blockdev *bdev, const void *buf,\r
+                     uint64_t blk_id, uint32_t blk_cnt)\r
+{\r
+       (void)bdev;\r
+       bool status;\r
+       uint64_t v = tim_get_us();\r
+\r
+       status = sdcWrite(&SDCD1, blk_id, buf, blk_cnt);\r
+       if (status != HAL_SUCCESS)\r
+               return EIO;\r
+\r
+       io_timings.acc_bwrite += tim_get_us() - v;\r
+       io_timings.cnt_bwrite++;\r
+       io_timings.av_bwrite = io_timings.acc_bwrite / io_timings.cnt_bwrite;\r
+\r
+       return EOK;\r
+}\r
+\r
+static int sdc_close(struct ext4_blockdev *bdev)\r
+{\r
+       (void)bdev;\r
+       return EOK;\r
+}\r
+\r
+/******************************************************************************/\r
+\r
+struct ext4_bcache *sdc_cache_get(void) { return &_sdc_cache; }\r
+\r
+struct ext4_blockdev *sdc_bdev_get(void) { return &_sdc; }\r
diff --git a/blockdev/chibios/sdc_lwext4.h b/blockdev/chibios/sdc_lwext4.h
new file mode 100644 (file)
index 0000000..f70194a
--- /dev/null
@@ -0,0 +1,45 @@
+/*\r
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * - Redistributions of source code must retain the above copyright\r
+ *   notice, this list of conditions and the following disclaimer.\r
+ * - Redistributions in binary form must reproduce the above copyright\r
+ *   notice, this list of conditions and the following disclaimer in the\r
+ *   documentation and/or other materials provided with the distribution.\r
+ * - The name of the author may not be used to endorse or promote products\r
+ *   derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#ifndef SDC_LWEXT4_H_\r
+#define SDC_LWEXT4_H_\r
+\r
+#include <config.h>\r
+#include <ext4_config.h>\r
+#include <ext4_blockdev.h>\r
+\r
+#include <stdint.h>\r
+#include <stdbool.h>\r
+\r
+/**@brief   SDC cache get.*/\r
+struct ext4_bcache *sdc_cache_get(void);\r
+\r
+/**@brief   SDC blockdev get.*/\r
+struct ext4_blockdev *sdc_bdev_get(void);\r
+\r
+\r
+#endif /* CHIBI_SDC_LWEXT4_H_ */\r
diff --git a/blockdev/chibios/spi_lwext4.c b/blockdev/chibios/spi_lwext4.c
new file mode 100644 (file)
index 0000000..a67ca79
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "../chibios/spi_lwext4.h"
+
+#include <config.h>
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include <hal.h>
+#include <mmc_spi.h>
+
+
+#if HAL_USE_MMC_SPI
+extern MMCDriver MMCD1;
+#endif
+
+/**@brief   Block size.*/
+#define SPI_BLOCK_SIZE 512
+
+/**@brief   MBR_block ID*/
+#define MBR_BLOCK_ID 0
+#define MBR_PART_TABLE_OFF 446
+
+struct part_tab_entry {
+       uint8_t status;
+       uint8_t chs1[3];
+       uint8_t type;
+       uint8_t chs2[3];
+       uint32_t first_lba;
+       uint32_t sectors;
+} __attribute__((packed));
+
+/**@brief   Partition block offset*/
+static uint32_t part_offset;
+
+/**@brief IO timings*/
+struct spi_io_timings {
+       uint64_t acc_bread;
+       uint64_t acc_bwrite;
+
+       uint32_t cnt_bread;
+       uint32_t cnt_bwrite;
+
+       uint32_t av_bread;
+       uint32_t av_bwrite;
+};
+
+static struct spi_io_timings io_timings;
+
+void io_timings_clear(void)
+{
+       memset(&io_timings, 0, sizeof(struct spi_io_timings));
+}
+
+const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms)
+{
+       static struct ext4_io_stats s;
+
+       s.io_read = (((float)io_timings.acc_bread * 100.0) / time_sum_ms);
+       s.io_read /= 1000.0;
+
+       s.io_write = (((float)io_timings.acc_bwrite * 100.0) / time_sum_ms);
+       s.io_write /= 1000.0;
+
+       s.cpu = 100.0 - s.io_read - s.io_write;
+
+       return &s;
+}
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int spi_open(struct ext4_blockdev *bdev);
+static int spi_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+                    uint32_t blk_cnt);
+static int spi_bwrite(struct ext4_blockdev *bdev, const void *buf,
+                     uint64_t blk_id, uint32_t blk_cnt);
+static int spi_close(struct ext4_blockdev *bdev);
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(_spi, SPI_BLOCK_SIZE, 0, spi_open, spi_bread,
+                             spi_bwrite, spi_close);
+
+/******************************************************************************/
+EXT4_BCACHE_STATIC_INSTANCE(_spi_cache, CONFIG_BLOCK_DEV_CACHE_SIZE,
+                           EXT_LOGICAL_BLOCK_SIZE);
+
+/******************************************************************************/
+
+static int spi_open(struct ext4_blockdev *bdev)
+{
+
+       (void)bdev;
+
+       static uint8_t mbr[512];
+       struct part_tab_entry *part0;
+
+       if (mmcConnect(&MMCD1) != HAL_SUCCESS)
+               return EIO;
+
+       if (mmcStartSequentialRead(&MMCD1, 0) != HAL_SUCCESS)
+               return EIO;
+
+       if (mmcSequentialRead(&MMCD1, mbr) != HAL_SUCCESS)
+               return EIO;
+
+       if (mmcStopSequentialRead(&MMCD1) != HAL_SUCCESS)
+               return EIO;
+
+       part0 = (struct part_tab_entry *)(mbr + MBR_PART_TABLE_OFF);
+
+       part_offset = part0->first_lba;
+       _spi.ph_bcnt = MMCD1.capacity * SPI_BLOCK_SIZE;
+
+       return EOK;
+}
+
+static int spi_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+                    uint32_t blk_cnt)
+{
+       (void)bdev;
+       uint64_t v = tim_get_us();
+
+       if (mmcStartSequentialRead(&MMCD1, blk_id) != HAL_SUCCESS)
+               return EIO;
+
+       while (blk_cnt) {
+               if (mmcSequentialRead(&MMCD1, buf) != HAL_SUCCESS)
+                       return EIO;
+
+               buf += SPI_BLOCK_SIZE;
+               blk_cnt--;
+       }
+
+       if (mmcStopSequentialRead(&MMCD1) != HAL_SUCCESS)
+               return EIO;
+
+       io_timings.acc_bread += tim_get_us() - v;
+       io_timings.cnt_bread++;
+       io_timings.av_bread = io_timings.acc_bread / io_timings.cnt_bread;
+
+       return EOK;
+}
+
+static int spi_bwrite(struct ext4_blockdev *bdev, const void *buf,
+                     uint64_t blk_id, uint32_t blk_cnt)
+{
+       (void)bdev;
+       uint64_t v = tim_get_us();
+
+       if (mmcStartSequentialWrite(&MMCD1, blk_id) != HAL_SUCCESS)
+               return EIO;
+
+       while (blk_cnt) {
+               if (mmcSequentialWrite(&MMCD1, buf) != HAL_SUCCESS)
+                       return EIO;
+
+               buf += SPI_BLOCK_SIZE;
+               blk_cnt--;
+       }
+
+       if (mmcStopSequentialWrite(&MMCD1) != HAL_SUCCESS)
+               return EIO;
+
+       io_timings.acc_bwrite += tim_get_us() - v;
+       io_timings.cnt_bwrite++;
+       io_timings.av_bwrite = io_timings.acc_bwrite / io_timings.cnt_bwrite;
+
+       return EOK;
+}
+
+static int spi_close(struct ext4_blockdev *bdev)
+{
+       (void)bdev;
+       return EOK;
+}
+
+/******************************************************************************/
+
+struct ext4_bcache *spi_cache_get(void) { return &_spi_cache; }
+
+struct ext4_blockdev *spi_bdev_get(void) { return &_spi; }
diff --git a/blockdev/chibios/spi_lwext4.h b/blockdev/chibios/spi_lwext4.h
new file mode 100644 (file)
index 0000000..292c4f0
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * spi_lwext4.h
+ *
+ *  Created on: 21 gru 2014
+ *      Author: gko
+ */
+
+#ifndef SPI_LWEXT4_H_
+#define SPI_LWEXT4_H_
+
+#include <config.h>
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief   SPI cache get.*/
+struct ext4_bcache *spi_cache_get(void);
+
+/**@brief   SPI blockdev get.*/
+struct ext4_blockdev *spi_bdev_get(void);
+
+#endif /* SPI_LWEXT4_H_ */
diff --git a/blockdev/chibios/timings.c b/blockdev/chibios/timings.c
new file mode 100644 (file)
index 0000000..8f05d58
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "../chibios/timings.h"
+
+#include <config.h>
+
+#include <ch.h>
+#include <chvt.h>
+
+
+void tim_wait_ms(uint32_t v) { chThdSleepMilliseconds(v); }
+
+uint64_t tim_get_us(void)
+{
+       uint64_t v = chVTGetSystemTimeX();
+       return ST2US(v);
+}
+
+uint32_t tim_get_ms(void)
+{
+       uint32_t v = chVTGetSystemTimeX();
+       return ST2MS(v);
+}
diff --git a/blockdev/filedev/ext4_filedev.c b/blockdev/filedev/ext4_filedev.c
deleted file mode 100644 (file)
index 14fae75..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#define _FILE_OFFSET_BITS 64
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <ext4_errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <fcntl.h>
-
-/**@brief   Default filename.*/
-static const char *fname = "ext2";
-
-/**@brief   Image block size.*/
-#define EXT4_FILEDEV_BSIZE 512
-
-/**@brief   Image file descriptor.*/
-static FILE *dev_file;
-
-#define DROP_LINUXCACHE_BUFFERS 0
-
-/**********************BLOCKDEV INTERFACE**************************************/
-static int filedev_open(struct ext4_blockdev *bdev);
-static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
-                        uint32_t blk_cnt);
-static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
-                         uint64_t blk_id, uint32_t blk_cnt);
-static int filedev_close(struct ext4_blockdev *bdev);
-
-/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_FILEDEV_BSIZE, 0, filedev_open,
-                             filedev_bread, filedev_bwrite, filedev_close);
-
-/******************************************************************************/
-static int filedev_open(struct ext4_blockdev *bdev)
-{
-       dev_file = fopen(fname, "r+b");
-
-       if (!dev_file)
-               return EIO;
-
-       /*No buffering at file.*/
-       setbuf(dev_file, 0);
-
-       if (fseek(dev_file, 0, SEEK_END))
-               return EFAULT;
-
-       _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize;
-
-       return EOK;
-}
-
-/******************************************************************************/
-
-static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
-                        uint32_t blk_cnt)
-{
-       if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
-               return EIO;
-
-       if (!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
-               return EIO;
-
-       return EOK;
-}
-
-static void drop_cache(void)
-{
-#if defined(__linux__) && DROP_LINUXCACHE_BUFFERS
-       int fd;
-       char *data = "3";
-
-       sync();
-       fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
-       write(fd, data, sizeof(char));
-       close(fd);
-#endif
-}
-
-/******************************************************************************/
-static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
-                         uint64_t blk_id, uint32_t blk_cnt)
-{
-       if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
-               return EIO;
-
-       if (!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
-               return EIO;
-
-       drop_cache();
-       return EOK;
-}
-/******************************************************************************/
-static int filedev_close(struct ext4_blockdev *bdev)
-{
-       fclose(dev_file);
-       return EOK;
-}
-
-/******************************************************************************/
-struct ext4_blockdev *ext4_filedev_get(void) { return &_filedev; }
-/******************************************************************************/
-void ext4_filedev_filename(const char *n) { fname = n; }
-
-/******************************************************************************/
diff --git a/blockdev/filedev/ext4_filedev.h b/blockdev/filedev/ext4_filedev.h
deleted file mode 100644 (file)
index 8f13d9a..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef EXT4_FILEDEV_H_
-#define EXT4_FILEDEV_H_
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-
-#include <stdint.h>
-#include <stdbool.h>
-
-/**@brief   File blockdev get.*/
-struct ext4_blockdev *ext4_filedev_get(void);
-
-/**@brief   Set filename to open.*/
-void ext4_filedev_filename(const char *n);
-
-#endif /* EXT4_FILEDEV_H_ */
diff --git a/blockdev/filedev_win/io_raw.c b/blockdev/filedev_win/io_raw.c
deleted file mode 100644 (file)
index 902cd4f..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*\r
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * - Redistributions of source code must retain the above copyright\r
- *   notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- *   notice, this list of conditions and the following disclaimer in the\r
- *   documentation and/or other materials provided with the distribution.\r
- * - The name of the author may not be used to endorse or promote products\r
- *   derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-\r
-#include <ext4_config.h>\r
-#include <ext4_blockdev.h>\r
-#include <ext4_errno.h>\r
-#include <stdio.h>\r
-#include <stdbool.h>\r
-#include <string.h>\r
-\r
-#ifdef WIN32\r
-#include <windows.h>\r
-#include <winioctl.h>\r
-\r
-/**@brief   Default filename.*/\r
-static const char *fname = "ext2";\r
-\r
-/**@brief   IO block size.*/\r
-#define EXT4_IORAW_BSIZE 512\r
-\r
-/**@brief   Image file descriptor.*/\r
-static HANDLE dev_file;\r
-\r
-/**********************BLOCKDEV INTERFACE**************************************/\r
-static int io_raw_open(struct ext4_blockdev *bdev);\r
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,\r
-                       uint32_t blk_cnt);\r
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,\r
-                        uint64_t blk_id, uint32_t blk_cnt);\r
-static int io_raw_close(struct ext4_blockdev *bdev);\r
-\r
-/******************************************************************************/\r
-EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,\r
-                             io_raw_bread, io_raw_bwrite, io_raw_close);\r
-\r
-/******************************************************************************/\r
-static int io_raw_open(struct ext4_blockdev *bdev)\r
-{\r
-       char path[64];\r
-       DISK_GEOMETRY pdg;\r
-       uint64_t disk_size;\r
-       BOOL bResult = FALSE;\r
-       DWORD junk;\r
-\r
-       sprintf(path, "\\\\.\\%s", fname);\r
-\r
-       dev_file =\r
-           CreateFile(path, GENERIC_READ | GENERIC_WRITE,\r
-                      FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,\r
-                      FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);\r
-\r
-       if (dev_file == INVALID_HANDLE_VALUE) {\r
-               return EIO;\r
-       }\r
-\r
-       bResult =\r
-           DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,\r
-                           &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);\r
-\r
-       if (bResult == FALSE) {\r
-               CloseHandle(dev_file);\r
-               return EIO;\r
-       }\r
-\r
-       disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *\r
-                   (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;\r
-\r
-       _filedev.ph_bsize = pdg.BytesPerSector;\r
-       _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;\r
-\r
-       return EOK;\r
-}\r
-\r
-/******************************************************************************/\r
-\r
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,\r
-                       uint32_t blk_cnt)\r
-{\r
-       long hipart = blk_id >> (32 - 9);\r
-       long lopart = blk_id << 9;\r
-       long err;\r
-\r
-       SetLastError(0);\r
-       lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);\r
-\r
-       if (lopart == -1 && NO_ERROR != (err = GetLastError())) {\r
-               return EIO;\r
-       }\r
-\r
-       DWORD n;\r
-\r
-       if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {\r
-               err = GetLastError();\r
-               return EIO;\r
-       }\r
-       return EOK;\r
-}\r
-\r
-/******************************************************************************/\r
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,\r
-                        uint64_t blk_id, uint32_t blk_cnt)\r
-{\r
-       long hipart = blk_id >> (32 - 9);\r
-       long lopart = blk_id << 9;\r
-       long err;\r
-\r
-       SetLastError(0);\r
-       lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);\r
-\r
-       if (lopart == -1 && NO_ERROR != (err = GetLastError())) {\r
-               return EIO;\r
-       }\r
-\r
-       DWORD n;\r
-\r
-       if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {\r
-               err = GetLastError();\r
-               return EIO;\r
-       }\r
-       return EOK;\r
-}\r
-\r
-/******************************************************************************/\r
-static int io_raw_close(struct ext4_blockdev *bdev)\r
-{\r
-       CloseHandle(dev_file);\r
-       return EOK;\r
-}\r
-\r
-/******************************************************************************/\r
-struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }\r
-/******************************************************************************/\r
-void ext4_io_raw_filename(const char *n) { fname = n; }\r
-\r
-/******************************************************************************/\r
-#endif\r
diff --git a/blockdev/filedev_win/io_raw.h b/blockdev/filedev_win/io_raw.h
deleted file mode 100644 (file)
index cfd6561..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*\r
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * - Redistributions of source code must retain the above copyright\r
- *   notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- *   notice, this list of conditions and the following disclaimer in the\r
- *   documentation and/or other materials provided with the distribution.\r
- * - The name of the author may not be used to endorse or promote products\r
- *   derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-#ifndef IO_RAW_H_\r
-#define IO_RAW_H_\r
-\r
-#include <ext4_config.h>\r
-#include <ext4_blockdev.h>\r
-\r
-#include <stdint.h>\r
-#include <stdbool.h>\r
-\r
-/**@brief   IO raw blockdev get.*/\r
-struct ext4_blockdev *ext4_io_raw_dev_get(void);\r
-\r
-/**@brief   Set filrname to open.*/\r
-void ext4_io_raw_filename(const char *n);\r
-\r
-#endif /* IO_RAW_H_ */\r
diff --git a/blockdev/linux/ext4_filedev.c b/blockdev/linux/ext4_filedev.c
new file mode 100644 (file)
index 0000000..14fae75
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define _FILE_OFFSET_BITS 64
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+
+/**@brief   Default filename.*/
+static const char *fname = "ext2";
+
+/**@brief   Image block size.*/
+#define EXT4_FILEDEV_BSIZE 512
+
+/**@brief   Image file descriptor.*/
+static FILE *dev_file;
+
+#define DROP_LINUXCACHE_BUFFERS 0
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int filedev_open(struct ext4_blockdev *bdev);
+static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+                        uint32_t blk_cnt);
+static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
+                         uint64_t blk_id, uint32_t blk_cnt);
+static int filedev_close(struct ext4_blockdev *bdev);
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_FILEDEV_BSIZE, 0, filedev_open,
+                             filedev_bread, filedev_bwrite, filedev_close);
+
+/******************************************************************************/
+static int filedev_open(struct ext4_blockdev *bdev)
+{
+       dev_file = fopen(fname, "r+b");
+
+       if (!dev_file)
+               return EIO;
+
+       /*No buffering at file.*/
+       setbuf(dev_file, 0);
+
+       if (fseek(dev_file, 0, SEEK_END))
+               return EFAULT;
+
+       _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize;
+
+       return EOK;
+}
+
+/******************************************************************************/
+
+static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+                        uint32_t blk_cnt)
+{
+       if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
+               return EIO;
+
+       if (!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
+               return EIO;
+
+       return EOK;
+}
+
+static void drop_cache(void)
+{
+#if defined(__linux__) && DROP_LINUXCACHE_BUFFERS
+       int fd;
+       char *data = "3";
+
+       sync();
+       fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
+       write(fd, data, sizeof(char));
+       close(fd);
+#endif
+}
+
+/******************************************************************************/
+static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
+                         uint64_t blk_id, uint32_t blk_cnt)
+{
+       if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
+               return EIO;
+
+       if (!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
+               return EIO;
+
+       drop_cache();
+       return EOK;
+}
+/******************************************************************************/
+static int filedev_close(struct ext4_blockdev *bdev)
+{
+       fclose(dev_file);
+       return EOK;
+}
+
+/******************************************************************************/
+struct ext4_blockdev *ext4_filedev_get(void) { return &_filedev; }
+/******************************************************************************/
+void ext4_filedev_filename(const char *n) { fname = n; }
+
+/******************************************************************************/
diff --git a/blockdev/linux/ext4_filedev.h b/blockdev/linux/ext4_filedev.h
new file mode 100644 (file)
index 0000000..8f13d9a
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef EXT4_FILEDEV_H_
+#define EXT4_FILEDEV_H_
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief   File blockdev get.*/
+struct ext4_blockdev *ext4_filedev_get(void);
+
+/**@brief   Set filename to open.*/
+void ext4_filedev_filename(const char *n);
+
+#endif /* EXT4_FILEDEV_H_ */
diff --git a/blockdev/test_lwext4.c b/blockdev/test_lwext4.c
new file mode 100644 (file)
index 0000000..061ee8e
--- /dev/null
@@ -0,0 +1,375 @@
+/*
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <ext4.h>
+
+#include <stdio.h>
+#include <time.h>
+#include <inttypes.h>
+#include <string.h>
+
+#include "test_lwext4.h"
+
+/**@brief   Read-write size*/
+#define READ_MAX_WRITE_SZIZE 1024 * 8
+
+/**@brief   File read/write buffer*/
+static uint8_t rw_buff[READ_MAX_WRITE_SZIZE];
+
+/**@brief   Block device handle.*/
+static struct ext4_blockdev *bd;
+
+/**@brief   Block cache handle.*/
+static struct ext4_bcache *bc;
+
+static char *entry_to_str(uint8_t type)
+{
+       switch (type) {
+       case EXT4_DIRENTRY_UNKNOWN:
+               return "[unk] ";
+       case EXT4_DIRENTRY_REG_FILE:
+               return "[fil] ";
+       case EXT4_DIRENTRY_DIR:
+               return "[dir] ";
+       case EXT4_DIRENTRY_CHRDEV:
+               return "[cha] ";
+       case EXT4_DIRENTRY_BLKDEV:
+               return "[blk] ";
+       case EXT4_DIRENTRY_FIFO:
+               return "[fif] ";
+       case EXT4_DIRENTRY_SOCK:
+               return "[soc] ";
+       case EXT4_DIRENTRY_SYMLINK:
+               return "[sym] ";
+       default:
+               break;
+       }
+       return "[???]";
+}
+
+static clock_t get_ms(void) { return tim_get_ms(); }
+
+static void printf_io_timings(clock_t diff)
+{
+       const struct ext4_io_stats *stats = io_timings_get(diff);
+       printf("io_timings:\n");
+       printf("  io_read: %.3f%%\n", stats->io_read);
+       printf("  io_write: %.3f%%\n", stats->io_write);
+       printf("  io_cpu: %.3f%%\n", stats->cpu);
+}
+
+void test_lwext4_dir_ls(const char *path)
+{
+       char sss[255];
+       ext4_dir d;
+       const ext4_direntry *de;
+
+       printf("ls %s\n", path);
+
+       ext4_dir_open(&d, path);
+       de = ext4_dir_entry_next(&d);
+
+       while (de) {
+               memcpy(sss, de->name, de->name_length);
+               sss[de->name_length] = 0;
+               printf("  %s%s\n", entry_to_str(de->inode_type), sss);
+               de = ext4_dir_entry_next(&d);
+       }
+       ext4_dir_close(&d);
+}
+
+void test_lwext4_mp_stats(void)
+{
+       struct ext4_mount_stats stats;
+       ext4_mount_point_stats("/mp/", &stats);
+
+       printf("********************\n");
+       printf("ext4_mount_point_stats\n");
+       printf("inodes_count = %" PRIu32 "\n", stats.inodes_count);
+       printf("free_inodes_count = %" PRIu32 "\n", stats.free_inodes_count);
+       printf("blocks_count = %" PRIu32 "\n", (uint32_t)stats.blocks_count);
+       printf("free_blocks_count = %" PRIu32 "\n",
+              (uint32_t)stats.free_blocks_count);
+       printf("block_size = %" PRIu32 "\n", stats.block_size);
+       printf("block_group_count = %" PRIu32 "\n", stats.block_group_count);
+       printf("blocks_per_group= %" PRIu32 "\n", stats.blocks_per_group);
+       printf("inodes_per_group = %" PRIu32 "\n", stats.inodes_per_group);
+       printf("volume_name = %s\n", stats.volume_name);
+       printf("********************\n");
+}
+
+void test_lwext4_block_stats(void)
+{
+       if (!bd)
+               return;
+
+       printf("********************\n");
+       printf("ext4 blockdev stats\n");
+       printf("bdev->bread_ctr = %" PRIu32 "\n", bd->bread_ctr);
+       printf("bdev->bwrite_ctr = %" PRIu32 "\n", bd->bwrite_ctr);
+
+       printf("bcache->ref_blocks = %" PRIu32 "\n", bc->ref_blocks);
+       printf("bcache->max_ref_blocks = %" PRIu32 "\n", bc->max_ref_blocks);
+       printf("bcache->lru_ctr = %" PRIu32 "\n", bc->lru_ctr);
+
+       printf("\n");
+
+       uint32_t i;
+       for (i = 0; i < bc->cnt; ++i) {
+               printf("bcache->refctr[%" PRIu32 "]= %" PRIu32 "\n", i,
+                      bc->refctr[i]);
+       }
+
+       printf("\n");
+       for (i = 0; i < bc->cnt; ++i) {
+               printf("bcache->lru_id[%" PRIu32 "] = %" PRIu32 "\n", i,
+                      bc->lru_id[i]);
+       }
+
+       printf("\n");
+       for (i = 0; i < bc->cnt; ++i) {
+               printf("bcache->free_delay[%" PRIu32 "] = %d\n", i,
+                      bc->free_delay[i]);
+       }
+
+       printf("\n");
+       for (i = 0; i < bc->cnt; ++i) {
+               printf("bcache->lba[%" PRIu32 "] = %" PRIu32 "\n", i,
+                      (uint32_t)bc->lba[i]);
+       }
+
+       printf("********************\n");
+}
+
+bool test_lwext4_dir_test(int len)
+{
+       ext4_file f;
+       int r;
+       int i;
+       char path[64];
+       clock_t diff;
+       clock_t stop;
+       clock_t start;
+
+       printf("test_lwext4_dir_test: %d\n", len);
+       io_timings_clear();
+       start = get_ms();
+
+       printf("directory create: /mp/dir1\n");
+       r = ext4_dir_mk("/mp/dir1");
+       if (r != EOK) {
+               printf("ext4_dir_mk: rc = %d\n", r);
+               return false;
+       }
+
+       printf("add files to: /mp/dir1\n");
+       for (i = 0; i < len; ++i) {
+               sprintf(path, "/mp/dir1/f%d", i);
+               r = ext4_fopen(&f, path, "wb");
+               if (r != EOK) {
+                       printf("ext4_fopen: rc = %d\n", r);
+                       return false;
+               }
+       }
+
+       stop = get_ms();
+       diff = stop - start;
+       test_lwext4_dir_ls("/mp/dir1");
+       printf("test_lwext4_dir_test: time: %d ms\n", (int)diff);
+       printf("test_lwext4_dir_test: av: %d ms/entry\n", (int)diff / len);
+       printf_io_timings(diff);
+       return true;
+}
+
+static int verify_buf(const unsigned char *b, size_t len, unsigned char c)
+{
+       size_t i;
+       for (i = 0; i < len; ++i) {
+               if (b[i] != c)
+                       return c - b[i];
+       }
+
+       return 0;
+}
+
+bool test_lwext4_file_test(uint32_t rw_szie, uint32_t rw_count)
+{
+       int r;
+       size_t size;
+       uint32_t i;
+       clock_t start;
+       clock_t stop;
+       clock_t diff;
+       uint32_t kbps;
+       uint64_t size_bytes;
+
+       ext4_file f;
+
+       printf("file_test:\n");
+       printf("  rw size: %" PRIu32 "\n", rw_szie);
+       printf("  rw count: %" PRIu32 "\n", rw_count);
+
+       /*Add hello world file.*/
+       r = ext4_fopen(&f, "/mp/hello.txt", "wb");
+       r = ext4_fwrite(&f, "Hello World !\n", strlen("Hello World !\n"), 0);
+       r = ext4_fclose(&f);
+
+       io_timings_clear();
+       start = get_ms();
+       r = ext4_fopen(&f, "/mp/test1", "wb");
+       if (r != EOK) {
+               printf("ext4_fopen ERROR = %d\n", r);
+               return false;
+       }
+
+       printf("ext4_write: %" PRIu32 " * %" PRIu32 " ...\n", rw_szie,
+              rw_count);
+       for (i = 0; i < rw_count; ++i) {
+
+               memset(rw_buff, i % 10 + '0', rw_szie);
+
+               r = ext4_fwrite(&f, rw_buff, rw_szie, &size);
+
+               if ((r != EOK) || (size != rw_szie))
+                       break;
+       }
+
+       if (i != rw_count) {
+               printf("  file_test: rw_count = %" PRIu32 "\n", i);
+               return false;
+       }
+
+       stop = get_ms();
+       diff = stop - start;
+       size_bytes = rw_szie * rw_count;
+       size_bytes = (size_bytes * 1000) / 1024;
+       kbps = (size_bytes) / (diff + 1);
+       printf("  write time: %d ms\n", (int)diff);
+       printf("  write speed: %" PRIu32 " KB/s\n", kbps);
+       printf_io_timings(diff);
+       r = ext4_fclose(&f);
+
+       io_timings_clear();
+       start = get_ms();
+       r = ext4_fopen(&f, "/mp/test1", "r+");
+       if (r != EOK) {
+               printf("ext4_fopen ERROR = %d\n", r);
+               return false;
+       }
+
+       printf("ext4_read: %" PRIu32 " * %" PRIu32 " ...\n", rw_szie, rw_count);
+
+       for (i = 0; i < rw_count; ++i) {
+               r = ext4_fread(&f, rw_buff, rw_szie, &size);
+
+               if ((r != EOK) || (size != rw_szie))
+                       break;
+
+               if (verify_buf(rw_buff, rw_szie, i % 10 + '0'))
+                       break;
+       }
+
+       if (i != rw_count) {
+               printf("  file_test: rw_count = %" PRIu32 "\n", i);
+               return false;
+       }
+
+       stop = get_ms();
+       diff = stop - start;
+       size_bytes = rw_szie * rw_count;
+       size_bytes = (size_bytes * 1000) / 1024;
+       kbps = (size_bytes) / (diff + 1);
+       printf("  read time: %d ms\n", (int)diff);
+       printf("  read speed: %d KB/s\n", (int)kbps);
+       printf_io_timings(diff);
+
+       r = ext4_fclose(&f);
+       return true;
+}
+void test_lwext4_cleanup(void)
+{
+       clock_t start;
+       clock_t stop;
+       clock_t diff;
+
+       printf("\ncleanup:\n");
+       ext4_fremove("/mp/hello.txt");
+
+       printf("remove /mp/test1\n");
+       ext4_fremove("/mp/test1");
+
+       printf("remove /mp/dir1\n");
+       io_timings_clear();
+       start = get_ms();
+       ext4_dir_rm("/mp/dir1");
+       stop = get_ms();
+       diff = stop - start;
+       printf("cleanup: time: %d ms\n", (int)diff);
+       printf_io_timings(diff);
+}
+
+bool test_lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache)
+{
+       int r;
+
+       bc = bcache;
+       bd = bdev;
+
+       if (!bd) {
+               printf("test_lwext4_mount: no block device\n");
+               return false;
+       }
+
+       ext4_dmask_set(EXT4_DEBUG_ALL);
+
+       r = ext4_device_register(bd, bc ? bc : 0, "ext4_fs");
+       if (r != EOK) {
+               printf("ext4_device_register: rc = %d\n", r);
+               return false;
+       }
+
+       r = ext4_mount("ext4_fs", "/mp/");
+       if (r != EOK) {
+               printf("ext4_mount: rc = %d\n", r);
+               return false;
+       }
+
+       ext4_cache_write_back("/mp/", 1);
+       return true;
+}
+
+bool test_lwext4_umount(void)
+{
+       ext4_cache_write_back("/mp/", 0);
+       int r = ext4_umount("/mp/");
+       if (r != EOK) {
+               printf("ext4_umount: fail %d", r);
+               return false;
+       }
+       return true;
+}
diff --git a/blockdev/test_lwext4.h b/blockdev/test_lwext4.h
new file mode 100644 (file)
index 0000000..0ed04ac
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TEST_LWEXT4_H_
+#define TEST_LWEXT4_H_
+
+#include <stdint.h>
+#include <stdbool.h>
+
+void test_lwext4_dir_ls(const char *path);
+void test_lwext4_mp_stats(void);
+void test_lwext4_block_stats(void);
+bool test_lwext4_dir_test(int len);
+bool test_lwext4_file_test(uint32_t rw_szie, uint32_t rw_count);
+void test_lwext4_cleanup(void);
+
+bool test_lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache);
+bool test_lwext4_umount(void);
+
+void tim_wait_ms(uint32_t v);
+
+uint32_t tim_get_ms(void);
+uint64_t tim_get_us(void);
+
+struct ext4_io_stats {
+       float io_read;
+       float io_write;
+       float cpu;
+};
+
+void io_timings_clear(void);
+const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms);
+
+#endif /* TEST_LWEXT4_H_ */
diff --git a/blockdev/windows/io_raw.c b/blockdev/windows/io_raw.c
new file mode 100644 (file)
index 0000000..902cd4f
--- /dev/null
@@ -0,0 +1,161 @@
+/*\r
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * - Redistributions of source code must retain the above copyright\r
+ *   notice, this list of conditions and the following disclaimer.\r
+ * - Redistributions in binary form must reproduce the above copyright\r
+ *   notice, this list of conditions and the following disclaimer in the\r
+ *   documentation and/or other materials provided with the distribution.\r
+ * - The name of the author may not be used to endorse or promote products\r
+ *   derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#include <ext4_config.h>\r
+#include <ext4_blockdev.h>\r
+#include <ext4_errno.h>\r
+#include <stdio.h>\r
+#include <stdbool.h>\r
+#include <string.h>\r
+\r
+#ifdef WIN32\r
+#include <windows.h>\r
+#include <winioctl.h>\r
+\r
+/**@brief   Default filename.*/\r
+static const char *fname = "ext2";\r
+\r
+/**@brief   IO block size.*/\r
+#define EXT4_IORAW_BSIZE 512\r
+\r
+/**@brief   Image file descriptor.*/\r
+static HANDLE dev_file;\r
+\r
+/**********************BLOCKDEV INTERFACE**************************************/\r
+static int io_raw_open(struct ext4_blockdev *bdev);\r
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,\r
+                       uint32_t blk_cnt);\r
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,\r
+                        uint64_t blk_id, uint32_t blk_cnt);\r
+static int io_raw_close(struct ext4_blockdev *bdev);\r
+\r
+/******************************************************************************/\r
+EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,\r
+                             io_raw_bread, io_raw_bwrite, io_raw_close);\r
+\r
+/******************************************************************************/\r
+static int io_raw_open(struct ext4_blockdev *bdev)\r
+{\r
+       char path[64];\r
+       DISK_GEOMETRY pdg;\r
+       uint64_t disk_size;\r
+       BOOL bResult = FALSE;\r
+       DWORD junk;\r
+\r
+       sprintf(path, "\\\\.\\%s", fname);\r
+\r
+       dev_file =\r
+           CreateFile(path, GENERIC_READ | GENERIC_WRITE,\r
+                      FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,\r
+                      FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);\r
+\r
+       if (dev_file == INVALID_HANDLE_VALUE) {\r
+               return EIO;\r
+       }\r
+\r
+       bResult =\r
+           DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,\r
+                           &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);\r
+\r
+       if (bResult == FALSE) {\r
+               CloseHandle(dev_file);\r
+               return EIO;\r
+       }\r
+\r
+       disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *\r
+                   (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;\r
+\r
+       _filedev.ph_bsize = pdg.BytesPerSector;\r
+       _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;\r
+\r
+       return EOK;\r
+}\r
+\r
+/******************************************************************************/\r
+\r
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,\r
+                       uint32_t blk_cnt)\r
+{\r
+       long hipart = blk_id >> (32 - 9);\r
+       long lopart = blk_id << 9;\r
+       long err;\r
+\r
+       SetLastError(0);\r
+       lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);\r
+\r
+       if (lopart == -1 && NO_ERROR != (err = GetLastError())) {\r
+               return EIO;\r
+       }\r
+\r
+       DWORD n;\r
+\r
+       if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {\r
+               err = GetLastError();\r
+               return EIO;\r
+       }\r
+       return EOK;\r
+}\r
+\r
+/******************************************************************************/\r
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,\r
+                        uint64_t blk_id, uint32_t blk_cnt)\r
+{\r
+       long hipart = blk_id >> (32 - 9);\r
+       long lopart = blk_id << 9;\r
+       long err;\r
+\r
+       SetLastError(0);\r
+       lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);\r
+\r
+       if (lopart == -1 && NO_ERROR != (err = GetLastError())) {\r
+               return EIO;\r
+       }\r
+\r
+       DWORD n;\r
+\r
+       if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {\r
+               err = GetLastError();\r
+               return EIO;\r
+       }\r
+       return EOK;\r
+}\r
+\r
+/******************************************************************************/\r
+static int io_raw_close(struct ext4_blockdev *bdev)\r
+{\r
+       CloseHandle(dev_file);\r
+       return EOK;\r
+}\r
+\r
+/******************************************************************************/\r
+struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }\r
+/******************************************************************************/\r
+void ext4_io_raw_filename(const char *n) { fname = n; }\r
+\r
+/******************************************************************************/\r
+#endif\r
diff --git a/blockdev/windows/io_raw.h b/blockdev/windows/io_raw.h
new file mode 100644 (file)
index 0000000..275fe22
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * - Redistributions of source code must retain the above copyright\r
+ *   notice, this list of conditions and the following disclaimer.\r
+ * - Redistributions in binary form must reproduce the above copyright\r
+ *   notice, this list of conditions and the following disclaimer in the\r
+ *   documentation and/or other materials provided with the distribution.\r
+ * - The name of the author may not be used to endorse or promote products\r
+ *   derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#ifndef IO_RAW_H_\r
+#define IO_RAW_H_\r
+\r
+#include <ext4_config.h>\r
+#include <ext4_blockdev.h>\r
+\r
+#include <stdint.h>\r
+#include <stdbool.h>\r
+\r
+/**@brief   IO raw blockdev get.*/\r
+struct ext4_blockdev *ext4_io_raw_dev_get(void);\r
+\r
+/**@brief   Set filrname to open.*/\r
+void ext4_io_raw_filename(const char *n);\r
+\r
+\r
+#endif /* IO_RAW_H_ */\r
index 1e51edefcaa4334065f8dd1ce1bbe78d5b464bfa..9651e4d621d3de49972d62d5c5f73c4cb553cd0b 100644 (file)
@@ -1,4 +1,4 @@
-#Generic demo\r
-add_executable(generic main.c)\r
-target_link_libraries(generic lwext4)\r
-target_link_libraries(generic blockdev)
\ No newline at end of file
+#Generic demo
+add_executable(generic generic.c)
+target_link_libraries(generic blockdev)
+target_link_libraries(generic lwext4)
diff --git a/demos/generic/generic.c b/demos/generic/generic.c
new file mode 100644 (file)
index 0000000..8b50257
--- /dev/null
@@ -0,0 +1,269 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <ext4.h>
+#include "../../blockdev/linux/ext4_filedev.h"
+#include "../../blockdev/windows/io_raw.h"
+#include "../../blockdev/test_lwext4.h"
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+/**@brief   Input stream name.*/
+char input_name[128] = "ext2";
+
+/**@brief   Read-write size*/
+static int rw_szie = 1024 * 1024;
+
+/**@brief   Read-write size*/
+static int rw_count = 10;
+
+/**@brief   Directory test count*/
+static int dir_cnt = 0;
+
+/**@brief   Static or dynamic cache mode*/
+static bool cache_mode = true;
+
+/**@brief   Cleanup after test.*/
+static bool cleanup_flag = false;
+
+/**@brief   Block device stats.*/
+static bool bstat = false;
+
+/**@brief   Superblock stats.*/
+static bool sbstat = false;
+
+/**@brief   Indicates that input is windows partition.*/
+static bool winpart = false;
+
+/**@brief   File write buffer*/
+static uint8_t *wr_buff;
+
+/**@brief   File read buffer.*/
+static uint8_t *rd_buff;
+
+/**@brief   Block device handle.*/
+static struct ext4_blockdev *bd;
+
+/**@brief   Static cache instance*/
+EXT4_BCACHE_STATIC_INSTANCE(_lwext4_cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);
+
+/**@brief   Block cache handle.*/
+static struct ext4_bcache *bc = &_lwext4_cache;
+
+static const char *usage = "                                    \n\
+Welcome in ext4 generic demo.                                   \n\
+Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)  \n\
+Usage:                                                          \n\
+    --i   - input file              (default = ext2)            \n\
+    --rws - single R/W size         (default = 1024 * 1024)     \n\
+    --rwc - R/W count               (default = 10)              \n\
+    --cache  - 0 static, 1 dynamic  (default = 1)               \n\
+    --dirs   - directory test count (default = 0)               \n\
+    --clean  - clean up after test                              \n\
+    --bstat  - block device stats                               \n\
+    --sbstat - superblock stats                                 \n\
+    --wpart  - windows partition mode                           \n\
+\n";
+
+void io_timings_clear(void)
+{
+}
+
+const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms)
+{
+       static struct ext4_io_stats s;
+       return &s;
+}
+
+uint32_t tim_get_ms(void)
+{
+       struct timeval t;
+       gettimeofday(&t, NULL);
+       return (t.tv_sec * 1000) + (t.tv_usec / 1000);
+}
+
+uint64_t tim_get_us(void)
+{
+       struct timeval t;
+       gettimeofday(&t, NULL);
+       return (t.tv_sec * 1000000) + (t.tv_usec);
+}
+
+static bool open_linux(void)
+{
+       ext4_filedev_filename(input_name);
+       bd = ext4_filedev_get();
+       if (!bd) {
+               printf("open_filedev: fail\n");
+               return false;
+       }
+       return true;
+}
+
+static bool open_windows(void)
+{
+#ifdef WIN32
+       ext4_io_raw_filename(input_name);
+       bd = ext4_io_raw_dev_get();
+       if (!bd) {
+               printf("open_winpartition: fail\n");
+               return false;
+       }
+       return true;
+#else
+       printf("open_winpartition: this mode should be used only under windows "
+              "!\n");
+       return false;
+#endif
+}
+
+
+static bool parse_opt(int argc, char **argv)
+{
+       int option_index = 0;
+       int c;
+
+       static struct option long_options[] = {
+           {"in", required_argument, 0, 'a'},
+           {"rws", required_argument, 0, 'b'},
+           {"rwc", required_argument, 0, 'c'},
+           {"cache", required_argument, 0, 'd'},
+           {"dirs", required_argument, 0, 'e'},
+           {"clean", no_argument, 0, 'f'},
+           {"bstat", no_argument, 0, 'g'},
+           {"sbstat", no_argument, 0, 'h'},
+           {"wpart", no_argument, 0, 'i'},
+           {0, 0, 0, 0}};
+
+       while (-1 != (c = getopt_long(argc, argv, "a:b:c:d:e:fghi",
+                                     long_options, &option_index))) {
+
+               switch (c) {
+               case 'a':
+                       strcpy(input_name, optarg);
+                       break;
+               case 'b':
+                       rw_szie = atoi(optarg);
+                       break;
+               case 'c':
+                       rw_count = atoi(optarg);
+                       break;
+               case 'd':
+                       cache_mode = atoi(optarg);
+                       break;
+               case 'e':
+                       dir_cnt = atoi(optarg);
+                       break;
+               case 'f':
+                       cleanup_flag = true;
+                       break;
+               case 'g':
+                       bstat = true;
+                       break;
+               case 'h':
+                       sbstat = true;
+                       break;
+               case 'i':
+                       winpart = true;
+                       break;
+               default:
+                       printf("%s", usage);
+                       return false;
+               }
+       }
+       return true;
+}
+
+int main(int argc, char **argv)
+{
+       if (!parse_opt(argc, argv))
+               return EXIT_FAILURE;
+
+       printf("test conditions:\n");
+       printf("\timput name: %s\n", input_name);
+       printf("\trw size: %d\n", rw_szie);
+       printf("\trw count: %d\n", rw_count);
+       printf("\tcache mode: %s\n", cache_mode ? "dynamic" : "static");
+
+       if (winpart) {
+               if (!open_windows())
+                       return EXIT_FAILURE;
+       } else {
+               if (!open_linux())
+                       return EXIT_FAILURE;
+       }
+
+
+       if (!test_lwext4_mount(bd, bc))
+               return EXIT_FAILURE;
+
+       test_lwext4_cleanup();
+
+       if (sbstat)
+               test_lwext4_mp_stats();
+
+       test_lwext4_dir_ls("/mp/");
+       fflush(stdout);
+       if (!test_lwext4_dir_test(dir_cnt))
+               return EXIT_FAILURE;
+
+       fflush(stdout);
+       if (!test_lwext4_file_test(rw_count, rw_szie))
+               return EXIT_FAILURE;
+
+       fflush(stdout);
+       test_lwext4_dir_ls("/mp/");
+
+       if (sbstat)
+               test_lwext4_mp_stats();
+
+       if (cleanup_flag)
+               test_lwext4_cleanup();
+
+       if (bstat)
+               test_lwext4_block_stats();
+
+       if (!test_lwext4_umount())
+               return EXIT_FAILURE;
+
+       printf("\ntest finished\n");
+       return EXIT_SUCCESS;
+}
diff --git a/demos/generic/main.c b/demos/generic/main.c
deleted file mode 100644 (file)
index 079fb5b..0000000
+++ /dev/null
@@ -1,535 +0,0 @@
-/*\r
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * - Redistributions of source code must retain the above copyright\r
- *   notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- *   notice, this list of conditions and the following disclaimer in the\r
- *   documentation and/or other materials provided with the distribution.\r
- * - The name of the author may not be used to endorse or promote products\r
- *   derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <unistd.h>\r
-#include <getopt.h>\r
-#include <stdbool.h>\r
-#include <inttypes.h>\r
-#include <time.h>\r
-#include <unistd.h>\r
-#include <sys/time.h>\r
-\r
-#include <ext4_filedev.h>\r
-#include <io_raw.h>\r
-#include <ext4.h>\r
-\r
-#ifdef WIN32\r
-#include <windows.h>\r
-#endif\r
-\r
-/**@brief   Input stream name.*/\r
-char input_name[128] = "ext2";\r
-\r
-/**@brief   Read-write size*/\r
-static int rw_szie = 1024 * 1024;\r
-\r
-/**@brief   Read-write size*/\r
-static int rw_count = 10;\r
-\r
-/**@brief   Directory test count*/\r
-static int dir_cnt = 0;\r
-\r
-/**@brief   Static or dynamic cache mode*/\r
-static bool cache_mode = true;\r
-\r
-/**@brief   Cleanup after test.*/\r
-static bool cleanup_flag = false;\r
-\r
-/**@brief   Block device stats.*/\r
-static bool bstat = false;\r
-\r
-/**@brief   Superblock stats.*/\r
-static bool sbstat = false;\r
-\r
-/**@brief   Indicates that input is windows partition.*/\r
-static bool winpart = false;\r
-\r
-/**@brief   File write buffer*/\r
-static uint8_t *wr_buff;\r
-\r
-/**@brief   File read buffer.*/\r
-static uint8_t *rd_buff;\r
-\r
-/**@brief   Block device handle.*/\r
-static struct ext4_blockdev *bd;\r
-\r
-/**@brief   Static cache instance*/\r
-EXT4_BCACHE_STATIC_INSTANCE(_lwext4_cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);\r
-\r
-/**@brief   Block cache handle.*/\r
-static struct ext4_bcache *bc = &_lwext4_cache;\r
-\r
-static const char *usage = "                                    \n\\r
-Welcome in ext4 generic demo.                                   \n\\r
-Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)  \n\\r
-Usage:                                                          \n\\r
-    --i   - input file              (default = ext2)            \n\\r
-    --rws - single R/W size         (default = 1024 * 1024)     \n\\r
-    --rwc - R/W count               (default = 10)              \n\\r
-    --cache  - 0 static, 1 dynamic  (default = 1)               \n\\r
-    --dirs   - directory test count (default = 0)               \n\\r
-    --clean  - clean up after test                              \n\\r
-    --bstat  - block device stats                               \n\\r
-    --sbstat - superblock stats                                 \n\\r
-    --wpart  - windows partition mode                           \n\\r
-\n";\r
-\r
-static char *entry_to_str(uint8_t type)\r
-{\r
-       switch (type) {\r
-       case EXT4_DIRENTRY_UNKNOWN:\r
-               return "[UNK] ";\r
-       case EXT4_DIRENTRY_REG_FILE:\r
-               return "[FIL] ";\r
-       case EXT4_DIRENTRY_DIR:\r
-               return "[DIR] ";\r
-       case EXT4_DIRENTRY_CHRDEV:\r
-               return "[CHA] ";\r
-       case EXT4_DIRENTRY_BLKDEV:\r
-               return "[BLK] ";\r
-       case EXT4_DIRENTRY_FIFO:\r
-               return "[FIF] ";\r
-       case EXT4_DIRENTRY_SOCK:\r
-               return "[SOC] ";\r
-       case EXT4_DIRENTRY_SYMLINK:\r
-               return "[SYM] ";\r
-       default:\r
-               break;\r
-       }\r
-       return "[???]";\r
-}\r
-\r
-static void dir_ls(const char *path)\r
-{\r
-       char sss[255];\r
-       ext4_dir d;\r
-       const ext4_direntry *de;\r
-\r
-       printf("ls %s:\n", path);\r
-\r
-       ext4_dir_open(&d, path);\r
-       de = ext4_dir_entry_next(&d);\r
-\r
-       while (de) {\r
-               memcpy(sss, de->name, de->name_length);\r
-               sss[de->name_length] = 0;\r
-               printf("\t%s", entry_to_str(de->inode_type));\r
-               printf("%s", sss);\r
-               printf("\n");\r
-               de = ext4_dir_entry_next(&d);\r
-       }\r
-       ext4_dir_close(&d);\r
-}\r
-\r
-static void mp_stats(void)\r
-{\r
-       struct ext4_mount_stats stats;\r
-       ext4_mount_point_stats("/mp/", &stats);\r
-\r
-       printf("ext4_mount_point_stats:\n");\r
-       printf("\tinodes_count        = %" PRIu32 "\n", stats.inodes_count);\r
-       printf("\tfree_inodes_count   = %" PRIu32 "\n",\r
-              stats.free_inodes_count);\r
-       printf("\tblocks_count        = %" PRIu32 "\n",\r
-              (uint32_t)stats.blocks_count);\r
-       printf("\tfree_blocks_count   = %" PRIu32 "\n",\r
-              (uint32_t)stats.free_blocks_count);\r
-       printf("\tblock_size          = %" PRIu32 "\n", stats.block_size);\r
-       printf("\tblock_group_count   = %" PRIu32 "\n",\r
-              stats.block_group_count);\r
-       printf("\tblocks_per_group    = %" PRIu32 "\n", stats.blocks_per_group);\r
-       printf("\tinodes_per_group    = %" PRIu32 "\n", stats.inodes_per_group);\r
-       printf("\tvolume_name         = %s\n", stats.volume_name);\r
-}\r
-\r
-static void block_stats(void)\r
-{\r
-       uint32_t i;\r
-\r
-       printf("ext4 blockdev stats\n");\r
-       printf("\tbdev->bread_ctr          = %" PRIu32 "\n", bd->bread_ctr);\r
-       printf("\tbdev->bwrite_ctr         = %" PRIu32 "\n", bd->bwrite_ctr);\r
-\r
-       printf("\tbcache->ref_blocks       = %" PRIu32 "\n", bc->ref_blocks);\r
-       printf("\tbcache->max_ref_blocks   = %" PRIu32 "\n",\r
-              bc->max_ref_blocks);\r
-       printf("\tbcache->lru_ctr          = %" PRIu32 "\n", bc->lru_ctr);\r
-\r
-       printf("\n");\r
-       for (i = 0; i < bc->cnt; ++i) {\r
-               printf("\tbcache->refctr[%" PRIu32 "]     = %" PRIu32 "\n", i,\r
-                      bc->refctr[i]);\r
-       }\r
-\r
-       printf("\n");\r
-       for (i = 0; i < bc->cnt; ++i) {\r
-               printf("\tbcache->lru_id[%" PRIu32 "]     = %" PRIu32 "\n", i,\r
-                      bc->lru_id[i]);\r
-       }\r
-\r
-       printf("\n");\r
-       for (i = 0; i < bc->cnt; ++i) {\r
-               printf("\tbcache->free_delay[%" PRIu32 "] = %d\n", i,\r
-                      bc->free_delay[i]);\r
-       }\r
-\r
-       printf("\n");\r
-       for (i = 0; i < bc->cnt; ++i) {\r
-               printf("\tbcache->lba[%" PRIu32 "]        = %" PRIu32 "\n", i,\r
-                      (uint32_t)bc->lba[i]);\r
-       }\r
-}\r
-\r
-static clock_t get_ms(void)\r
-{\r
-       struct timeval t;\r
-       gettimeofday(&t, NULL);\r
-       return (t.tv_sec * 1000) + (t.tv_usec / 1000);\r
-}\r
-\r
-static bool dir_test(int len)\r
-{\r
-       ext4_file f;\r
-       int r;\r
-       int i;\r
-       char path[64];\r
-       clock_t diff;\r
-       clock_t stop;\r
-       clock_t start;\r
-\r
-       printf("\ndir_test: %d\n", len);\r
-       printf("directory create: /mp/dir1\n");\r
-       start = get_ms();\r
-       r = ext4_dir_mk("/mp/dir1");\r
-       if (r != EOK) {\r
-               printf("\text4_dir_mk: rc = %d\n", r);\r
-               return false;\r
-       }\r
-\r
-       ext4_cache_write_back("/mp/", 1);\r
-       printf("add files to: /mp/dir1\n");\r
-       for (i = 0; i < len; ++i) {\r
-               sprintf(path, "/mp/dir1/f%d", i);\r
-               r = ext4_fopen(&f, path, "wb");\r
-               if (r != EOK) {\r
-                       printf("\text4_fopen: rc = %d\n", r);\r
-                       return false;\r
-               }\r
-       }\r
-       ext4_cache_write_back("/mp/", 0);\r
-\r
-       stop = get_ms();\r
-       diff = stop - start;\r
-       dir_ls("/mp/dir1");\r
-       printf("dir_test: time: %d ms\n", (int)diff);\r
-       return true;\r
-}\r
-\r
-static bool file_test(void)\r
-{\r
-       int r;\r
-       size_t size;\r
-       ext4_file f;\r
-       int i;\r
-       clock_t start;\r
-       clock_t stop;\r
-       clock_t diff;\r
-       uint32_t kbps;\r
-       uint64_t size_bytes;\r
-\r
-       printf("\nfile_test:\n");\r
-       /*Add hello world file.*/\r
-       r = ext4_fopen(&f, "/mp/hello.txt", "wb");\r
-       r = ext4_fwrite(&f, "Hello World !\n", strlen("Hello World !\n"), 0);\r
-       r = ext4_fclose(&f);\r
-\r
-       printf("ext4_fopen: write test\n");\r
-       start = get_ms();\r
-       r = ext4_fopen(&f, "/mp/test1", "wb");\r
-       if (r != EOK) {\r
-               printf("\text4_fopen rc = %d\n", r);\r
-               return false;\r
-       }\r
-\r
-       printf("ext4_write: %d * %d ...\n", rw_szie, rw_count);\r
-       for (i = 0; i < rw_count; ++i) {\r
-\r
-               memset(wr_buff, i % 10 + '0', rw_szie);\r
-\r
-               r = ext4_fwrite(&f, wr_buff, rw_szie, &size);\r
-\r
-               if ((r != EOK) || (size != rw_szie))\r
-                       break;\r
-       }\r
-\r
-       if (i != rw_count) {\r
-               printf("\tfile_test: rw_count = %d\n", i);\r
-               return false;\r
-       }\r
-\r
-       stop = get_ms();\r
-       diff = stop - start;\r
-       size_bytes = rw_szie * rw_count;\r
-       size_bytes = (size_bytes * 1000) / 1024;\r
-       kbps = (size_bytes) / (diff + 1);\r
-       printf("\twrite time: %d ms\n", (int)diff);\r
-       printf("\twrite speed: %" PRIu32 " KB/s\n", kbps);\r
-       r = ext4_fclose(&f);\r
-\r
-       printf("ext4_fopen: read test\n");\r
-       start = get_ms();\r
-       r = ext4_fopen(&f, "/mp/test1", "r+");\r
-       if (r != EOK) {\r
-               printf("\text4_fopen rc = %d\n", r);\r
-               return false;\r
-       }\r
-\r
-       printf("ext4_read: %d * %d ...\n", rw_szie, rw_count);\r
-       for (i = 0; i < rw_count; ++i) {\r
-               memset(wr_buff, i % 10 + '0', rw_szie);\r
-               r = ext4_fread(&f, rd_buff, rw_szie, &size);\r
-\r
-               if ((r != EOK) || (size != rw_szie))\r
-                       break;\r
-\r
-               if (memcmp(rd_buff, wr_buff, rw_szie)) {\r
-                       break;\r
-               }\r
-       }\r
-       if (i != rw_count) {\r
-               printf("\tfile_test: rw_count = %d\n", i);\r
-               return false;\r
-       }\r
-       stop = get_ms();\r
-       diff = stop - start;\r
-       size_bytes = rw_szie * rw_count;\r
-       size_bytes = (size_bytes * 1000) / 1024;\r
-       kbps = (size_bytes) / (diff + 1);\r
-       printf("\tread time: %d ms\n", (int)diff);\r
-       printf("\tread speed: %" PRIu32 " KB/s\n", kbps);\r
-       r = ext4_fclose(&f);\r
-\r
-       return true;\r
-}\r
-static void cleanup(void)\r
-{\r
-       clock_t start;\r
-       clock_t stop;\r
-       clock_t diff;\r
-\r
-       printf("\ncleanup:\n");\r
-       ext4_fremove("/mp/hello.txt");\r
-       printf("cleanup: remove /mp/test1\n");\r
-       ext4_fremove("/mp/test1");\r
-\r
-       printf("cleanup: remove /mp/dir1\n");\r
-       start = get_ms();\r
-       ext4_dir_rm("/mp/dir1");\r
-       stop = get_ms();\r
-       diff = stop - start;\r
-       printf("cleanup: time: %d ms\n", (int)diff);\r
-}\r
-\r
-static bool open_filedev(void)\r
-{\r
-       ext4_filedev_filename(input_name);\r
-       bd = ext4_filedev_get();\r
-       if (!bd) {\r
-               printf("open_filedev: fail\n");\r
-               return false;\r
-       }\r
-       return true;\r
-}\r
-\r
-static bool open_winpartition(void)\r
-{\r
-#ifdef WIN32\r
-       ext4_io_raw_filename(input_name);\r
-       bd = ext4_io_raw_dev_get();\r
-       if (!bd) {\r
-               printf("open_winpartition: fail\n");\r
-               return false;\r
-       }\r
-       return true;\r
-#else\r
-       printf("open_winpartition: this mode should be used only under windows "\r
-              "!\n");\r
-       return false;\r
-#endif\r
-}\r
-\r
-static bool mount(void)\r
-{\r
-       int r;\r
-       if (winpart) {\r
-               if (!open_winpartition())\r
-                       return false;\r
-       } else {\r
-               if (!open_filedev())\r
-                       return false;\r
-       }\r
-       wr_buff = malloc(rw_szie);\r
-       rd_buff = malloc(rw_szie);\r
-\r
-       if (!wr_buff || !rd_buff) {\r
-               printf("mount: allocation failed\n");\r
-               return false;\r
-       }\r
-\r
-       ext4_dmask_set(EXT4_DEBUG_ALL);\r
-\r
-       r = ext4_device_register(bd, cache_mode ? 0 : bc, "ext4_fs");\r
-       if (r != EOK) {\r
-               printf("ext4_device_register: rc = %d\n", r);\r
-               return false;\r
-       }\r
-\r
-       r = ext4_mount("ext4_fs", "/mp/");\r
-       if (r != EOK) {\r
-               printf("ext4_mount: rc = %d\n", r);\r
-               return false;\r
-       }\r
-\r
-       return true;\r
-}\r
-\r
-static bool umount(void)\r
-{\r
-       int r = ext4_umount("/mp/");\r
-       if (r != EOK) {\r
-               printf("ext4_umount: rc = %d", r);\r
-               return false;\r
-       }\r
-       return true;\r
-}\r
-\r
-static bool parse_opt(int argc, char **argv)\r
-{\r
-       int option_index = 0;\r
-       int c;\r
-\r
-       static struct option long_options[] = {\r
-           {"in", required_argument, 0, 'a'},\r
-           {"rws", required_argument, 0, 'b'},\r
-           {"rwc", required_argument, 0, 'c'},\r
-           {"cache", required_argument, 0, 'd'},\r
-           {"dirs", required_argument, 0, 'e'},\r
-           {"clean", no_argument, 0, 'f'},\r
-           {"bstat", no_argument, 0, 'g'},\r
-           {"sbstat", no_argument, 0, 'h'},\r
-           {"wpart", no_argument, 0, 'i'},\r
-           {0, 0, 0, 0}};\r
-\r
-       while (-1 != (c = getopt_long(argc, argv, "a:b:c:d:e:fghi",\r
-                                     long_options, &option_index))) {\r
-\r
-               switch (c) {\r
-               case 'a':\r
-                       strcpy(input_name, optarg);\r
-                       break;\r
-               case 'b':\r
-                       rw_szie = atoi(optarg);\r
-                       break;\r
-               case 'c':\r
-                       rw_count = atoi(optarg);\r
-                       break;\r
-               case 'd':\r
-                       cache_mode = atoi(optarg);\r
-                       break;\r
-               case 'e':\r
-                       dir_cnt = atoi(optarg);\r
-                       break;\r
-               case 'f':\r
-                       cleanup_flag = true;\r
-                       break;\r
-               case 'g':\r
-                       bstat = true;\r
-                       break;\r
-               case 'h':\r
-                       sbstat = true;\r
-                       break;\r
-               case 'i':\r
-                       winpart = true;\r
-                       break;\r
-               default:\r
-                       printf("%s", usage);\r
-                       return false;\r
-               }\r
-       }\r
-       return true;\r
-}\r
-\r
-int main(int argc, char **argv)\r
-{\r
-       if (!parse_opt(argc, argv))\r
-               return EXIT_FAILURE;\r
-\r
-       printf("test conditions:\n");\r
-       printf("\timput name: %s\n", input_name);\r
-       printf("\trw size: %d\n", rw_szie);\r
-       printf("\trw count: %d\n", rw_count);\r
-       printf("\tcache mode: %s\n", cache_mode ? "dynamic" : "static");\r
-\r
-       if (!mount())\r
-               return EXIT_FAILURE;\r
-\r
-       cleanup();\r
-\r
-       if (sbstat)\r
-               mp_stats();\r
-\r
-       dir_ls("/mp/");\r
-       fflush(stdout);\r
-       if (!dir_test(dir_cnt))\r
-               return EXIT_FAILURE;\r
-\r
-       fflush(stdout);\r
-       if (!file_test())\r
-               return EXIT_FAILURE;\r
-\r
-       fflush(stdout);\r
-       dir_ls("/mp/");\r
-\r
-       if (sbstat)\r
-               mp_stats();\r
-\r
-       if (cleanup_flag)\r
-               cleanup();\r
-\r
-       if (bstat)\r
-               block_stats();\r
-\r
-       if (!umount())\r
-               return EXIT_FAILURE;\r
-\r
-       printf("\ntest finished\n");\r
-       return EXIT_SUCCESS;\r
-}\r
index 2b8232b05ce1171e1dbbcd1f88052b1dcd4eacbf..da7d77602d1df9347f75807ae2f0ee24d4cab4da 100644 (file)
@@ -33,6 +33,7 @@ set_target_properties(stm32f429_demo PROPERTIES COMPILE_FLAGS "-Wno-format")
 set_target_properties(stm32f429_demo PROPERTIES COMPILE_DEFINITIONS "STM32F429_439xx")\r
 \r
 set_target_properties(stm32f429_demo PROPERTIES LINK_FLAGS "-T${CMAKE_SOURCE_DIR}/demos/stm32f429_disco/stm32f429.ld")\r
+target_link_libraries(stm32f429_demo blockdev)\r
 target_link_libraries(stm32f429_demo lwext4)\r
 \r
 add_custom_target(stm32f429_size ALL DEPENDS stm32f429_demo COMMAND ${SIZE} -B stm32f429_demo)\r
index c9ca86c77c79ad205d7cfad7e302c13252c7a026..935e94298690a21622b168623880c26af4adca00 100644 (file)
@@ -41,6 +41,8 @@
 \r
 #include <usb_msc_lwext4.h>\r
 #include <ext4.h>\r
+#include "../../blockdev/test_lwext4.h"\r
+\r
 \r
 /**@brief   Read-write size*/\r
 #define READ_WRITE_SZIZE 1024 * 16\r
@@ -72,415 +74,99 @@ static bool bstat = false;
 /**@brief   Superblock stats.*/\r
 static bool sbstat = false;\r
 \r
-/**@brief   File write buffer*/\r
-static uint8_t wr_buff[READ_WRITE_SZIZE];\r
-\r
-/**@brief   File read buffer.*/\r
-static uint8_t rd_buff[READ_WRITE_SZIZE];\r
-\r
 /**@brief   Block device handle.*/\r
 static struct ext4_blockdev *bd;\r
 \r
 /**@brief   Block cache handle.*/\r
 static struct ext4_bcache   *bc;\r
 \r
-static char* entry_to_str(uint8_t type)\r
-{\r
-    switch(type){\r
-    case EXT4_DIRENTRY_UNKNOWN:\r
-        return "[UNK] ";\r
-    case EXT4_DIRENTRY_REG_FILE:\r
-        return "[FIL] ";\r
-    case EXT4_DIRENTRY_DIR:\r
-        return "[DIR] ";\r
-    case EXT4_DIRENTRY_CHRDEV:\r
-        return "[CHA] ";\r
-    case EXT4_DIRENTRY_BLKDEV:\r
-        return "[BLK] ";\r
-    case EXT4_DIRENTRY_FIFO:\r
-        return "[FIF] ";\r
-    case EXT4_DIRENTRY_SOCK:\r
-        return "[SOC] ";\r
-    case EXT4_DIRENTRY_SYMLINK:\r
-        return "[SYM] ";\r
-    default:\r
-        break;\r
-    }\r
-    return "[???]";\r
-}\r
-\r
-static void dir_ls(const char *path)\r
-{\r
-    char sss[255];\r
-    ext4_dir d;\r
-    const ext4_direntry *de;\r
-\r
-    printf("ls %s\n", path);\r
-\r
-    ext4_dir_open(&d, path);\r
-    de = ext4_dir_entry_next(&d);\r
-\r
-    while(de){\r
-        memcpy(sss, de->name, de->name_length);\r
-        sss[de->name_length] = 0;\r
-        printf("  %s", entry_to_str(de->inode_type));\r
-        printf("%s", sss);\r
-        printf("\n");\r
-        de = ext4_dir_entry_next(&d);\r
-    }\r
-    ext4_dir_close(&d);\r
-}\r
-\r
-static void mp_stats(void)\r
-{\r
-    struct ext4_mount_stats stats;\r
-    ext4_mount_point_stats("/mp/", &stats);\r
-\r
-    printf("********************\n");\r
-    printf("ext4_mount_point_stats\n");\r
-    printf("inodes_count = %u\n", stats.inodes_count);\r
-    printf("free_inodes_count = %u\n", stats.free_inodes_count);\r
-    printf("blocks_count = %u\n", (uint32_t)stats.blocks_count);\r
-    printf("free_blocks_count = %u\n", (uint32_t)stats.free_blocks_count);\r
-    printf("block_size = %u\n", stats.block_size);\r
-    printf("block_group_count = %u\n", stats.block_group_count);\r
-    printf("blocks_per_group= %u\n", stats.blocks_per_group);\r
-    printf("inodes_per_group = %u\n", stats.inodes_per_group);\r
-    printf("volume_name = %s\n", stats.volume_name);\r
-\r
-    printf("********************\n");\r
-\r
-}\r
-\r
-static void block_stats(void)\r
-{\r
-    uint32_t i;\r
-\r
-    printf("********************\n");\r
-    printf("ext4 blockdev stats\n");\r
-    printf("bdev->bread_ctr = %u\n", bd->bread_ctr);\r
-    printf("bdev->bwrite_ctr = %u\n", bd->bwrite_ctr);\r
-\r
-\r
-    printf("bcache->ref_blocks = %u\n", bc->ref_blocks);\r
-    printf("bcache->max_ref_blocks = %u\n", bc->max_ref_blocks);\r
-    printf("bcache->lru_ctr = %u\n", bc->lru_ctr);\r
-\r
-    printf("\n");\r
-    for (i = 0; i < bc->cnt; ++i) {\r
-        printf("bcache->refctr[%d]= %u\n", i, bc->refctr[i]);\r
-    }\r
-\r
-    printf("\n");\r
-    for (i = 0; i < bc->cnt; ++i) {\r
-        printf("bcache->lru_id[%d] = %u\n", i, bc->lru_id[i]);\r
-    }\r
-\r
-    printf("\n");\r
-    for (i = 0; i < bc->cnt; ++i) {\r
-        printf("bcache->free_delay[%d] = %d\n", i, bc->free_delay[i]);\r
-    }\r
-\r
-    printf("\n");\r
-    for (i = 0; i < bc->cnt; ++i) {\r
-        printf("bcache->lba[%d] = %u\n", i, (uint32_t)bc->lba[i]);\r
-    }\r
-\r
-    printf("********************\n");\r
-}\r
-\r
-static clock_t get_ms(void)\r
-{\r
-    return tim_get_ms();\r
-}\r
-\r
-static void printf_io_timings(clock_t diff)\r
-{\r
-    const struct ext4_io_stats *stats = io_timings_get(diff);\r
-    printf("io_timings:\n");\r
-    printf("  io_read: %.3f%%\n", stats->io_read);\r
-    printf("  io_write: %.3f%%\n", stats->io_write);\r
-    printf("  io_cpu: %.3f%%\n", stats->cpu);\r
-}\r
-\r
-static bool dir_test(int len)\r
-{\r
-    ext4_file f;\r
-    int       r;\r
-    int       i;\r
-    char path[64];\r
-    clock_t diff;\r
-    clock_t stop;\r
-    clock_t start;\r
-\r
-    printf("dir_test: %d\n", len);\r
-    io_timings_clear();\r
-    start = get_ms();\r
-\r
-    printf("directory create: /mp/dir1\n");\r
-    r = ext4_dir_mk("/mp/dir1");\r
-    if(r != EOK){\r
-        printf("ext4_dir_mk: rc = %d\n", r);\r
-        return false;\r
-    }\r
-\r
-    printf("add files to: /mp/dir1\n");\r
-    for (i = 0; i < len; ++i) {\r
-        sprintf(path, "/mp/dir1/f%d", i);\r
-        r = ext4_fopen(&f, path, "wb");\r
-        if(r != EOK){\r
-            printf("ext4_fopen: rc = %d\n", r);\r
-            return false;\r
-        }\r
-    }\r
-\r
-    stop =  get_ms();\r
-    diff = stop - start;\r
-    dir_ls("/mp/dir1");\r
-    printf("dir_test: time: %d ms\n", (int)diff);\r
-    printf("dir_test: av: %d ms/entry\n", (int)diff / len);\r
-    printf_io_timings(diff);\r
-    return true;\r
-}\r
-\r
-\r
-static bool file_test(void)\r
-{\r
-    int r;\r
-    size_t  size;\r
-    ext4_file f;\r
-    int i;\r
-    clock_t start;\r
-    clock_t stop;\r
-    clock_t diff;\r
-    uint32_t kbps;\r
-    uint64_t size_bytes;\r
-\r
-    printf("file_test:\n");\r
-\r
-    /*Add hello world file.*/\r
-    r = ext4_fopen(&f, "/mp/hello.txt", "wb");\r
-    r = ext4_fwrite(&f, "Hello World !\n", strlen("Hello World !\n"), 0);\r
-    r = ext4_fclose(&f);\r
-\r
-\r
-    io_timings_clear();\r
-    start = get_ms();\r
-    r = ext4_fopen(&f, "/mp/test1", "wb");\r
-    if(r != EOK){\r
-        printf("ext4_fopen ERROR = %d\n", r);\r
-        return false;\r
-    }\r
-\r
-    printf("ext4_write: %d * %d ...\n" , rw_szie, rw_count);\r
-    for (i = 0; i < rw_count; ++i) {\r
-\r
-        memset(wr_buff, i % 10 + '0', rw_szie);\r
-\r
-        r = ext4_fwrite(&f, wr_buff, rw_szie, &size);\r
-\r
-        if((r != EOK) || (size != rw_szie))\r
-            break;\r
-    }\r
-\r
-    if(i != rw_count){\r
-        printf("  file_test: rw_count = %d\n", i);\r
-        return false;\r
-    }\r
-\r
-    stop = get_ms();\r
-    diff = stop - start;\r
-    size_bytes = rw_szie * rw_count;\r
-    size_bytes = (size_bytes * 1000) / 1024;\r
-    kbps = (size_bytes) / (diff + 1);\r
-    printf("  write time: %d ms\n", (int)diff);\r
-    printf("  write speed: %d KB/s\n", kbps);\r
-    printf_io_timings(diff);\r
-    r = ext4_fclose(&f);\r
-\r
-\r
-    io_timings_clear();\r
-    start = get_ms();\r
-    r = ext4_fopen(&f, "/mp/test1", "r+");\r
-    if(r != EOK){\r
-        printf("ext4_fopen ERROR = %d\n", r);\r
-        return false;\r
-    }\r
-\r
-    printf("ext4_read: %d * %d ...\n" , rw_szie, rw_count);\r
-\r
-    for (i = 0; i < rw_count; ++i) {\r
-        memset(wr_buff, i % 10 + '0', rw_szie);\r
-        r = ext4_fread(&f, rd_buff, rw_szie, &size);\r
-\r
-        if((r != EOK) || (size != rw_szie))\r
-            break;\r
-\r
-        if(memcmp(rd_buff, wr_buff, rw_szie))\r
-            break;\r
-    }\r
-\r
-    if(i != rw_count){\r
-        printf("  file_test: rw_count = %d\n", i);\r
-        return false;\r
-    }\r
-\r
-    stop = get_ms();\r
-    diff = stop - start;\r
-    size_bytes = rw_szie * rw_count;\r
-    size_bytes = (size_bytes * 1000) / 1024;\r
-    kbps = (size_bytes) / (diff + 1);\r
-    printf("  read time: %d ms\n", (int)diff);\r
-    printf("  read speed: %d KB/s\n", kbps);\r
-    printf_io_timings(diff);\r
-\r
-    r = ext4_fclose(&f);\r
-    return true;\r
-\r
-}\r
-static void cleanup(void)\r
-{\r
-    clock_t start;\r
-    clock_t stop;\r
-    clock_t diff;\r
-\r
-    printf("\ncleanup:\n");\r
-    ext4_fremove("/mp/hello.txt");\r
-\r
-    printf("remove /mp/test1\n");\r
-    ext4_fremove("/mp/test1");\r
-\r
-\r
-    printf("remove /mp/dir1\n");\r
-    io_timings_clear();\r
-    start = get_ms();\r
-    ext4_dir_rm("/mp/dir1");\r
-    stop = get_ms();\r
-    diff = stop - start;\r
-    printf("cleanup: time: %d ms\n", (int)diff);\r
-    printf_io_timings(diff);\r
-}\r
-\r
 static bool open_filedev(void)\r
 {\r
 \r
-    bd = ext4_usb_msc_get();\r
-    bc = ext4_usb_msc_cache_get();\r
-    if(!bd || !bc){\r
-        printf("open_filedev: fail\n");\r
-        return false;\r
-    }\r
-    return true;\r
-}\r
-\r
-static bool mount(void)\r
-{\r
-    int r;\r
-\r
-    if(!open_filedev())\r
-        return false;\r
-\r
-    ext4_dmask_set(EXT4_DEBUG_ALL);\r
-\r
-    r = ext4_device_register(bd, cache_mode ? 0 : bc, "ext4_fs");\r
-    if(r != EOK){\r
-        printf("ext4_device_register: rc = %d\n", r);\r
-        return false;\r
-    }\r
-\r
-    r = ext4_mount("ext4_fs", "/mp/");\r
-    if(r != EOK){\r
-        printf("ext4_mount: rc = %d\n", r);\r
-        return false;\r
-    }\r
-\r
-    return true;\r
+       bd = ext4_usb_msc_get();\r
+       bc = ext4_usb_msc_cache_get();\r
+       if(!bd || !bc){\r
+               printf("open_filedev: fail\n");\r
+               return false;\r
+       }\r
+       return true;\r
 }\r
 \r
-static bool umount(void)\r
-{\r
-    int r = ext4_umount("/mp/");\r
-    if(r != EOK){\r
-        printf("ext4_umount: fail %d", r);\r
-        return false;\r
-    }\r
-    return true;\r
-}\r
-\r
-\r
 int main(void)\r
 {\r
-    hw_init();\r
-\r
-    setbuf(stdout, 0);\r
-    printf("connect usb drive...\n");\r
+       hw_init();\r
 \r
-    while(!hw_usb_connected())\r
-        hw_usb_process();\r
-    printf("usb drive connected\n");\r
+       setbuf(stdout, 0);\r
+       printf("connect usb drive...\n");\r
 \r
-    while(!hw_usb_enum_done())\r
-        hw_usb_process();\r
-    printf("usb drive enum done\n");\r
+       while(!hw_usb_connected())\r
+               hw_usb_process();\r
+       printf("usb drive connected\n");\r
 \r
-    hw_led_red(1);\r
+       while(!hw_usb_enum_done())\r
+               hw_usb_process();\r
+       printf("usb drive enum done\n");\r
 \r
-    printf("test conditions:\n");\r
-    printf("  rw size: %d\n",  rw_szie);\r
-    printf("  rw count: %d\n", rw_count);\r
-    printf("  cache mode: %s\n", cache_mode ? "dynamic" : "static");\r
+       hw_led_red(1);\r
 \r
+       printf("test conditions:\n");\r
+       printf("  rw size: %d\n",  rw_szie);\r
+       printf("  rw count: %d\n", rw_count);\r
+       printf("  cache mode: %s\n", cache_mode ? "dynamic" : "static");\r
 \r
-    tim_wait_ms(TEST_DELAY_MS);\r
-    if(!mount())\r
-        return EXIT_FAILURE;\r
+       if (!open_filedev())\r
+               goto Finish;\r
 \r
-    tim_wait_ms(TEST_DELAY_MS);\r
+       tim_wait_ms(TEST_DELAY_MS);\r
+       if(!test_lwext4_mount(bd, bc))\r
+               return EXIT_FAILURE;\r
 \r
-    ext4_cache_write_back("/mp/", 1);\r
-    cleanup();\r
+       tim_wait_ms(TEST_DELAY_MS);\r
 \r
-    if(sbstat){\r
-        tim_wait_ms(TEST_DELAY_MS);\r
-        mp_stats();\r
-    }\r
+       ext4_cache_write_back("/mp/", 1);\r
+       test_lwext4_cleanup();\r
 \r
-    tim_wait_ms(TEST_DELAY_MS);\r
-    dir_ls("/mp/");\r
-    if(!dir_test(dir_cnt))\r
-        return EXIT_FAILURE;\r
+       if(sbstat){\r
+               tim_wait_ms(TEST_DELAY_MS);\r
+               test_lwext4_mp_stats();\r
+       }\r
 \r
-    tim_wait_ms(TEST_DELAY_MS);\r
-    if(!file_test())\r
-        return EXIT_FAILURE;\r
+       tim_wait_ms(TEST_DELAY_MS);\r
+       test_lwext4_dir_ls("/mp/");\r
+       if(!test_lwext4_dir_test(dir_cnt))\r
+               return EXIT_FAILURE;\r
 \r
-    if(sbstat){\r
-        tim_wait_ms(TEST_DELAY_MS);\r
-        mp_stats();\r
-    }\r
+       tim_wait_ms(TEST_DELAY_MS);\r
+       if(!test_lwext4_file_test(rw_szie, rw_count))\r
+               return EXIT_FAILURE;\r
 \r
-    if(cleanup_flag){\r
-        tim_wait_ms(TEST_DELAY_MS);\r
-        cleanup();\r
-    }\r
+       if(sbstat){\r
+               tim_wait_ms(TEST_DELAY_MS);\r
+               test_lwext4_mp_stats();\r
+       }\r
 \r
-    if(bstat){\r
-        tim_wait_ms(TEST_DELAY_MS);\r
-        block_stats();\r
-    }\r
+       if(cleanup_flag){\r
+               tim_wait_ms(TEST_DELAY_MS);\r
+               test_lwext4_cleanup();\r
+       }\r
 \r
-    ext4_cache_write_back("/mp/", 0);\r
-    if(!umount())\r
-        return EXIT_FAILURE;\r
+       if(bstat){\r
+               tim_wait_ms(TEST_DELAY_MS);\r
+               test_lwext4_block_stats();\r
+       }\r
 \r
-    printf("press RESET button to restart\n");\r
+       ext4_cache_write_back("/mp/", 0);\r
+       if(!test_lwext4_umount())\r
+               return EXIT_FAILURE;\r
 \r
-    while (1) {\r
-        tim_wait_ms(500);\r
-        hw_led_green(1);\r
-        tim_wait_ms(500);\r
-        hw_led_green(0);\r
+       printf("press RESET button to restart\n");\r
+       Finish:\r
+       while (1) {\r
+               tim_wait_ms(500);\r
+               hw_led_green(1);\r
+               tim_wait_ms(500);\r
+               hw_led_green(0);\r
 \r
-    }\r
+       }\r
 }\r
 \r
index f7ff2cd8131d62d1243136e3ea01655c058a64e2..b66a6b5eee40c2e41bc1e179fa6ee30635609932 100644 (file)
@@ -40,6 +40,7 @@
 #include <usbh_msc.h>\r
 \r
 #include <usb_msc_lwext4.h>\r
+#include "../../blockdev/test_lwext4.h"\r
 \r
 extern USBH_HandleTypeDef hUSB_Host;\r
 \r
index 66bec1c86bb124c64af4de734d20dd7d11e990b5..ad8a1b84af1e30b1e28080240e7722c0040e95eb 100644 (file)
@@ -40,18 +40,4 @@ struct ext4_bcache*   ext4_usb_msc_cache_get(void);
 /**@brief   USB MSC blockdev get.*/\r
 struct ext4_blockdev* ext4_usb_msc_get(void);\r
 \r
-\r
-\r
-struct ext4_io_stats {\r
-    float io_read;\r
-    float io_write;\r
-    float cpu;\r
-};\r
-\r
-void io_timings_clear(void);\r
-const struct ext4_io_stats * io_timings_get(uint32_t time_sum_ms);\r
-\r
-\r
-\r
-\r
 #endif /* USB_MSC_LWEXT4_H_ */\r