From patchwork Sun Sep 10 11:21:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 812115 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g5IM3Dtv"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqpt84D2Pz9sDB for ; Sun, 10 Sep 2017 21:36:32 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2A5A0C21E8C; Sun, 10 Sep 2017 11:27:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EF2FCC21F44; Sun, 10 Sep 2017 11:24:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A5BE6C21F28; Sun, 10 Sep 2017 11:23:09 +0000 (UTC) Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by lists.denx.de (Postfix) with ESMTPS id DF189C21EBF for ; Sun, 10 Sep 2017 11:23:02 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id c69so3970239qke.5 for ; Sun, 10 Sep 2017 04:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y9Zc0Nv79pXQfDgDO26uLmB5Oesm4aAENBswlPKEk6U=; b=g5IM3Dtv4U4AkacmpI01t7FWK/azE2ZgRMDHZD6YvG905QG7D2HIvFDMX+5jbJ70+x Ueu6KlkXNtPE8/RNlRyrE+kN/cj3G3aNEnKEyhg3SLpmJIjq1k+FBTOxWSrymsohdK+O G/8i2KANuhBObTmfX+TyJ2kIiLPUW3VjqzYIzDNr4HNdNxBLnKVyl+0YDSmNJ+QJzRyt mEb8eEGlgP88swb+P5RoZfUbX0ICVBU2+7HIiWrKzxyLM0isrwjR8Lsb7eGcRpJp6h+0 yN8HywmQuoiyhTCE+nLy7FtOu/1Z0ZQwTKywcf7uFYN4adT7LPs6E8vKN9QwARYbL6Q1 HzWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y9Zc0Nv79pXQfDgDO26uLmB5Oesm4aAENBswlPKEk6U=; b=CsLdd9KWtIvXPstaIXUc30NlnreeDms57W3QgfE2JRaA7xwYPmbVfhHKsvfNdcX0Kg C4XvHpXf0HHkOh7DoZtmESCEQYMQ3Qnwn2W4KSNEImjfvW2EVH4n1Cljxv63olvj9CcO rxfxFOJubdASzfBR8jSvybupCO2hMldELeB85Lm1Q4auVitdfJYvt9/53+YLX5nJFZWg r7K9rvJe1LMdjsIKTaZ0Onn6rvN19FkMLOLozh2L5o9N67GPciVajhZICPSlX8I1TbUx whNOkTryeXoj4MKThIs34AgfBy/1sd71YYhIoYtuJaJHD84hHXkK6fXTlxv90IXQwr4C pByw== X-Gm-Message-State: AHPjjUhjKC9/21q+qI6qYNu8o3aPt/n8bqv0nl2RqIsdTDE463Cd5GSI 4texuY2YYcrb0hK//4o= X-Google-Smtp-Source: AOwi7QDsmbSfHv448a/Gw6Jb5hMCdkTJGZMmOg4uFRTNjtvavTOgxeTkVtnZrZZk/+dcltiCgue0Vg== X-Received: by 10.55.75.8 with SMTP id y8mr10023302qka.255.1505042581565; Sun, 10 Sep 2017 04:23:01 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id p60sm4231329qtd.93.2017.09.10.04.22.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 04:23:00 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sun, 10 Sep 2017 07:21:33 -0400 Message-Id: <20170910112149.21358-17-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170910112149.21358-1-robdclark@gmail.com> References: <20170910112149.21358-1-robdclark@gmail.com> MIME-Version: 1.0 Cc: Stephen Warren , Heinrich Schuchardt , Philipp Skadorov , Genevieve Chan , Tien Fong Chee Subject: [U-Boot] [PATCH v3 8/9] fs/fat: fix case for FAT shortnames X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 Reviewed-by: Ɓukasz Majewski --- 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 */