summaryrefslogtreecommitdiff
path: root/nuttx/fs/fat/fs_fat32dirent.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-11-19 20:30:39 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-11-19 20:30:39 +0000
commitfa09debae62c900129855fe03932ab0ceef2d0b0 (patch)
tree6b21b337cfd6e6cd8baeeb33a375a7c9226bf696 /nuttx/fs/fat/fs_fat32dirent.c
parent3d7a7cab5a53586684ea034062e200d33951fef0 (diff)
downloadpx4-nuttx-fa09debae62c900129855fe03932ab0ceef2d0b0.tar.gz
px4-nuttx-fa09debae62c900129855fe03932ab0ceef2d0b0.tar.bz2
px4-nuttx-fa09debae62c900129855fe03932ab0ceef2d0b0.zip
Revised FAT bugfix
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4104 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs/fat/fs_fat32dirent.c')
-rw-r--r--nuttx/fs/fat/fs_fat32dirent.c96
1 files changed, 19 insertions, 77 deletions
diff --git a/nuttx/fs/fat/fs_fat32dirent.c b/nuttx/fs/fat/fs_fat32dirent.c
index 54633004f..0c8d19f24 100644
--- a/nuttx/fs/fat/fs_fat32dirent.c
+++ b/nuttx/fs/fat/fs_fat32dirent.c
@@ -144,8 +144,6 @@ static inline int fat_getsfname(uint8_t *direntry, char *buffer,
static void fat_getlfnchunk(uint8_t *chunk, uint8_t *dest, int nchunk);
static inline int fat_getlfname(struct fat_mountpt_s *fs, struct fs_dirent_s *dir);
#endif
-static int fat_dirverify(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo,
- uint16_t offset);
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);
@@ -794,14 +792,13 @@ static inline int fat_findalias(struct fat_mountpt_s *fs,
memcpy(&tmpinfo, dirinfo, sizeof(struct fat_dirinfo_s));
- /* Then re-initialize to the beginning of the current directory, skipping
- * over the first entry (unused in the root directory and '.' entry in other
- * directories).
+ /* Then re-initialize to the beginning of the current directory, starting
+ * with the first entry.
*/
tmpinfo.dir.fd_startcluster = tmpinfo.dir.fd_currcluster;
tmpinfo.dir.fd_currsector = tmpinfo.fd_seq.ds_startsector;
- tmpinfo.dir.fd_index = 1;
+ tmpinfo.dir.fd_index = 0;
/* Search for the single short file name directory entry in this directory */
@@ -1912,56 +1909,6 @@ static inline int fat_getlfname(struct fat_mountpt_s *fs, struct fs_dirent_s *di
#endif
/****************************************************************************
- * Name: fat_dirverify
- *
- * Desciption:
- * Verify that every entry preceding this one is marked with something
- * other than DIR0_ALLEMPTY. This is necessary only in the root directory
- * of freshly formatted volumes. In that case, all entries are set to
- * zero.
- *
- * This function also assures that the sector containing the entry is in
- * the sector cache.
- *
- ****************************************************************************/
-
-static int fat_dirverify(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo,
- uint16_t offset)
-{
- uint8_t *direntry;
- uint16_t i;
- int ret;
-
- /* Make sure that the sector containing the directory entry is in the sector
- * cache.
- */
-
- ret = fat_fscacheread(fs, dirinfo->dir.fd_currsector);
- if (ret < 0)
- {
- return ret;
- }
-
- /* Check every entry preceding this one */
-
- for (i = 0; i < offset; i += DIR_SIZE)
- {
- /* Is the rest of the directory marked empty? */
-
- direntry = &fs->fs_buffer[i];
- if (direntry[DIR_NAME] == DIR0_ALLEMPTY)
- {
- /* Then mark the just the entry as empty */
-
- fs->fs_dirty = true;
- direntry[DIR_NAME] = DIR0_EMPTY;
- }
- }
-
- return OK;
-}
-
-/****************************************************************************
* Name: fat_putsfname
*
* Desciption: Write the short directory entry name.
@@ -2067,12 +2014,6 @@ static int fat_putlfname(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo
int namelen;
int ret;
- /* Some special handling in case we are writing the first entry of the
- * root directory in a freshly formatted volume.
- */
-
- (void)fat_dirverify(fs, dirinfo, dirinfo->fd_seq.ds_lfnoffset);
-
/* Get the length of the long file name (size of the fd_lfname array is
* LDIR_MAXFNAME+1 we do not have to check the length of the string).
* NOTE that remainder is conditionally incremented to include the NUL
@@ -2126,10 +2067,17 @@ static int fat_putlfname(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo
seqno = LDIR0_LAST | nentries;
- /* Now loop, writing each long file name entry. We know that the sector
- * is in the sector cache because fat_dirverify() assures us that that is
- * so.
- */
+ /* Make sure that the sector containing the "last" long file name entry
+ * is in the sector cache (it probably is not).
+ */
+
+ ret = fat_fscacheread(fs, dirinfo->dir.fd_currsector);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ /* Now loop, writing each long file name entry */
for (;;)
{
@@ -2255,12 +2203,6 @@ static int fat_putsfdirentry(struct fat_mountpt_s *fs,
{
uint8_t *direntry;
- /* Some special handling in case we are writing the first entry of the
- * root directory in a freshly formatted volume.
- */
-
- (void)fat_dirverify(fs, dirinfo, dirinfo->fd_seq.ds_offset);
-
/* Initialize the 32-byte directory entry */
direntry = &fs->fs_buffer[dirinfo->fd_seq.ds_offset];
@@ -2336,11 +2278,11 @@ int fat_finddirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo,
dirinfo->dir.fd_currsector = cluster;
}
- /* fd_index is the index into the current directory table. It is set to one
- * to skip over the first, unused entry in the root directory.
+ /* fd_index is the index into the current directory table. It is set to the
+ * the first, entry in the root directory.
*/
- dirinfo->dir.fd_index = 1;
+ dirinfo->dir.fd_index = 0;
/* If no path was provided, then the root directory must be exactly what
* the caller is looking for.
@@ -2489,9 +2431,9 @@ int fat_allocatedirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo
dirinfo->dir.fd_currsector = fs->fs_rootbase;
}
- /* Skip over the first, unused entry in the root directory. */
+ /* Start at the first entry in the root directory. */
- dirinfo->dir.fd_index = 1;
+ dirinfo->dir.fd_index = 0;
/* Is this a path segment a long or a short file. Was a long file
* name parsed?