romfs: Simplify fstat() implementation. It is not necessary to save the file type at open, We know in this context that the file is a regular file.

This commit is contained in:
Gregory Nutt 2017-02-13 06:55:06 -06:00
parent 904478c1d9
commit 29028bcd5a
2 changed files with 20 additions and 4 deletions

View File

@ -205,7 +205,11 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
}
/* The full path exists -- but is the final component a file
* or a directory?
* or a directory? Or some other Unix file type that not
* appropriate in this contex.
*
* REVISIT: This logic should follow hard/soft link file
* types. At present, it returns the ENXIO.
*/
if (IS_DIRECTORY(dirinfo.rd_next))
@ -216,6 +220,20 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
ferr("ERROR: '%s' is a directory\n", relpath);
goto errout_with_semaphore;
}
else if (!IS_FILE(dirinfo.rd_next))
{
/* ENXIO indicates "The named file is a character special or
* block special file, and the device associated with this
* special file does not exist."
*
* Here we also return ENXIO if the file is not a directory
* or a regular file.
*/
ret = -ENXIO;
ferr("ERROR: '%s' is a special file\n", relpath);
goto errout_with_semaphore;
}
#ifdef CONFIG_FILE_MODE
# warning "Missing check for privileges based on inode->i_mode"
@ -238,7 +256,6 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
*/
rf->rf_size = dirinfo.rd_size;
rf->rf_type = (uint8_t)(dirinfo.rd_next & RFNEXT_ALLMODEMASK);
/* Get the start of the file data */
@ -720,7 +737,7 @@ static int romfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
{
/* Return information about the directory entry */
ret = romfs_stat_common(rf->rf_type, rf->rf_size,
ret = romfs_stat_common(RFNEXT_FILE, rf->rf_size,
rm->rm_hwsectorsize, buf);
}

View File

@ -163,7 +163,6 @@ struct romfs_file_s
uint32_t rf_size; /* Size of the file in bytes */
uint32_t rf_cachesector; /* Current sector in the rf_buffer */
uint8_t *rf_buffer; /* File sector buffer, allocated if rm_xipbase==0 */
uint8_t rf_type; /* File type (for fstat()) */
};
/* This structure is used internally for describing the result of