From 7ee46cebcbee82e3522b84a82041e4aa86760e40 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?=
 <benoit.thebaudeau@advansee.com>
Date: Fri, 20 Jul 2012 03:20:29 +0000
Subject: [PATCH] FAT: Fix file contents listed as directory
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With:
fatls mmc 0 /dir/file
dir: regular directory
file: regular file

The previous code read the contents of file as if it were directory entries to
list. This patch refuses to list file contents as if it were a folder.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 fs/fat/fat.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index f7bb1dadff3..19f6a8c0af6 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1109,11 +1109,11 @@ rootdir_done:
 			goto exit;
 		}
 
-		if (idx >= 0) {
-			if (!(dentptr->attr & ATTR_DIR))
-				goto exit;
+		if (isdir && !(dentptr->attr & ATTR_DIR))
+			goto exit;
+
+		if (idx >= 0)
 			subname = nextname;
-		}
 	}
 
 	ret = get_contents(mydata, dentptr, buffer, maxsize);
-- 
GitLab