[syslinux:master] fat: Make mangle behavior similar to the standard one

syslinux-bot for H. Peter Anvin hpa at linux.intel.com
Fri Jun 29 14:00:02 PDT 2012


Commit-ID:  8804b0e5eb2b64c6e49025f5599552e8f00d9c33
Gitweb:     http://www.syslinux.org/commit/8804b0e5eb2b64c6e49025f5599552e8f00d9c33
Author:     H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Fri, 29 Jun 2012 13:57:42 -0700
Committer:  H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Fri, 29 Jun 2012 13:57:42 -0700

fat: Make mangle behavior similar to the standard one

Handle mangle in FAT the same as in the generic version, except for \
-> / conversion.

Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>

---
 core/fs/fat/fat.c |   35 +++++++++++++++++++----------------
 1 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/core/fs/fat/fat.c b/core/fs/fat/fat.c
index d307926..b08923c 100644
--- a/core/fs/fat/fat.c
+++ b/core/fs/fat/fat.c
@@ -220,24 +220,30 @@ static sector_t next_sector(struct file *file)
     return sector;
 }
 
-/*
- * Mangle a filename pointed to by src into a buffer pointed to by dst;
- * ends on encountering any whitespace.
+/**
+ * mangle_name:
+ *
+ * Mangle a filename pointed to by src into a buffer pointed
+ * to by dst; ends on encountering any whitespace.
+ * dst is preserved.
+ *
+ * This verifies that a filename is < FILENAME_MAX characters,
+ * doesn't contain whitespace, zero-pads the output buffer,
+ * and removes redundant slashes.
+ *
+ * Unlike the generic version, this also converts backslashes to
+ * forward slashes.
  *
  */
 static void vfat_mangle_name(char *dst, const char *src)
 {
     char *p = dst;
+    int i = FILENAME_MAX-1;
     char c;
-    int i = FILENAME_MAX -1;
 
-    /*
-     * Copy the filename, converting backslash to slash and
-     * collapsing duplicate separators.
-     */
     while (not_whitespace(c = *src)) {
-        if (c == '\\')
-            c = '/';
+	if (c == '\\')
+	    c = '/';
 
         if (c == '/') {
             if (src[1] == '/' || src[1] == '\\') {
@@ -250,16 +256,13 @@ static void vfat_mangle_name(char *dst, const char *src)
         *dst++ = *src++;
     }
 
-    /* Strip terminal slashes or whitespace */
     while (1) {
         if (dst == p)
             break;
-	if (*(dst-1) == '/' && dst-1 == p) /* it's the '/' case */
-		break;
-	if (dst-2 == p && *(dst-2) == '.' && *(dst-1) == '.' )	/* the '..' case */
-		break;
-        if ((*(dst-1) != '/') && (*(dst-1) != '.'))
+        if (dst[-1] != '/')
             break;
+	if ((dst[-1] == '/') && ((dst - 1) == p))
+	    break;
 
         dst--;
         i++;


More information about the Syslinux-commits mailing list