ffat: Enable support for long file names

Fixes #270.
This commit is contained in:
Christian Prochaska 2012-07-09 15:28:11 +02:00 committed by Norman Feske
parent e1435a3f57
commit 69ec6f5dd8
4 changed files with 33 additions and 14 deletions

View File

@ -4,10 +4,11 @@
INC_DIR += $(REP_DIR)/src/lib/ffat/contrib INC_DIR += $(REP_DIR)/src/lib/ffat/contrib
SRC_C = ff.c SRC_C = ff.c ccsbcs.c
SRC_CC = diskio_block.cc SRC_CC = diskio_block.cc
LIBS = signal LIBS = signal
vpath % $(REP_DIR)/contrib/ff007e/src
vpath % $(REP_DIR)/src/lib/ffat/ vpath % $(REP_DIR)/src/lib/ffat/
vpath % $(REP_DIR)/contrib/ff007e/src
vpath % $(REP_DIR)/contrib/ff007e/src/option

View File

@ -1,6 +1,6 @@
diff --git a/src/ffconf.h b/src/ffconf.h diff -urN ff007e.orig/src/ffconf.h ff007e/src/ffconf.h
--- a/src/ffconf.h --- ff007e.orig/src/ffconf.h 2009-11-03 00:44:22.000000000 +0100
+++ b/src/ffconf.h +++ ff007e/src/ffconf.h 2012-07-09 13:08:03.000000000 +0200
@@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */ /* 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. /* 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. / 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 @@ @@ -105,7 +105,7 @@
*/ */

View File

@ -320,9 +320,10 @@ class Plugin : public Libc::Plugin
::memset(dirent, 0, sizeof(struct dirent)); ::memset(dirent, 0, sizeof(struct dirent));
FILINFO ffat_file_info; 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) { switch(res) {
case FR_OK: case FR_OK:
break; break;
@ -354,8 +355,9 @@ class Plugin : public Libc::Plugin
dirent->d_reclen = sizeof(struct dirent); dirent->d_reclen = sizeof(struct dirent);
::strncpy(dirent->d_name, ffat_file_info.fname, if (dirent->d_name[0] == 0) /* use short file name */
sizeof(dirent->d_name)); ::strncpy(dirent->d_name, ffat_file_info.fname,
sizeof(dirent->d_name));
dirent->d_namlen = ::strlen(dirent->d_name); dirent->d_namlen = ::strlen(dirent->d_name);
@ -587,6 +589,9 @@ class Plugin : public Libc::Plugin
using namespace Ffat; using namespace Ffat;
FILINFO file_info; 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); FRESULT res = f_stat(path, &file_info);

View File

@ -23,8 +23,8 @@
#define CALL_AND_CHECK(ret, operation, condition, info_string, ...) \ #define CALL_AND_CHECK(ret, operation, condition, info_string, ...) \
ret = operation; \
printf("calling " #operation " " info_string "\n", ##__VA_ARGS__); \ printf("calling " #operation " " info_string "\n", ##__VA_ARGS__); \
ret = operation; \
if (condition) { \ if (condition) { \
printf(#operation " succeeded\n"); \ printf(#operation " succeeded\n"); \
} else { \ } else { \
@ -37,16 +37,20 @@ int main(int argc, char *argv[])
{ {
int ret, fd; int ret, fd;
char const *dir_name = "/testdir"; char const *dir_name = "/testdir";
char const *file_name = "test.tst"; char const *dir_name_long = "testdir long";
char const *pattern = "a single line of text"; 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); CALL_AND_CHECK(ret, mkdir(dir_name, 0777), ret == 0, "dir_name=%s", dir_name);
/* change to new directory */ /* change to new directory */
CALL_AND_CHECK(ret, chdir(dir_name), ret == 0, "dir_name=%s", dir_name); 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 */ /* write pattern to a file */
CALL_AND_CHECK(fd, open(file_name, O_CREAT | O_WRONLY), fd >= 0, "file_name=%s", file_name); CALL_AND_CHECK(fd, open(file_name, O_CREAT | O_WRONLY), fd >= 0, "file_name=%s", file_name);
size_t count = strlen(pattern); size_t count = strlen(pattern);