mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
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:
+20
-3
@@ -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
|
/* 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))
|
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);
|
ferr("ERROR: '%s' is a directory\n", relpath);
|
||||||
goto errout_with_semaphore;
|
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
|
#ifdef CONFIG_FILE_MODE
|
||||||
# warning "Missing check for privileges based on inode->i_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_size = dirinfo.rd_size;
|
||||||
rf->rf_type = (uint8_t)(dirinfo.rd_next & RFNEXT_ALLMODEMASK);
|
|
||||||
|
|
||||||
/* Get the start of the file data */
|
/* 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 */
|
/* 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);
|
rm->rm_hwsectorsize, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,7 +163,6 @@ struct romfs_file_s
|
|||||||
uint32_t rf_size; /* Size of the file in bytes */
|
uint32_t rf_size; /* Size of the file in bytes */
|
||||||
uint32_t rf_cachesector; /* Current sector in the rf_buffer */
|
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_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
|
/* This structure is used internally for describing the result of
|
||||||
|
|||||||
Reference in New Issue
Block a user