summaryrefslogtreecommitdiff
path: root/core/fs/fat
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-08-12 20:56:46 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-08-12 20:56:46 -0700
commit0456f52098e30355a09ad2e05c3a26fc2dbc1752 (patch)
tree6913b6476e85971a9fff393b55f0aca249e51984 /core/fs/fat
parent73ed95079a6d317db472935a8965f36a63f10140 (diff)
downloadsyslinux-0456f52098e30355a09ad2e05c3a26fc2dbc1752.tar.gz
core: make FILENAME_MAX common; librarize mangle/unmangle
FILENAME_MAX was 2^8 in all variants by now; make it a common define. Libraries mangle/unmangle; we have generic_mangle_name for Unix-like filesystems, and unmangle now defaults to simple strcpy. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'core/fs/fat')
-rw-r--r--core/fs/fat/fat.c49
1 files changed, 19 insertions, 30 deletions
diff --git a/core/fs/fat/fat.c b/core/fs/fat/fat.c
index 83dc9081..1b1c532e 100644
--- a/core/fs/fat/fat.c
+++ b/core/fs/fat/fat.c
@@ -6,9 +6,6 @@
#include "fat_fs.h"
#include "fs.h"
-
-#define FILENAME_MAX_LG2 8
-#define FILENAME_MAX (1 << FILENAME_MAX_LG2)
#define ROOT_DIR_WORD 0x002f
/* file structure. This holds the information for each currently open file */
@@ -352,55 +349,47 @@ static uint32_t vfat_getfssec(struct file *gfile, char *buf, int sectors,
* ends on encountering any whitespace.
*
*/
-static void vfat_mangle_name(char *dst, char *src)
+static void vfat_mangle_name(char *dst, const char *src)
{
char *p = dst;
+ char c;
int i = FILENAME_MAX -1;
- while(*src > ' ') {
- if ( *src == '\\' )
- *src = '/';
+ /*
+ * Copy the filename, converting backslash to slash and
+ * collapsing duplicate separators.
+ */
+ while (not_whitespace(c = *src)) {
+ if (c == '\\')
+ c = '/';
- if (*src == '/') {
- if (*(src+1) == '/') {
- src ++;
- i --;
+ if (c == '/') {
+ if (src[1] == '/' || src[1] == '\\') {
+ src++;
+ i--;
continue;
}
}
- i --;
+ i--;
*dst++ = *src++;
}
+ /* Strip terminal slashes or whitespace */
while (1) {
if (dst == p)
break;
if ((*(dst-1) != '/') && (*(dst-1) != '.'))
break;
- dst --;
- i ++;
+ dst--;
+ i++;
}
- i ++;
+ i++;
for (; i > 0; i --)
*dst++ = '\0';
}
-
-/*
- * Does the opposite of mangle_name; converts a DOS-mangled
- * filename to the conventional representation. This is
- * needed for the BOOT_IMAGE= parameter for the kernel.
- *
- * it returns the lenght of the filename.
- */
-static int vfat_unmangle_name(char *dst, char *src)
-{
- strcpy(dst, src);
- return strlen(src);
-}
-
/**
* mangle_dos_name:
*
@@ -959,6 +948,6 @@ const struct fs_ops vfat_fs_ops = {
.getfssec = vfat_getfssec,
.close_file = vfat_close_file,
.mangle_name = vfat_mangle_name,
- .unmangle_name = vfat_unmangle_name,
+ .unmangle_name = NULL,
.load_config = vfat_load_config
};