From b637a0cc3eb0c0dd1658a5b98fecf8f56430eda0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 15 Mar 2015 12:22:12 -0600 Subject: [PATCH] Costmetic changes name while debugging a filename issue --- TODO | 31 ++++++++++++++++++++++++++++++- fs/fat/fs_fat32.c | 1 - fs/fat/fs_fat32dirent.c | 26 ++++++++++++++++---------- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index 66e1be8272..5ec04619a6 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,7 @@ nuttx/ (6) Binary loaders (binfmt/) (12) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) - (11) Libraries (libc/, libm/) + (12) Libraries (libc/, libm/) (11) File system/Generic drivers (fs/, drivers/) (9) Graphics subystem (graphics/) (1) Pascal add-on (pcode/) @@ -1303,6 +1303,35 @@ o File system / Generic drivers (fs/, drivers/) Status: Open Priority: Medium + Title: MISSING FILES IN NSH 'LS' OF A DIRECTORY + Description: I have seen cases where (1) long file names are enabled, + but (2) a short file name is created like: + + nsh> echo "This is another thest" >/mnt/sdcard/another.txt + + But then on subsequent 'ls' operations, the file does not appear: + + nsh> ls -l /mnt/sdcard + + I have determined that the problem is because, for some as- + of-yet-unkown reason the short file name is treated as a long + file name. The name then fails the long filename checksum + test and is skipped. + + readdir() (and fat_readdir()) is the logic underlying the + failure and the problem appears to be something unique to the + fat_readdir() implementation. Why? Because the file is + visible when you put the SD card on a PC and because this + works fine: + + nsh> ls -l /mnt/sdcard/another.txt + + The failure does not happen on all short file names. I do + not understand the pattern. But I have not had the opportunity + to dig into this deeply. + Status: Open + Priority: Medium-High + o Graphics subsystem (graphics/) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index 305cb0aa4c..fafa2b59d2 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -1694,7 +1694,6 @@ static int fat_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) */ #ifdef CONFIG_FAT_LFN - /* Get a reference to the current, short file name directory * entry. */ diff --git a/fs/fat/fs_fat32dirent.c b/fs/fat/fs_fat32dirent.c index b79c5110fe..cfe0bd0f20 100644 --- a/fs/fat/fs_fat32dirent.c +++ b/fs/fat/fs_fat32dirent.c @@ -148,7 +148,8 @@ static int fat_putsfname(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo #ifdef CONFIG_FAT_LFN static void fat_initlfname(uint8_t *chunk, int nchunk); static void fat_putlfnchunk(uint8_t *chunk, const uint8_t *src, int nchunk); -static int fat_putlfname(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo); +static int fat_putlfname(struct fat_mountpt_s *fs, + struct fat_dirinfo_s *dirinfo); #endif static int fat_putsfdirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo, @@ -169,7 +170,9 @@ static int fat_putsfdirentry(struct fat_mountpt_s *fs, /**************************************************************************** * Name: fat_lfnchecksum * - * Desciption: Caculate the checksum of . + * Description: + * Verify that the checksum of the short file name matches the checksum + * that we found in the long file name entries. * ****************************************************************************/ @@ -182,7 +185,7 @@ static uint8_t fat_lfnchecksum(const uint8_t *sfname) for (i = DIR_MAXFNAME; i; i--) { sum = ((sum & 1) << 7) + (sum >> 1) + *sfname++; - } + } return sum; } @@ -604,7 +607,7 @@ static inline int fat_createalias(struct fat_dirinfo_s *dirinfo) tmp = ext - (char*)dirinfo->fd_lfname; namechars = tmp; - /* And the rest, exluding the '.' is the extension. */ + /* And the rest, excluding the '.' is the extension. */ extchars = len - namechars - 1; ext++; @@ -617,9 +620,9 @@ static inline int fat_createalias(struct fat_dirinfo_s *dirinfo) extchars = 0; } +#ifdef CONFIG_FAT_LCNAMES /* Alias are always all upper case */ -#ifdef CONFIG_FAT_LCNAMES dirinfo->fd_ntflags = 0; #endif @@ -628,7 +631,7 @@ static inline int fat_createalias(struct fat_dirinfo_s *dirinfo) memset(dirinfo->fd_name, ' ', DIR_MAXFNAME); /* Handle a special case where there is no name. Windows seems to use - * the extension plus random stuff then ~1 to pat to 8 bytes. Some + * the extension plus random stuff then ~1 to pad to 8 bytes. Some * examples: * * a.b -> a.b No long name @@ -673,7 +676,7 @@ static inline int fat_createalias(struct fat_dirinfo_s *dirinfo) if (ch == '\0') { /* This is the end of the source string. Do we need to add ~1. We - * will do that if we were parsing the name part when the endo of + * will do that if we were parsing the name part when the end of * string was encountered. */ @@ -2001,7 +2004,8 @@ static void fat_putlfnchunk(uint8_t *chunk, const uint8_t *src, int nchunk) ****************************************************************************/ #ifdef CONFIG_FAT_LFN -static int fat_putlfname(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo) +static int fat_putlfname(struct fat_mountpt_s *fs, + struct fat_dirinfo_s *dirinfo) { uint16_t diroffset; uint8_t *direntry; @@ -2036,6 +2040,7 @@ static int fat_putlfname(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo nentries++; remainder++; } + DEBUGASSERT(nentries > 0 && nentries <= LDIR_MAXLFNS); /* Create the short file name alias */ @@ -2059,7 +2064,7 @@ static int fat_putlfname(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo startsector = fat_cluster2sector(fs, dirinfo->dir.fd_currcluster); dirinfo->dir.fd_index += (dirinfo->dir.fd_currsector - startsector) * DIRSEC_NDIRS(fs); - /* Make sure that the alias is unique in this directory*/ + /* Make sure that the alias is unique in this directory */ ret = fat_uniquealias(fs, dirinfo); if (ret < 0) @@ -2418,7 +2423,8 @@ int fat_finddirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo, * ****************************************************************************/ -int fat_allocatedirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo) +int fat_allocatedirentry(struct fat_mountpt_s *fs, + struct fat_dirinfo_s *dirinfo) { int32_t cluster; int32_t prevcluster;