From 69ec6f5dd8cf39998c4529b974bdc9cf7e98bdcc Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Mon, 9 Jul 2012 15:28:11 +0200 Subject: [PATCH] ffat: Enable support for long file names Fixes #270. --- libports/lib/mk/ffat_block.mk | 5 +++-- libports/src/lib/ffat/config.patch | 15 ++++++++++++--- libports/src/lib/libc_ffat/plugin.cc | 13 +++++++++---- libports/src/test/libc_ffat/main.cc | 14 +++++++++----- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/libports/lib/mk/ffat_block.mk b/libports/lib/mk/ffat_block.mk index 6f6d06687..3a2e5d6c3 100644 --- a/libports/lib/mk/ffat_block.mk +++ b/libports/lib/mk/ffat_block.mk @@ -4,10 +4,11 @@ INC_DIR += $(REP_DIR)/src/lib/ffat/contrib -SRC_C = ff.c +SRC_C = ff.c ccsbcs.c SRC_CC = diskio_block.cc LIBS = signal -vpath % $(REP_DIR)/contrib/ff007e/src vpath % $(REP_DIR)/src/lib/ffat/ +vpath % $(REP_DIR)/contrib/ff007e/src +vpath % $(REP_DIR)/contrib/ff007e/src/option diff --git a/libports/src/lib/ffat/config.patch b/libports/src/lib/ffat/config.patch index b6d73a32e..3e87856c2 100644 --- a/libports/src/lib/ffat/config.patch +++ b/libports/src/lib/ffat/config.patch @@ -1,6 +1,6 @@ -diff --git a/src/ffconf.h b/src/ffconf.h ---- a/src/ffconf.h -+++ b/src/ffconf.h +diff -urN ff007e.orig/src/ffconf.h ff007e/src/ffconf.h +--- ff007e.orig/src/ffconf.h 2009-11-03 00:44:22.000000000 +0100 ++++ ff007e/src/ffconf.h 2012-07-09 13:08:03.000000000 +0200 @@ -40,7 +40,7 @@ /* To enable string functions, set _USE_STRFUNC to 1 or 2. */ @@ -19,6 +19,15 @@ diff --git a/src/ffconf.h b/src/ffconf.h /* The _CODE_PAGE specifies the OEM code page to be used on the target system. / Incorrect setting of the code page can cause a file open failure. / +@@ -86,7 +86,7 @@ + */ + + +-#define _USE_LFN 0 /* 0, 1 or 2 */ ++#define _USE_LFN 1 /* 0, 1 or 2 */ + #define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ + /* The _USE_LFN option switches the LFN support. + / @@ -105,7 +105,7 @@ */ diff --git a/libports/src/lib/libc_ffat/plugin.cc b/libports/src/lib/libc_ffat/plugin.cc index 034e34f4c..167a674a2 100644 --- a/libports/src/lib/libc_ffat/plugin.cc +++ b/libports/src/lib/libc_ffat/plugin.cc @@ -320,9 +320,10 @@ class Plugin : public Libc::Plugin ::memset(dirent, 0, sizeof(struct dirent)); FILINFO ffat_file_info; - FRESULT res; + ffat_file_info.lfname = dirent->d_name; + ffat_file_info.lfsize = sizeof(dirent->d_name); - res = f_readdir(_get_ffat_dir(fd), &ffat_file_info); + FRESULT res = f_readdir(_get_ffat_dir(fd), &ffat_file_info); switch(res) { case FR_OK: break; @@ -354,8 +355,9 @@ class Plugin : public Libc::Plugin dirent->d_reclen = sizeof(struct dirent); - ::strncpy(dirent->d_name, ffat_file_info.fname, - sizeof(dirent->d_name)); + if (dirent->d_name[0] == 0) /* use short file name */ + ::strncpy(dirent->d_name, ffat_file_info.fname, + sizeof(dirent->d_name)); dirent->d_namlen = ::strlen(dirent->d_name); @@ -587,6 +589,9 @@ class Plugin : public Libc::Plugin using namespace Ffat; FILINFO file_info; + /* the long file name is not used in this function */ + file_info.lfname = 0; + file_info.lfsize = 0; FRESULT res = f_stat(path, &file_info); diff --git a/libports/src/test/libc_ffat/main.cc b/libports/src/test/libc_ffat/main.cc index 03725508d..7c39e8eba 100644 --- a/libports/src/test/libc_ffat/main.cc +++ b/libports/src/test/libc_ffat/main.cc @@ -23,8 +23,8 @@ #define CALL_AND_CHECK(ret, operation, condition, info_string, ...) \ - ret = operation; \ printf("calling " #operation " " info_string "\n", ##__VA_ARGS__); \ + ret = operation; \ if (condition) { \ printf(#operation " succeeded\n"); \ } else { \ @@ -37,16 +37,20 @@ int main(int argc, char *argv[]) { int ret, fd; - char const *dir_name = "/testdir"; - char const *file_name = "test.tst"; - char const *pattern = "a single line of text"; + char const *dir_name = "/testdir"; + char const *dir_name_long = "testdir long"; + char const *file_name = "test.tst"; + char const *pattern = "a single line of text"; - /* create directory */ + /* create directory (short name) */ CALL_AND_CHECK(ret, mkdir(dir_name, 0777), ret == 0, "dir_name=%s", dir_name); /* change to new directory */ CALL_AND_CHECK(ret, chdir(dir_name), ret == 0, "dir_name=%s", dir_name); + /* create directory (long name) */ + CALL_AND_CHECK(ret, mkdir(dir_name_long, 0777), ret == 0, "dir_name_long=%s", dir_name_long); + /* write pattern to a file */ CALL_AND_CHECK(fd, open(file_name, O_CREAT | O_WRONLY), fd >= 0, "file_name=%s", file_name); size_t count = strlen(pattern);