mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Merge pull request #24 from aldot/silence-shadow-warnings-1
Silence shadow warnings
This commit is contained in:
		
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							| @@ -37,7 +37,7 @@ test: test_format test_dirs test_files test_seek test_truncate test_parallel \ | ||||
| 	test_alloc test_paths test_orphan test_move test_corrupt | ||||
| test_%: tests/test_%.sh | ||||
| ifdef QUIET | ||||
| 	./$< | sed -n '/^[-=]/p' | ||||
| 	@./$< | sed -n '/^[-=]/p' | ||||
| else | ||||
| 	./$< | ||||
| endif | ||||
|   | ||||
| @@ -190,7 +190,7 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) { | ||||
|     } | ||||
|  | ||||
|     if (!err && S_ISREG(st.st_mode) && (S_IWUSR & st.st_mode)) { | ||||
|         int err = unlink(emu->path); | ||||
|         err = unlink(emu->path); | ||||
|         if (err) { | ||||
|             return -errno; | ||||
|         } | ||||
|   | ||||
							
								
								
									
										58
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -481,7 +481,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir, | ||||
|             while (newoff < (0x7fffffff & dir->d.size)-4) { | ||||
|                 if (i < count && regions[i].oldoff == oldoff) { | ||||
|                     lfs_crc(&crc, regions[i].newdata, regions[i].newlen); | ||||
|                     int err = lfs_bd_prog(lfs, dir->pair[0], | ||||
|                     err = lfs_bd_prog(lfs, dir->pair[0], | ||||
|                             newoff, regions[i].newdata, regions[i].newlen); | ||||
|                     if (err) { | ||||
|                         if (err == LFS_ERR_CORRUPT) { | ||||
| @@ -495,7 +495,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir, | ||||
|                     i += 1; | ||||
|                 } else { | ||||
|                     uint8_t data; | ||||
|                     int err = lfs_bd_read(lfs, oldpair[1], oldoff, &data, 1); | ||||
|                     err = lfs_bd_read(lfs, oldpair[1], oldoff, &data, 1); | ||||
|                     if (err) { | ||||
|                         return err; | ||||
|                     } | ||||
| @@ -1005,7 +1005,7 @@ int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) { | ||||
|             return LFS_ERR_INVAL; | ||||
|         } | ||||
|  | ||||
|         int err = lfs_dir_fetch(lfs, dir, dir->d.tail); | ||||
|         err = lfs_dir_fetch(lfs, dir, dir->d.tail); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
| @@ -1016,6 +1016,7 @@ int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) { | ||||
| } | ||||
|  | ||||
| lfs_soff_t lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir) { | ||||
|     (void)lfs; | ||||
|     return dir->pos; | ||||
| } | ||||
|  | ||||
| @@ -1116,7 +1117,7 @@ static int lfs_ctz_extend(lfs_t *lfs, | ||||
|             if (size != lfs->cfg->block_size) { | ||||
|                 for (lfs_off_t i = 0; i < size; i++) { | ||||
|                     uint8_t data; | ||||
|                     int err = lfs_cache_read(lfs, rcache, NULL, | ||||
|                     err = lfs_cache_read(lfs, rcache, NULL, | ||||
|                             head, i, &data, 1); | ||||
|                     if (err) { | ||||
|                         return err; | ||||
| @@ -1142,7 +1143,7 @@ static int lfs_ctz_extend(lfs_t *lfs, | ||||
|             lfs_size_t skips = lfs_ctz(index) + 1; | ||||
|  | ||||
|             for (lfs_off_t i = 0; i < skips; i++) { | ||||
|                 int err = lfs_cache_prog(lfs, pcache, rcache, | ||||
|                 err = lfs_cache_prog(lfs, pcache, rcache, | ||||
|                         nblock, 4*i, &head, 4); | ||||
|                 if (err) { | ||||
|                     if (err == LFS_ERR_CORRUPT) { | ||||
| @@ -1450,7 +1451,7 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) { | ||||
|             !lfs_pairisnull(file->pair)) { | ||||
|         // update dir entry | ||||
|         lfs_dir_t cwd; | ||||
|         int err = lfs_dir_fetch(lfs, &cwd, file->pair); | ||||
|         err = lfs_dir_fetch(lfs, &cwd, file->pair); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
| @@ -1669,7 +1670,8 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { | ||||
|         return LFS_ERR_INVAL; | ||||
|     } | ||||
|  | ||||
|     if (size < lfs_file_size(lfs, file)) { | ||||
|     lfs_off_t oldsize = lfs_file_size(lfs, file); | ||||
|     if (size < oldsize) { | ||||
|         // need to flush since directly changing metadata | ||||
|         int err = lfs_file_flush(lfs, file); | ||||
|         if (err) { | ||||
| @@ -1686,11 +1688,11 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { | ||||
|  | ||||
|         file->size = size; | ||||
|         file->flags |= LFS_F_DIRTY; | ||||
|     } else if (size > lfs_file_size(lfs, file)) { | ||||
|     } else if (size > oldsize) { | ||||
|         lfs_off_t pos = file->pos; | ||||
|  | ||||
|         // flush+seek if not already at end | ||||
|         if (file->pos != lfs_file_size(lfs, file)) { | ||||
|         if (file->pos != oldsize) { | ||||
|             int err = lfs_file_seek(lfs, file, 0, SEEK_END); | ||||
|             if (err) { | ||||
|                 return err; | ||||
| @@ -1716,6 +1718,7 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { | ||||
| } | ||||
|  | ||||
| lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file) { | ||||
|     (void)lfs; | ||||
|     return file->pos; | ||||
| } | ||||
|  | ||||
| @@ -1729,6 +1732,7 @@ int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file) { | ||||
| } | ||||
|  | ||||
| lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) { | ||||
|     (void)lfs; | ||||
|     if (file->flags & LFS_F_WRITING) { | ||||
|         return lfs_max(file->pos, file->size); | ||||
|     } else { | ||||
| @@ -1737,7 +1741,7 @@ lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) { | ||||
| } | ||||
|  | ||||
|  | ||||
| /// General fs oprations /// | ||||
| /// General fs operations /// | ||||
| int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info) { | ||||
|     // check for root, can only be something like '/././../.' | ||||
|     if (strspn(path, "/.") == strlen(path)) { | ||||
| @@ -1801,7 +1805,7 @@ int lfs_remove(lfs_t *lfs, const char *path) { | ||||
|         // must be empty before removal, checking size | ||||
|         // without masking top bit checks for any case where | ||||
|         // dir is not empty | ||||
|         int err = lfs_dir_fetch(lfs, &dir, entry.d.u.dir); | ||||
|         err = lfs_dir_fetch(lfs, &dir, entry.d.u.dir); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } else if (dir.d.size != sizeof(dir.d)+4) { | ||||
| @@ -1826,7 +1830,7 @@ int lfs_remove(lfs_t *lfs, const char *path) { | ||||
|         cwd.d.tail[0] = dir.d.tail[0]; | ||||
|         cwd.d.tail[1] = dir.d.tail[1]; | ||||
|  | ||||
|         int err = lfs_dir_commit(lfs, &cwd, NULL, 0); | ||||
|         err = lfs_dir_commit(lfs, &cwd, NULL, 0); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
| @@ -1883,7 +1887,7 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { | ||||
|         // must be empty before removal, checking size | ||||
|         // without masking top bit checks for any case where | ||||
|         // dir is not empty | ||||
|         int err = lfs_dir_fetch(lfs, &dir, preventry.d.u.dir); | ||||
|         err = lfs_dir_fetch(lfs, &dir, preventry.d.u.dir); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } else if (dir.d.size != sizeof(dir.d)+4) { | ||||
| @@ -1910,12 +1914,12 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { | ||||
|     newentry.d.nlen = strlen(newpath); | ||||
|  | ||||
|     if (prevexists) { | ||||
|         int err = lfs_dir_update(lfs, &newcwd, &newentry, newpath); | ||||
|         err = lfs_dir_update(lfs, &newcwd, &newentry, newpath); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
|     } else { | ||||
|         int err = lfs_dir_append(lfs, &newcwd, &newentry, newpath); | ||||
|         err = lfs_dir_append(lfs, &newcwd, &newentry, newpath); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
| @@ -1943,7 +1947,7 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { | ||||
|         newcwd.d.tail[0] = dir.d.tail[0]; | ||||
|         newcwd.d.tail[1] = dir.d.tail[1]; | ||||
|  | ||||
|         int err = lfs_dir_commit(lfs, &newcwd, NULL, 0); | ||||
|         err = lfs_dir_commit(lfs, &newcwd, NULL, 0); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
| @@ -2080,7 +2084,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) { | ||||
|     // write both pairs to be safe | ||||
|     bool valid = false; | ||||
|     for (int i = 0; i < 2; i++) { | ||||
|         int err = lfs_dir_commit(lfs, &superdir, (struct lfs_region[]){ | ||||
|         err = lfs_dir_commit(lfs, &superdir, (struct lfs_region[]){ | ||||
|                 {sizeof(superdir.d), sizeof(superblock.d), | ||||
|                  &superblock.d, sizeof(superblock.d)} | ||||
|             }, 1); | ||||
| @@ -2125,7 +2129,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { | ||||
|     } | ||||
|  | ||||
|     if (!err) { | ||||
|         int err = lfs_bd_read(lfs, dir.pair[0], sizeof(dir.d), | ||||
|         err = lfs_bd_read(lfs, dir.pair[0], sizeof(dir.d), | ||||
|                 &superblock.d, sizeof(superblock.d)); | ||||
|         if (err) { | ||||
|             return err; | ||||
| @@ -2182,7 +2186,7 @@ int lfs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data) { | ||||
|  | ||||
|         // iterate over contents | ||||
|         while (dir.off + sizeof(entry.d) <= (0x7fffffff & dir.d.size)-4) { | ||||
|             int err = lfs_bd_read(lfs, dir.pair[0], dir.off, | ||||
|             err = lfs_bd_read(lfs, dir.pair[0], dir.off, | ||||
|                     &entry.d, sizeof(entry.d)); | ||||
|             if (err) { | ||||
|                 return err; | ||||
| @@ -2190,7 +2194,7 @@ int lfs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data) { | ||||
|  | ||||
|             dir.off += lfs_entry_size(&entry); | ||||
|             if ((0x70 & entry.d.type) == (0x70 & LFS_TYPE_REG)) { | ||||
|                 int err = lfs_ctz_traverse(lfs, &lfs->rcache, NULL, | ||||
|                 err = lfs_ctz_traverse(lfs, &lfs->rcache, NULL, | ||||
|                         entry.d.u.file.head, entry.d.u.file.size, cb, data); | ||||
|                 if (err) { | ||||
|                     return err; | ||||
| @@ -2244,7 +2248,7 @@ static int lfs_pred(lfs_t *lfs, const lfs_block_t dir[2], lfs_dir_t *pdir) { | ||||
|             return true; | ||||
|         } | ||||
|  | ||||
|         int err = lfs_dir_fetch(lfs, pdir, pdir->d.tail); | ||||
|         err = lfs_dir_fetch(lfs, pdir, pdir->d.tail); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
| @@ -2270,7 +2274,7 @@ static int lfs_parent(lfs_t *lfs, const lfs_block_t dir[2], | ||||
|         } | ||||
|  | ||||
|         while (true) { | ||||
|             int err = lfs_dir_next(lfs, parent, entry); | ||||
|             err = lfs_dir_next(lfs, parent, entry); | ||||
|             if (err && err != LFS_ERR_NOENT) { | ||||
|                 return err; | ||||
|             } | ||||
| @@ -2304,13 +2308,13 @@ static int lfs_moved(lfs_t *lfs, const void *e) { | ||||
|     // iterate over all directory directory entries | ||||
|     lfs_entry_t entry; | ||||
|     while (!lfs_pairisnull(cwd.d.tail)) { | ||||
|         int err = lfs_dir_fetch(lfs, &cwd, cwd.d.tail); | ||||
|         err = lfs_dir_fetch(lfs, &cwd, cwd.d.tail); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
|  | ||||
|         while (true) { | ||||
|             int err = lfs_dir_next(lfs, &cwd, &entry); | ||||
|             err = lfs_dir_next(lfs, &cwd, &entry); | ||||
|             if (err && err != LFS_ERR_NOENT) { | ||||
|                 return err; | ||||
|             } | ||||
| @@ -2441,7 +2445,7 @@ int lfs_deorphan(lfs_t *lfs) { | ||||
|         // check entries for moves | ||||
|         lfs_entry_t entry; | ||||
|         while (true) { | ||||
|             int err = lfs_dir_next(lfs, &cwd, &entry); | ||||
|             err = lfs_dir_next(lfs, &cwd, &entry); | ||||
|             if (err && err != LFS_ERR_NOENT) { | ||||
|                 return err; | ||||
|             } | ||||
| @@ -2460,7 +2464,7 @@ int lfs_deorphan(lfs_t *lfs) { | ||||
|                 if (moved) { | ||||
|                     LFS_DEBUG("Found move %d %d", | ||||
|                             entry.d.u.dir[0], entry.d.u.dir[1]); | ||||
|                     int err = lfs_dir_remove(lfs, &cwd, &entry); | ||||
|                     err = lfs_dir_remove(lfs, &cwd, &entry); | ||||
|                     if (err) { | ||||
|                         return err; | ||||
|                     } | ||||
| @@ -2468,7 +2472,7 @@ int lfs_deorphan(lfs_t *lfs) { | ||||
|                     LFS_DEBUG("Found partial move %d %d", | ||||
|                             entry.d.u.dir[0], entry.d.u.dir[1]); | ||||
|                     entry.d.type &= ~0x80; | ||||
|                     int err = lfs_dir_update(lfs, &cwd, &entry, NULL); | ||||
|                     err = lfs_dir_update(lfs, &cwd, &entry, NULL); | ||||
|                     if (err) { | ||||
|                         return err; | ||||
|                     } | ||||
|   | ||||
| @@ -7,11 +7,11 @@ | ||||
|  | ||||
|  | ||||
| // test stuff | ||||
| void test_log(const char *s, uintmax_t v) {{ | ||||
| static void test_log(const char *s, uintmax_t v) {{ | ||||
|     printf("%s: %jd\n", s, v); | ||||
| }} | ||||
|  | ||||
| void test_assert(const char *file, unsigned line, | ||||
| static void test_assert(const char *file, unsigned line, | ||||
|         const char *s, uintmax_t v, uintmax_t e) {{ | ||||
|     static const char *last[6] = {{0, 0}}; | ||||
|     if (v != e || !(last[0] == s || last[1] == s || | ||||
| @@ -37,7 +37,8 @@ void test_assert(const char *file, unsigned line, | ||||
|  | ||||
|  | ||||
| // utility functions for traversals | ||||
| int test_count(void *p, lfs_block_t b) {{ | ||||
| static int __attribute__((used)) test_count(void *p, lfs_block_t b) {{ | ||||
|     (void)b; | ||||
|     unsigned *u = (unsigned*)p; | ||||
|     *u += 1; | ||||
|     return 0; | ||||
| @@ -96,7 +97,7 @@ const struct lfs_config cfg = {{ | ||||
|  | ||||
|  | ||||
| // Entry point | ||||
| int main() {{ | ||||
| int main(void) {{ | ||||
|     lfs_emubd_create(&cfg, "blocks"); | ||||
|  | ||||
| {tests} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user