fs/fat: Avoid caculating the bogus directory entry address for the FAT root directory (since it has no directory entry). This change should have no effect, other than making the logic clearer.

This commit is contained in:
Boris Astardzhiev 2018-05-24 06:18:15 -06:00 committed by Gregory Nutt
parent c9be3dd387
commit ae6b80f8b6

View File

@ -217,11 +217,18 @@ static int fat_open(FAR struct file *filep, FAR const char *relpath,
/* The name exists -- but is it a file or a directory? */
direntry = &fs->fs_buffer[dirinfo.fd_seq.ds_offset];
if (dirinfo.fd_root ||
(DIR_GETATTRIBUTES(direntry) & FATATTR_DIRECTORY))
if (dirinfo.fd_root)
{
/* It is a directory */
/* It is the root directory */
ret = -EISDIR;
goto errout_with_semaphore;
}
direntry = &fs->fs_buffer[dirinfo.fd_seq.ds_offset];
if ((DIR_GETATTRIBUTES(direntry) & FATATTR_DIRECTORY) != 0)
{
/* It is a regular directory */
ret = -EISDIR;
goto errout_with_semaphore;
@ -1576,8 +1583,6 @@ static int fat_opendir(FAR struct inode *mountpt, FAR const char *relpath,
goto errout_with_semaphore;
}
direntry = &fs->fs_buffer[dirinfo.fd_seq.ds_offset];
/* Check if this is the root directory */
if (dirinfo.fd_root)
@ -1591,10 +1596,13 @@ static int fat_opendir(FAR struct inode *mountpt, FAR const char *relpath,
dir->u.fat.fd_currsector = dirinfo.dir.fd_currsector;
dir->u.fat.fd_index = dirinfo.dir.fd_index;
}
else
{
/* This is not the root directory. Verify that it is some kind of directory */
else if ((DIR_GETATTRIBUTES(direntry) & FATATTR_DIRECTORY) == 0)
direntry = &fs->fs_buffer[dirinfo.fd_seq.ds_offset];
if ((DIR_GETATTRIBUTES(direntry) & FATATTR_DIRECTORY) == 0)
{
/* The entry is not a directory */
@ -1612,6 +1620,7 @@ static int fat_opendir(FAR struct inode *mountpt, FAR const char *relpath,
dir->u.fat.fd_currsector = fat_cluster2sector(fs, dir->u.fat.fd_currcluster);
dir->u.fat.fd_index = 2;
}
}
fat_semgive(fs);
return OK;