summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorAKASHI Takahiro <takahiro.akashi@linaro.org>2018-09-11 15:58:59 +0900
committerAlexander Graf <agraf@suse.de>2018-09-23 21:55:29 +0200
commitb94b6be543c24ce8ce5debececb0af0708fbd97f (patch)
tree30d3e8bd33cc34ce7c20785a26ac513147dba36f /fs
parentf23101f9513064efa716a132b114b2c2748b7823 (diff)
downloadu-boot-b94b6be543c24ce8ce5debececb0af0708fbd97f.tar.gz
u-boot-b94b6be543c24ce8ce5debececb0af0708fbd97f.tar.bz2
u-boot-b94b6be543c24ce8ce5debececb0af0708fbd97f.zip
fs: fat: handle "." and ".." of root dir correctly with fat_itr_resolve()
FAT's root directory does not have "." nor ".." So care must be taken when scanning root directory with fat_itr_resolve(). Without this patch, any file path starting with "." or ".." will not be resolved at all. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/fat/fat.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 5f921e81e3..c475f12c4f 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -931,6 +931,27 @@ static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
while (next[0] && !ISDIRDELIM(next[0]))
next++;
+ if (itr->is_root) {
+ /* root dir doesn't have "." nor ".." */
+ if ((((next - path) == 1) && !strncmp(path, ".", 1)) ||
+ (((next - path) == 2) && !strncmp(path, "..", 2))) {
+ /* point back to itself */
+ itr->clust = itr->fsdata->root_cluster;
+ itr->dent = NULL;
+ itr->remaining = 0;
+ itr->last_cluster = 0;
+
+ if (next[0] == 0) {
+ if (type & TYPE_DIR)
+ return 0;
+ else
+ return -ENOENT;
+ }
+
+ return fat_itr_resolve(itr, next, type);
+ }
+ }
+
while (fat_itr_next(itr)) {
int match = 0;
unsigned n = max(strlen(itr->name), (size_t)(next - path));