1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 */ 4 5 #ifndef FS_LITTLEFS_H 6 #define FS_LITTLEFS_H 7 8 #ifdef __cplusplus 9 extern "C" { 10 #endif 11 12 struct littlefs_cfg_param { 13 /** 14 * @brief Minimum size of a block read. All read operations will be a 15 * multiple of this value. 16 */ 17 unsigned int read_size; 18 19 /** 20 * @brief Minimum size of a block program. All program operations will be a 21 * multiple of this value. 22 */ 23 unsigned int prog_size; 24 25 /** 26 * @brief Size of an erasable block. This does not impact ram consumption and 27 * may be larger than the physical erase size. However, non-inlined files 28 * take up at minimum one block. Must be a multiple of the read 29 * and program sizes. 30 */ 31 unsigned int block_size; 32 33 /** 34 * @brief Number of erasable blocks on the device. 35 */ 36 unsigned int block_count; 37 38 /** 39 * @brief Number of erase cycles before littlefs evicts metadata logs and moves 40 * the metadata to another block. Suggested values are in the 41 * range 100-1000, with large values having better performance at the cost 42 * of less consistent wear distribution. 43 * 44 * @note Set to -1 to disable block-level wear-leveling. 45 */ 46 int block_cycles; 47 48 /** 49 * @brief Size of block caches. Each cache buffers a portion of a block in RAM. 50 * The littlefs needs a read cache, a program cache, and one additional 51 * cache per file. Larger caches can improve performance by storing more 52 * data and reducing the number of disk accesses. Must be a multiple of 53 * the read and program sizes, and a factor of the block size. 54 */ 55 unsigned int cache_size; 56 /** 57 * @brief Size of the lookahead buffer in bytes. A larger lookahead buffer 58 * increases the number of blocks found during an allocation pass. The 59 * lookahead buffer is stored as a compact bitmap, so each byte of RAM 60 * can track 8 blocks. Must be a multiple of 8. 61 */ 62 unsigned int lookahead_size; 63 }; 64 65 /** 66 * @brief Fetch littlefs config params 67 * 68 * @param @param[in] cfg Pointer to littlefs_cfg struct 69 * 70 * @return On success, return 0, else return -1 71 */ 72 int32_t littlefs_fetch_cfg_param(struct littlefs_cfg_param *cfg_param); 73 74 /** 75 * @brief Mount littlefs file system and register VFS driver for it 76 * 77 * @return On success, return 0, else return negative error code 78 */ 79 int32_t littlefs_register(void); 80 81 /** 82 * @brief Unmount littlefs file system and unregister VFS driver for it 83 * 84 * @return On success, return 0, else return negative error code 85 */ 86 int32_t littlefs_unregister(void); 87 88 /** 89 * @brief Used to format a specified partition. 90 * This API is expected to be used after littlefs initialization. 91 * 92 * @param @param[in] partition The partition name, e.g. "/data" or "/system" 93 * 94 * @return On success, return 0, else return negative value 95 */ 96 int littlefs_format(const char *partition); 97 98 /** 99 * @brief Used to format a specified partition. 100 * This API is expected to be used before nftl/littlefs initialization. 101 * 102 * @param @param[in] partition The partition name, e.g. "/data" or "/system" 103 * 104 * @return On success, return 0, else return negative value 105 */ 106 int littlefs_format2(const char *partition); 107 108 #ifdef AOS_COMP_NFTL 109 /** 110 * @brief Used to cleanup a specified partition, e.g. erase free blocks. 111 * 112 * @param @param[in] partition The partition name, e.g. "/data" or "/system" 113 * 114 * @return On success, return 0, else return negative value 115 */ 116 int littlefs_clean_partition(const char *partition); 117 #endif /* AOS_COMP_NFTL */ 118 119 /** 120 * @brief List the mounted littlefs filesystem. 121 * 122 * @return On success, return 0, else return negative error code 123 */ 124 int lfs_list(); 125 126 #ifdef __cplusplus 127 } 128 #endif 129 130 #endif 131 132