cmake_minimum_required(VERSION 2.8)\r
\r
\r
+include_directories(lwext4)\r
+include_directories(blockdev/filedev)\r
+include_directories(blockdev/filedev_win)\r
\r
-#LIBRARY\r
-include_directories(. lwext4)\r
-aux_source_directory(lwext4 LWEXT4_SRC)\r
-add_library(lwext4 ${LWEXT4_SRC})\r
+\r
+#Library build\r
+add_subdirectory(lwext4)\r
+#Detect all possible warnings for lwext4 target\r
+set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic")\r
\r
#Examples\r
-if(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m3)\r
- #Library size print\r
- add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)\r
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m3)\r
+ #cortex-m3 demos\r
+ #...\r
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m4)\r
- #Library size print\r
- add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)\r
- #Discoery disco demo\r
- include(demos/stm32f429_disco/stm32f429_demo.cmake)\r
+ #cortex-m4 demos\r
+ add_subdirectory(demos/stm32f429_disco)\r
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL bf518)\r
- #Library size print\r
- add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)\r
+ #bf518 demos\r
+ #...\r
else()\r
- #Warning setup\r
- set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic -std=gnu99")\r
- #Library size print\r
- add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND size -B liblwext4.a)\r
#Generic example target\r
- include(demos/generic/generic.cmake)\r
- include(fs_test/fs_test.cmake)\r
+ add_subdirectory(blockdev)\r
+ add_subdirectory(fs_test)\r
+ add_subdirectory(demos/generic)\r
endif()\r
\r
+\r
#DISTRIBUTION\r
set(CPACK_PACKAGE_VERSION_MAJOR "0")\r
set(CPACK_PACKAGE_VERSION_MINOR "4")\r
generic:\r
rm -R -f build_generic\r
mkdir build_generic\r
- cd build_generic && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) ..\r
+ cd build_generic && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/generic.cmake ..\r
\r
bf518:\r
rm -R -f build_bf518\r
--- /dev/null
+#Blockdev library\r
+aux_source_directory(filedev BLOCKDEV_SRC)\r
+aux_source_directory(filedev_win BLOCKDEV_SRC)\r
+add_library(blockdev ${BLOCKDEV_SRC})\r
+\r
--- /dev/null
+#Generic demo\r
+add_executable(fileimage_demo main.c)\r
+target_link_libraries(fileimage_demo lwext4)\r
+target_link_libraries(fileimage_demo blockdev)
\ No newline at end of file
+++ /dev/null
-include_directories(blockdev/filedev)\r
-include_directories(blockdev/filedev_win)\r
-\r
-aux_source_directory(blockdev/filedev GENERIC_SRC)\r
-aux_source_directory(blockdev/filedev_win GENERIC_SRC)\r
-aux_source_directory(demos/generic GENERIC_SRC)\r
-\r
-add_executable(fileimage_demo ${GENERIC_SRC})\r
-target_link_libraries(fileimage_demo lwext4)
\ No newline at end of file
#include <stdbool.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
--- /dev/null
+#Discoery disco demo\r
+enable_language(ASM)\r
+set (STM32F429_DEMO_ASM\r
+ startup.S\r
+)\r
+\r
+\r
+include_directories(.)\r
+include_directories(cmsis)\r
+include_directories(stm/lcd_utils)\r
+include_directories(stm/stm32f4_spl/inc)\r
+include_directories(stm/stm32f429)\r
+include_directories(stm/usb_dev/Core/inc)\r
+include_directories(stm/usb_host/Core/inc)\r
+include_directories(stm/usb_host/Class/MSC/inc)\r
+include_directories(stm/usb_otg/inc)\r
+include_directories(stm/usb_user)\r
+\r
+aux_source_directory(. STM32F429_DEMO)\r
+aux_source_directory(cmsis STM32F429_DEMO)\r
+aux_source_directory(stm/lcd_utils STM32F429_DEMO)\r
+aux_source_directory(stm/stm32f4_spl/src STM32F429_DEMO)\r
+aux_source_directory(stm/stm32f429 STM32F429_DEMO)\r
+aux_source_directory(stm/usb_host/Core/src STM32F429_DEMO)\r
+aux_source_directory(stm/usb_host/Class/MSC/src STM32F429_DEMO)\r
+aux_source_directory(stm/usb_otg/src STM32F429_DEMO)\r
+aux_source_directory(stm/usb_user STM32F429_DEMO)\r
+add_executable(stm324f29_demo ${STM32F429_DEMO} ${STM32F429_DEMO_ASM})\r
+\r
+set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")\r
+set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-format")\r
+set_target_properties(stm324f29_demo PROPERTIES COMPILE_DEFINITIONS "STM32F429_439xx")\r
+\r
+set_target_properties(stm324f29_demo PROPERTIES LINK_FLAGS "-T${CMAKE_SOURCE_DIR}/demos/stm32f429_disco/stm32f429.ld")\r
+target_link_libraries(stm324f29_demo lwext4)\r
+\r
+add_custom_target(stm32f429_size ALL DEPENDS stm324f29_demo COMMAND ${SIZE} -B stm324f29_demo)
\ No newline at end of file
+++ /dev/null
-#Discoery disco demo\r
-enable_language(ASM)\r
-set (STM32F429_DEMO_ASM\r
- demos/stm32f429_disco/startup.S\r
-)\r
-\r
-\r
-include_directories(demos/stm32f429_disco)\r
-include_directories(demos/stm32f429_disco/cmsis)\r
-include_directories(demos/stm32f429_disco/stm/lcd_utils)\r
-include_directories(demos/stm32f429_disco/stm/stm32f4_spl/inc)\r
-include_directories(demos/stm32f429_disco/stm/stm32f429)\r
-include_directories(demos/stm32f429_disco/stm/usb_dev/Core/inc)\r
-include_directories(demos/stm32f429_disco/stm/usb_host/Core/inc)\r
-include_directories(demos/stm32f429_disco/stm/usb_host/Class/MSC/inc)\r
-include_directories(demos/stm32f429_disco/stm/usb_otg/inc)\r
-include_directories(demos/stm32f429_disco/stm/usb_user)\r
-\r
-aux_source_directory(demos/stm32f429_disco STM32F429_DEMO)\r
-aux_source_directory(demos/stm32f429_disco/cmsis STM32F429_DEMO)\r
-aux_source_directory(demos/stm32f429_disco/stm/lcd_utils STM32F429_DEMO)\r
-aux_source_directory(demos/stm32f429_disco/stm/stm32f4_spl/src STM32F429_DEMO)\r
-aux_source_directory(demos/stm32f429_disco/stm/stm32f429 STM32F429_DEMO)\r
-aux_source_directory(demos/stm32f429_disco/stm/usb_host/Core/src STM32F429_DEMO)\r
-aux_source_directory(demos/stm32f429_disco/stm/usb_host/Class/MSC/src STM32F429_DEMO)\r
-aux_source_directory(demos/stm32f429_disco/stm/usb_otg/src STM32F429_DEMO)\r
-aux_source_directory(demos/stm32f429_disco/stm/usb_user STM32F429_DEMO)\r
-\r
-add_executable(stm324f29_demo ${STM32F429_DEMO} ${STM32F429_DEMO_ASM})\r
-\r
-set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")\r
-set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-format")\r
-set_target_properties(stm324f29_demo PROPERTIES COMPILE_DEFINITIONS "STM32F429_439xx")\r
-\r
-set_target_properties(stm324f29_demo PROPERTIES LINK_FLAGS "-T${CMAKE_SOURCE_DIR}/demos/stm32f429_disco/stm32f429.ld")\r
-target_link_libraries(stm324f29_demo lwext4)\r
-\r
-add_custom_target(stm32f429_size ALL DEPENDS stm324f29_demo COMMAND ${SIZE} -B stm324f29_demo)
\ No newline at end of file
+++ /dev/null
-/*\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
-/** @addtogroup lwext4\r
- * @{\r
- */\r
-/**\r
- * @file ext4.h\r
- * @brief Ext4 high level operations (files, directories, mount points...).\r
- * Client has to include only this file.\r
- */\r
-\r
-#ifndef EXT4_H_\r
-#define EXT4_H_\r
-\r
-#include <ext4_config.h>\r
-#include <ext4_blockdev.h>\r
-#include <stdint.h>\r
-\r
-/********************************FILE OPEN FLAGS*****************************/\r
-\r
-#ifndef O_RDONLY\r
-#define O_RDONLY 00\r
-#endif\r
-\r
-#ifndef O_WRONLY\r
-#define O_WRONLY 01\r
-#endif\r
-\r
-#ifndef O_RDWR\r
-#define O_RDWR 02\r
-#endif\r
-\r
-#ifndef O_CREAT\r
-#define O_CREAT 0100\r
-#endif\r
-\r
-#ifndef O_EXCL\r
-#define O_EXCL 0200\r
-#endif\r
-\r
-#ifndef O_TRUNC\r
-#define O_TRUNC 01000\r
-#endif\r
-\r
-#ifndef O_APPEND\r
-#define O_APPEND 02000\r
-#endif\r
-\r
-/********************************FILE SEEK FLAGS*****************************/\r
-\r
-#ifndef SEEK_SET\r
-#define SEEK_SET 0\r
-#endif\r
-\r
-#ifndef SEEK_CUR\r
-#define SEEK_CUR 1\r
-#endif\r
-\r
-#ifndef SEEK_END\r
-#define SEEK_END 2\r
-#endif\r
-\r
-/********************************OS LOCK INFERFACE***************************/\r
-\r
-/**@brief OS dependent lock interface.*/\r
-struct ext4_lock {\r
-\r
- /**@brief Lock access to mount point*/\r
- void (*lock)(void);\r
-\r
- /**@brief Unlock access to mount point*/\r
- void (*unlock)(void);\r
-};\r
-\r
-\r
-/********************************FILE DESCRIPTOR*****************************/\r
-\r
-/**@brief File descriptor*/\r
-typedef struct ext4_file {\r
-\r
- /**@brief Mount point handle.*/\r
- struct ext4_mountpoint *mp;\r
-\r
- /**@brief File inode id*/\r
- uint32_t inode;\r
-\r
- /**@brief Open flags.*/\r
- uint32_t flags;\r
-\r
- /**@brief File size.*/\r
- uint64_t fsize;\r
-\r
- /**@brief File position*/\r
- uint64_t fpos;\r
-}ext4_file;\r
-\r
-/*****************************DIRECTORY DESCRIPTOR***************************/\r
-/**@brief Directory entry types. Copy from ext4_types.h*/\r
-enum {\r
- EXT4_DIRENTRY_UNKNOWN = 0,\r
- EXT4_DIRENTRY_REG_FILE,\r
- EXT4_DIRENTRY_DIR,\r
- EXT4_DIRENTRY_CHRDEV,\r
- EXT4_DIRENTRY_BLKDEV,\r
- EXT4_DIRENTRY_FIFO,\r
- EXT4_DIRENTRY_SOCK,\r
- EXT4_DIRENTRY_SYMLINK\r
-};\r
-\r
-/**@brief Directory entry descriptor. Copy from ext4_types.h*/\r
-typedef struct {\r
- uint32_t inode;\r
- uint16_t entry_length;\r
- uint8_t name_length;\r
- uint8_t inode_type;\r
- uint8_t name[255];\r
-}ext4_direntry;\r
-\r
-typedef struct {\r
- /**@brief File descriptor*/\r
- ext4_file f;\r
- /**@brief Current directory entry.*/\r
- ext4_direntry de;\r
-}ext4_dir;\r
-\r
-/********************************MOUNT OPERATIONS****************************/\r
-\r
-/**@brief Register a block device to a name.\r
- * @warning Block device has to be filled by\r
- * @ref EXT4_BLOCKDEV_STATIC_INSTANCE. Block cache may be created\r
- * @ref EXT4_BCACHE_STATIC_INSTANCE.\r
- * Block cache may by created automatically when bc parameter is 0.\r
- * @param bd block device\r
- * @param bd block device cache (0 = automatic cache mode)\r
- * @param dev_name register name\r
- * @param standard error code*/\r
-int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc,\r
- const char *dev_name);\r
-\r
-/**@brief Mount a block device with EXT4 partition to the mount point.\r
- * @param dev_name block device name (@ref ext4_device_register)\r
- * @param mount_point mount point, for example\r
- * - /\r
- * - /my_partition/\r
- * - /my_second_partition/\r
- *\r
- * @return standard error code */\r
-int ext4_mount(const char * dev_name, char *mount_point);\r
-\r
-/**@brief Umount operation.\r
- * @param mount_point mount name\r
- * @return standard error code */\r
-int ext4_umount(char *mount_point);\r
-\r
-\r
-/**@brief Some of the filesystem stats.*/\r
-struct ext4_mount_stats {\r
- uint32_t inodes_count;\r
- uint32_t free_inodes_count;\r
- uint64_t blocks_count;\r
- uint64_t free_blocks_count;\r
-\r
- uint32_t block_size;\r
- uint32_t block_group_count;\r
- uint32_t blocks_per_group;\r
- uint32_t inodes_per_group;\r
-\r
- char volume_name[16];\r
-};\r
-\r
-/**@brief Get file system params.\r
- * @param mount_point mount path\r
- * @param stats ext fs stats\r
- * @return standard error code */\r
-int ext4_mount_point_stats(const char *mount_point,\r
- struct ext4_mount_stats *stats);\r
-\r
-\r
-/**@brief Enable/disable write back cache mode.\r
- * @warning Default model of cache is write trough. It means that when You do:\r
- *\r
- * ext4_fopen(...);\r
- * ext4_fwrie(...);\r
- * < --- data is flushed to physical drive\r
- *\r
- * When you do:\r
- * ext4_cache_write_back(..., 1);\r
- * ext4_fopen(...);\r
- * ext4_fwrie(...);\r
- * < --- data is NOT flushed to physical drive\r
- * ext4_cache_write_back(..., 0);\r
- * < --- when write back mode is disabled all\r
- * cache data will be flushed\r
- * To enable write back mode permanently just call this function\r
- * once after ext4_mount (and disable before ext4_umount).\r
- *\r
- * Some of the function use write back cache mode internally.\r
- * If you enable write back mode twice you have to disable it twice\r
- * to flush all data:\r
- *\r
- * ext4_cache_write_back(..., 1);\r
- * ext4_cache_write_back(..., 1);\r
- *\r
- * ext4_cache_write_back(..., 0);\r
- * ext4_cache_write_back(..., 0);\r
- *\r
- * Write back mode is useful when you want to create a lot of empty\r
- * files/directories.\r
- *\r
- * @param path mount point path\r
- * @param on enable/disable\r
- *\r
- * @return standard error code */\r
-int ext4_cache_write_back(const char *path, bool on);\r
-\r
-/********************************FILE OPERATIONS*****************************/\r
-\r
-/**@brief Remove file by path.\r
- * @param path path to file\r
- * @return standard error code */\r
-int ext4_fremove(const char *path);\r
-\r
-/**@brief File open function.\r
- * @param filename, (has to start from mount point)\r
- * /my_partition/my_file\r
- * @param flags open file flags\r
- * |---------------------------------------------------------------|\r
- * | r or rb O_RDONLY |\r
- * |---------------------------------------------------------------|\r
- * | w or wb O_WRONLY|O_CREAT|O_TRUNC |\r
- * |---------------------------------------------------------------|\r
- * | a or ab O_WRONLY|O_CREAT|O_APPEND |\r
- * |---------------------------------------------------------------|\r
- * | r+ or rb+ or r+b O_RDWR |\r
- * |---------------------------------------------------------------|\r
- * | w+ or wb+ or w+b O_RDWR|O_CREAT|O_TRUNC |\r
- * |---------------------------------------------------------------|\r
- * | a+ or ab+ or a+b O_RDWR|O_CREAT|O_APPEND |\r
- * |---------------------------------------------------------------|\r
- *\r
- * @return standard error code*/\r
-int ext4_fopen (ext4_file *f, const char *path, const char *flags);\r
-\r
-/**@brief File close function.\r
- * @param f file handle\r
- * @return standard error code*/\r
-int ext4_fclose(ext4_file *f);\r
-\r
-/**@brief Read data from file.\r
- * @param f file handle\r
- * @param buf output buffer\r
- * @param size bytes to read\r
- * @param rcnt bytes read (may be NULL)\r
- * @return standard error code*/\r
-int ext4_fread (ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt);\r
-\r
-/**@brief Write data to file.\r
- * @param f file handle\r
- * @param buf data to write\r
- * @param size write length\r
- * @param wcnt bytes written (may be NULL)\r
- * @return standard error code*/\r
-int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt);\r
-\r
-/**@brief File seek operation.\r
- * @param f file handle\r
- * @param offset offset to seek\r
- * @param origin seek type:\r
- * @ref SEEK_SET\r
- * @ref SEEK_CUR\r
- * @ref SEEK_END\r
- * @return standard error code*/\r
-int ext4_fseek (ext4_file *f, uint64_t offset, uint32_t origin);\r
-\r
-/**@brief Get file position.\r
- * @param f file handle\r
- * @return actual file position */\r
-uint64_t ext4_ftell (ext4_file *f);\r
-\r
-/**@brief Get file size.\r
- * @param f file handle\r
- * @return file size */\r
-uint64_t ext4_fsize (ext4_file *f);\r
-\r
-/*********************************DIRECTORY OPERATION***********************/\r
-\r
-/**@brief Recursive directory remove.\r
- * @param path directory path to remove\r
- * @return standard error code*/\r
-int ext4_dir_rm(const char *path);\r
-\r
-/**@brief Create new directory.\r
- * @param name new directory name\r
- * @return standard error code*/\r
-int ext4_dir_mk(const char *path);\r
-\r
-/**@brief Directory open.\r
- * @param d directory handle\r
- * @param path directory path\r
- * @return standard error code*/\r
-int ext4_dir_open (ext4_dir *d, const char *path);\r
-\r
-/**@brief Directory close.\r
- * @param d directory handle\r
- * @return standard error code*/\r
-int ext4_dir_close(ext4_dir *d);\r
-\r
-\r
-/**@brief Return directory entry by id.\r
- * @param d directory handle\r
- * @param id entry id\r
- * @return directory entry id (NULL id no entry)*/\r
-ext4_direntry* ext4_dir_entry_get(ext4_dir *d, uint32_t id);\r
-\r
-#endif /* EXT4_H_ */\r
-\r
-/**\r
- * @}\r
- */\r
\r
ifeq ($(OS),Windows_NT)\r
-LWEXT4_CLIENT = @build_generic\\lwext4_client\r
-LWEXT4_SERVER = @build_generic\\lwext4_server\r
+LWEXT4_CLIENT = @build_generic\\fs_test\\lwext4_client\r
+LWEXT4_SERVER = @build_generic\\fs_test\\lwext4_server\r
else\r
-LWEXT4_CLIENT = @build_generic/lwext4_client\r
-LWEXT4_SERVER = @build_generic/lwext4_server\r
+LWEXT4_CLIENT = @build_generic/fs_test/lwext4_client\r
+LWEXT4_SERVER = @build_generic/fs_test/lwext4_server\r
endif\r
\r
TEST_DIR = /test\r
server_ext4:\r
$(LWEXT4_SERVER) -i ext_images/ext4\r
\r
-all_tests: t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20
\ No newline at end of file
+tests: t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20
\ No newline at end of file
--- /dev/null
+#fs_test executables\r
+add_executable(lwext4_server lwext4_server.c)\r
+target_link_libraries(lwext4_server lwext4)\r
+target_link_libraries(lwext4_server blockdev)\r
+if(WIN32)\r
+target_link_libraries(lwext4_server ws2_32)\r
+endif(WIN32)\r
+add_executable(lwext4_client lwext4_client.c)\r
+target_link_libraries(lwext4_client lwext4)\r
+if(WIN32)\r
+target_link_libraries(lwext4_client ws2_32)\r
+endif(WIN32)\r
+++ /dev/null
-include_directories(blockdev/filedev)\r
-include_directories(blockdev/filedev_win)\r
-\r
-aux_source_directory(blockdev/filedev BLOCKDEV_SRC)\r
-aux_source_directory(blockdev/filedev_win BLOCKDEV_SRC)\r
-\r
-\r
-add_executable(lwext4_server fs_test/lwext4_server.c ${BLOCKDEV_SRC})\r
-target_link_libraries(lwext4_server lwext4)\r
-if(WIN32)\r
-target_link_libraries(lwext4_server ws2_32)\r
-endif(WIN32)\r
-add_executable(lwext4_client fs_test/lwext4_client.c ${BLOCKDEV_SRC})\r
-target_link_libraries(lwext4_client lwext4)\r
-if(WIN32)\r
-target_link_libraries(lwext4_client ws2_32)\r
-endif(WIN32)
\ No newline at end of file
#include <stdbool.h>\r
#include <getopt.h>\r
#include <time.h>\r
+#include <sys/time.h>\r
\r
#ifdef WIN32\r
#include <winsock2.h>\r
--- /dev/null
+\r
+#LIBRARY\r
+include_directories(.)\r
+aux_source_directory(. LWEXT4_SRC)\r
+add_library(lwext4 ${LWEXT4_SRC})\r
+add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)\r
+\r
+\r
--- /dev/null
+/*\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
+/** @addtogroup lwext4\r
+ * @{\r
+ */\r
+/**\r
+ * @file ext4.h\r
+ * @brief Ext4 high level operations (files, directories, mount points...).\r
+ * Client has to include only this file.\r
+ */\r
+\r
+#ifndef EXT4_H_\r
+#define EXT4_H_\r
+\r
+#include <ext4_config.h>\r
+#include <ext4_blockdev.h>\r
+#include <stdint.h>\r
+\r
+/********************************FILE OPEN FLAGS*****************************/\r
+\r
+#ifndef O_RDONLY\r
+#define O_RDONLY 00\r
+#endif\r
+\r
+#ifndef O_WRONLY\r
+#define O_WRONLY 01\r
+#endif\r
+\r
+#ifndef O_RDWR\r
+#define O_RDWR 02\r
+#endif\r
+\r
+#ifndef O_CREAT\r
+#define O_CREAT 0100\r
+#endif\r
+\r
+#ifndef O_EXCL\r
+#define O_EXCL 0200\r
+#endif\r
+\r
+#ifndef O_TRUNC\r
+#define O_TRUNC 01000\r
+#endif\r
+\r
+#ifndef O_APPEND\r
+#define O_APPEND 02000\r
+#endif\r
+\r
+/********************************FILE SEEK FLAGS*****************************/\r
+\r
+#ifndef SEEK_SET\r
+#define SEEK_SET 0\r
+#endif\r
+\r
+#ifndef SEEK_CUR\r
+#define SEEK_CUR 1\r
+#endif\r
+\r
+#ifndef SEEK_END\r
+#define SEEK_END 2\r
+#endif\r
+\r
+/********************************OS LOCK INFERFACE***************************/\r
+\r
+/**@brief OS dependent lock interface.*/\r
+struct ext4_lock {\r
+\r
+ /**@brief Lock access to mount point*/\r
+ void (*lock)(void);\r
+\r
+ /**@brief Unlock access to mount point*/\r
+ void (*unlock)(void);\r
+};\r
+\r
+\r
+/********************************FILE DESCRIPTOR*****************************/\r
+\r
+/**@brief File descriptor*/\r
+typedef struct ext4_file {\r
+\r
+ /**@brief Mount point handle.*/\r
+ struct ext4_mountpoint *mp;\r
+\r
+ /**@brief File inode id*/\r
+ uint32_t inode;\r
+\r
+ /**@brief Open flags.*/\r
+ uint32_t flags;\r
+\r
+ /**@brief File size.*/\r
+ uint64_t fsize;\r
+\r
+ /**@brief File position*/\r
+ uint64_t fpos;\r
+}ext4_file;\r
+\r
+/*****************************DIRECTORY DESCRIPTOR***************************/\r
+/**@brief Directory entry types. Copy from ext4_types.h*/\r
+enum {\r
+ EXT4_DIRENTRY_UNKNOWN = 0,\r
+ EXT4_DIRENTRY_REG_FILE,\r
+ EXT4_DIRENTRY_DIR,\r
+ EXT4_DIRENTRY_CHRDEV,\r
+ EXT4_DIRENTRY_BLKDEV,\r
+ EXT4_DIRENTRY_FIFO,\r
+ EXT4_DIRENTRY_SOCK,\r
+ EXT4_DIRENTRY_SYMLINK\r
+};\r
+\r
+/**@brief Directory entry descriptor. Copy from ext4_types.h*/\r
+typedef struct {\r
+ uint32_t inode;\r
+ uint16_t entry_length;\r
+ uint8_t name_length;\r
+ uint8_t inode_type;\r
+ uint8_t name[255];\r
+}ext4_direntry;\r
+\r
+typedef struct {\r
+ /**@brief File descriptor*/\r
+ ext4_file f;\r
+ /**@brief Current directory entry.*/\r
+ ext4_direntry de;\r
+}ext4_dir;\r
+\r
+/********************************MOUNT OPERATIONS****************************/\r
+\r
+/**@brief Register a block device to a name.\r
+ * @warning Block device has to be filled by\r
+ * @ref EXT4_BLOCKDEV_STATIC_INSTANCE. Block cache may be created\r
+ * @ref EXT4_BCACHE_STATIC_INSTANCE.\r
+ * Block cache may by created automatically when bc parameter is 0.\r
+ * @param bd block device\r
+ * @param bd block device cache (0 = automatic cache mode)\r
+ * @param dev_name register name\r
+ * @param standard error code*/\r
+int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc,\r
+ const char *dev_name);\r
+\r
+/**@brief Mount a block device with EXT4 partition to the mount point.\r
+ * @param dev_name block device name (@ref ext4_device_register)\r
+ * @param mount_point mount point, for example\r
+ * - /\r
+ * - /my_partition/\r
+ * - /my_second_partition/\r
+ *\r
+ * @return standard error code */\r
+int ext4_mount(const char * dev_name, char *mount_point);\r
+\r
+/**@brief Umount operation.\r
+ * @param mount_point mount name\r
+ * @return standard error code */\r
+int ext4_umount(char *mount_point);\r
+\r
+\r
+/**@brief Some of the filesystem stats.*/\r
+struct ext4_mount_stats {\r
+ uint32_t inodes_count;\r
+ uint32_t free_inodes_count;\r
+ uint64_t blocks_count;\r
+ uint64_t free_blocks_count;\r
+\r
+ uint32_t block_size;\r
+ uint32_t block_group_count;\r
+ uint32_t blocks_per_group;\r
+ uint32_t inodes_per_group;\r
+\r
+ char volume_name[16];\r
+};\r
+\r
+/**@brief Get file system params.\r
+ * @param mount_point mount path\r
+ * @param stats ext fs stats\r
+ * @return standard error code */\r
+int ext4_mount_point_stats(const char *mount_point,\r
+ struct ext4_mount_stats *stats);\r
+\r
+\r
+/**@brief Enable/disable write back cache mode.\r
+ * @warning Default model of cache is write trough. It means that when You do:\r
+ *\r
+ * ext4_fopen(...);\r
+ * ext4_fwrie(...);\r
+ * < --- data is flushed to physical drive\r
+ *\r
+ * When you do:\r
+ * ext4_cache_write_back(..., 1);\r
+ * ext4_fopen(...);\r
+ * ext4_fwrie(...);\r
+ * < --- data is NOT flushed to physical drive\r
+ * ext4_cache_write_back(..., 0);\r
+ * < --- when write back mode is disabled all\r
+ * cache data will be flushed\r
+ * To enable write back mode permanently just call this function\r
+ * once after ext4_mount (and disable before ext4_umount).\r
+ *\r
+ * Some of the function use write back cache mode internally.\r
+ * If you enable write back mode twice you have to disable it twice\r
+ * to flush all data:\r
+ *\r
+ * ext4_cache_write_back(..., 1);\r
+ * ext4_cache_write_back(..., 1);\r
+ *\r
+ * ext4_cache_write_back(..., 0);\r
+ * ext4_cache_write_back(..., 0);\r
+ *\r
+ * Write back mode is useful when you want to create a lot of empty\r
+ * files/directories.\r
+ *\r
+ * @param path mount point path\r
+ * @param on enable/disable\r
+ *\r
+ * @return standard error code */\r
+int ext4_cache_write_back(const char *path, bool on);\r
+\r
+/********************************FILE OPERATIONS*****************************/\r
+\r
+/**@brief Remove file by path.\r
+ * @param path path to file\r
+ * @return standard error code */\r
+int ext4_fremove(const char *path);\r
+\r
+/**@brief File open function.\r
+ * @param filename, (has to start from mount point)\r
+ * /my_partition/my_file\r
+ * @param flags open file flags\r
+ * |---------------------------------------------------------------|\r
+ * | r or rb O_RDONLY |\r
+ * |---------------------------------------------------------------|\r
+ * | w or wb O_WRONLY|O_CREAT|O_TRUNC |\r
+ * |---------------------------------------------------------------|\r
+ * | a or ab O_WRONLY|O_CREAT|O_APPEND |\r
+ * |---------------------------------------------------------------|\r
+ * | r+ or rb+ or r+b O_RDWR |\r
+ * |---------------------------------------------------------------|\r
+ * | w+ or wb+ or w+b O_RDWR|O_CREAT|O_TRUNC |\r
+ * |---------------------------------------------------------------|\r
+ * | a+ or ab+ or a+b O_RDWR|O_CREAT|O_APPEND |\r
+ * |---------------------------------------------------------------|\r
+ *\r
+ * @return standard error code*/\r
+int ext4_fopen (ext4_file *f, const char *path, const char *flags);\r
+\r
+/**@brief File close function.\r
+ * @param f file handle\r
+ * @return standard error code*/\r
+int ext4_fclose(ext4_file *f);\r
+\r
+/**@brief Read data from file.\r
+ * @param f file handle\r
+ * @param buf output buffer\r
+ * @param size bytes to read\r
+ * @param rcnt bytes read (may be NULL)\r
+ * @return standard error code*/\r
+int ext4_fread (ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt);\r
+\r
+/**@brief Write data to file.\r
+ * @param f file handle\r
+ * @param buf data to write\r
+ * @param size write length\r
+ * @param wcnt bytes written (may be NULL)\r
+ * @return standard error code*/\r
+int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt);\r
+\r
+/**@brief File seek operation.\r
+ * @param f file handle\r
+ * @param offset offset to seek\r
+ * @param origin seek type:\r
+ * @ref SEEK_SET\r
+ * @ref SEEK_CUR\r
+ * @ref SEEK_END\r
+ * @return standard error code*/\r
+int ext4_fseek (ext4_file *f, uint64_t offset, uint32_t origin);\r
+\r
+/**@brief Get file position.\r
+ * @param f file handle\r
+ * @return actual file position */\r
+uint64_t ext4_ftell (ext4_file *f);\r
+\r
+/**@brief Get file size.\r
+ * @param f file handle\r
+ * @return file size */\r
+uint64_t ext4_fsize (ext4_file *f);\r
+\r
+/*********************************DIRECTORY OPERATION***********************/\r
+\r
+/**@brief Recursive directory remove.\r
+ * @param path directory path to remove\r
+ * @return standard error code*/\r
+int ext4_dir_rm(const char *path);\r
+\r
+/**@brief Create new directory.\r
+ * @param name new directory name\r
+ * @return standard error code*/\r
+int ext4_dir_mk(const char *path);\r
+\r
+/**@brief Directory open.\r
+ * @param d directory handle\r
+ * @param path directory path\r
+ * @return standard error code*/\r
+int ext4_dir_open (ext4_dir *d, const char *path);\r
+\r
+/**@brief Directory close.\r
+ * @param d directory handle\r
+ * @return standard error code*/\r
+int ext4_dir_close(ext4_dir *d);\r
+\r
+\r
+/**@brief Return directory entry by id.\r
+ * @param d directory handle\r
+ * @param id entry id\r
+ * @return directory entry id (NULL id no entry)*/\r
+ext4_direntry* ext4_dir_entry_get(ext4_dir *d, uint32_t id);\r
+\r
+#endif /* EXT4_H_ */\r
+\r
+/**\r
+ * @}\r
+ */\r
# Name of the target\r
-SET(CMAKE_SYSTEM_NAME Generic)\r
+set(CMAKE_SYSTEM_NAME bfin-elf)\r
set(CMAKE_SYSTEM_PROCESSOR bf518)\r
\r
# Toolchain settings\r
set(SIZE bfin-elf-size)\r
\r
set(CMAKE_C_FLAGS "-mcpu=bf518 -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")\r
-set(CMAKE_CXX_FLAGS "-mcpu=bf518 -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")\r
+set(CMAKE_CXX_FLAGS "-mcpu=bf518 -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")\r
set(CMAKE_ASM_FLAGS "-mcpu=bf518 -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags")\r
-set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mcpu=bf592" CACHE INTERNAL "exe link flags")\r
+set(CMAKE_EXE_LINKER_FLAGS "-mcpu=bf592 -nostartfiles -Wl,--gc-sections" CACHE INTERNAL "exe link flags")\r
\r
\r
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags")\r
# Name of the target\r
-SET(CMAKE_SYSTEM_NAME Generic)\r
+set(CMAKE_SYSTEM_NAME arm-none-eabi)\r
set(CMAKE_SYSTEM_PROCESSOR cortex-m3)\r
\r
# Toolchain settings\r
set(CMAKE_C_FLAGS "-mthumb -mcpu=cortex-m3 -fno-builtin -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")\r
set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m3 -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")\r
set(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m3" CACHE INTERNAL "asm compiler flags")\r
-set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m3" CACHE INTERNAL "exe link flags")\r
+set(CMAKE_EXE_LINKER_FLAGS "-mthumb -mcpu=cortex-m3 -nostartfiles -Wl,--gc-sections" CACHE INTERNAL "exe link flags")\r
\r
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags")\r
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags")\r
# Name of the target\r
-SET(CMAKE_SYSTEM_NAME Generic)\r
+set(CMAKE_SYSTEM_NAME arm-none-eabi)\r
set(CMAKE_SYSTEM_PROCESSOR cortex-m4)\r
\r
# Toolchain settings\r
set(CMAKE_C_FLAGS "-mthumb -mcpu=cortex-m4 -fno-builtin -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")\r
set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m4 -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")\r
set(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m4" CACHE INTERNAL "asm compiler flags")\r
-set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m4" CACHE INTERNAL "exe link flags")\r
+set(CMAKE_EXE_LINKER_FLAGS " -mthumb -mcpu=cortex-m4 -nostartfiles -Wl,--gc-sections" CACHE INTERNAL "exe link flags")\r
\r
\r
\r
\r
SET(CMAKE_C_FLAGS_RELEASE "-Os" CACHE INTERNAL "c release compiler flags")\r
SET(CMAKE_CXX_FLAGS_RELEASE "-Os" CACHE INTERNAL "cxx release compiler flags")\r
-SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags")\r
-\r
+SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags")
\ No newline at end of file
--- /dev/null
+# Name of the target
+set(CMAKE_SYSTEM_PROCESSOR generic)
+
+# Toolchain settings
+set(CMAKE_C_COMPILER gcc)
+set(CMAKE_CXX_COMPILER g++)
+set(AS as)
+set(AR ar)
+set(OBJCOPY objcopy)
+set(OBJDUMP objdump)
+set(SIZE size)
+
+set(CMAKE_C_FLAGS "-std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")
+set(CMAKE_CXX_FLAGS "-fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
+set(CMAKE_ASM_FLAGS "" CACHE INTERNAL "asm compiler flags")
+set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections" CACHE INTERNAL "exe link flags")
+
+
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags")
+SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags")
+
+SET(CMAKE_C_FLAGS_RELEASE "-O2" CACHE INTERNAL "c release compiler flags")
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2" CACHE INTERNAL "cxx release compiler flags")
+SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags")
\ No newline at end of file