public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rob Clark <robdclark@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 8/9] fs/fat: fix case for FAT shortnames
Date: Sat,  9 Sep 2017 13:15:59 -0400	[thread overview]
Message-ID: <20170909171606.20029-9-robdclark@gmail.com> (raw)
In-Reply-To: <20170909171606.20029-1-robdclark@gmail.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="windows-1254", Size: 3114 bytes --]

Noticed when comparing our output to linux.  There are some lcase bits
which control whether filename and/or extension should be downcase'd.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Łukasz Majewski <lukma@denx.de>
---
 fs/fat/fat.c       | 16 ++++++++++------
 fs/fat/fat_write.c |  4 ++--
 include/fat.h      |  6 +++++-
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index c951d84f57..65873a2c2a 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -29,11 +29,13 @@ static const int vfat_enabled = 0;
 #endif
 
 /*
- * Convert a string to lowercase.
+ * Convert a string to lowercase.  Converts at most 'len' characters,
+ * 'len' may be larger than the length of 'str' if 'str' is NULL
+ * terminated.
  */
-static void downcase(char *str)
+static void downcase(char *str, size_t len)
 {
-	while (*str != '\0') {
+	while (*str != '\0' && len--) {
 		*str = tolower(*str);
 		str++;
 	}
@@ -131,10 +133,13 @@ static void get_name(dir_entry *dirent, char *s_name)
 	ptr = s_name;
 	while (*ptr && *ptr != ' ')
 		ptr++;
+	if (dirent->lcase & CASE_LOWER_BASE)
+		downcase(s_name, (unsigned)(ptr - s_name));
 	if (dirent->ext[0] && dirent->ext[0] != ' ') {
-		*ptr = '.';
-		ptr++;
+		*ptr++ = '.';
 		memcpy(ptr, dirent->ext, 3);
+		if (dirent->lcase & CASE_LOWER_EXT)
+			downcase(ptr, 3);
 		ptr[3] = '\0';
 		while (*ptr && *ptr != ' ')
 			ptr++;
@@ -144,7 +149,6 @@ static void get_name(dir_entry *dirent, char *s_name)
 		*s_name = '\0';
 	else if (*s_name == aRING)
 		*s_name = DELETED_FLAG;
-	downcase(s_name);
 }
 
 static int flush_dirty_fat_buffer(fsdata *mydata);
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 4ca024c208..d0468baf8f 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -345,7 +345,7 @@ get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster,
 		*l_name = '\0';
 	else if (*l_name == aRING)
 		*l_name = DELETED_FLAG;
-	downcase(l_name);
+	downcase(l_name, INT_MAX);
 
 	/* Return the real directory entry */
 	*retdent = realdent;
@@ -981,7 +981,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
 
 	memcpy(l_filename, filename, name_len);
 	l_filename[name_len] = 0; /* terminate the string */
-	downcase(l_filename);
+	downcase(l_filename, INT_MAX);
 
 	startsect = mydata->rootdir_sect;
 	retdent = find_directory_entry(mydata, startsect,
diff --git a/include/fat.h b/include/fat.h
index 83cd90017e..0f58939124 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -128,10 +128,14 @@ typedef struct volume_info
 	/* Boot sign comes last, 2 bytes */
 } volume_info;
 
+/* see dir_entry::lcase: */
+#define CASE_LOWER_BASE	8	/* base (name) is lower case */
+#define CASE_LOWER_EXT	16	/* extension is lower case */
+
 typedef struct dir_entry {
 	char	name[8],ext[3];	/* Name and extension */
 	__u8	attr;		/* Attribute bits */
-	__u8	lcase;		/* Case for base and extension */
+	__u8	lcase;		/* Case for name and ext (CASE_LOWER_x) */
 	__u8	ctime_ms;	/* Creation time, milliseconds */
 	__u16	ctime;		/* Creation time */
 	__u16	cdate;		/* Creation date */
-- 
2.13.5


  parent reply	other threads:[~2017-09-09 17:15 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-09 17:15 [U-Boot] [PATCH v3 0/9] fs/fat: cleanups + readdir implementation Rob Clark
2017-09-09 17:15 ` [U-Boot] [PATCH v3 1/9] fs/fat: split out helper to init fsdata Rob Clark
2017-09-16  2:31   ` [U-Boot] [U-Boot, v3, " Tom Rini
2017-09-09 17:15 ` [U-Boot] [PATCH v3 2/9] fs/fat: introduce new director iterators Rob Clark
2017-09-16  2:32   ` [U-Boot] [U-Boot, v3, " Tom Rini
2017-09-09 17:15 ` [U-Boot] [PATCH v3 3/9] fat/fs: convert to directory iterators Rob Clark
2017-09-12 12:29   ` Simon Glass
2017-09-16  2:32   ` [U-Boot] [U-Boot, v3, " Tom Rini
2017-09-16 20:32     ` Adam Ford
2017-09-16 20:42       ` Rob Clark
2017-09-17 11:08         ` Adam Ford
2017-09-17 12:28           ` Rob Clark
2017-09-17 12:30             ` Rob Clark
2017-09-17 12:53           ` Rob Clark
2017-09-17 13:28             ` Tom Rini
2017-09-17 13:42             ` Adam Ford
2017-09-17 13:50               ` Rob Clark
2017-09-17 13:52                 ` Adam Ford
2017-09-09 17:15 ` [U-Boot] [PATCH v3 4/9] fs: add fs_readdir() Rob Clark
2017-09-12 12:29   ` Simon Glass
2017-09-16  2:32   ` [U-Boot] [U-Boot,v3,4/9] " Tom Rini
2017-09-09 17:15 ` [U-Boot] [PATCH v3 5/9] fs/fat: implement opendir/readdir/closedir Rob Clark
2017-09-12 12:29   ` Simon Glass
2017-09-16  2:32   ` [U-Boot] [U-Boot, v3, " Tom Rini
2017-09-09 17:15 ` [U-Boot] [PATCH v3 6/9] fat/fs: remove a bunch of dead code Rob Clark
2017-09-16  2:32   ` [U-Boot] [U-Boot,v3,6/9] " Tom Rini
2017-09-09 17:15 ` [U-Boot] [PATCH v3 7/9] fat/fs: move ls to generic implementation Rob Clark
2017-09-16  2:32   ` [U-Boot] [U-Boot, v3, " Tom Rini
2017-09-09 17:15 ` Rob Clark [this message]
2017-09-12 12:29   ` [U-Boot] [PATCH v3 8/9] fs/fat: fix case for FAT shortnames Simon Glass
2017-09-16  2:32   ` [U-Boot] [U-Boot,v3,8/9] " Tom Rini
2017-09-09 17:16 ` [U-Boot] [PATCH v3 9/9] fs/fat: Clean up open-coded sector <-> cluster conversions Rob Clark
2017-09-12 12:29   ` Simon Glass
2017-09-16  2:32   ` [U-Boot] [U-Boot, v3, " Tom Rini
  -- strict thread matches above, loose matches on Subject: below --
2017-09-10 11:21 [U-Boot] [PATCH v2 00/21] efi_loader: enough UEFI for standard distro boot Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v3 8/9] fs/fat: fix case for FAT shortnames Rob Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170909171606.20029-9-robdclark@gmail.com \
    --to=robdclark@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox