fs/romfs: get file path by ioctl with FION_FILEPATH

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-02-18 20:36:52 +08:00 committed by Xiang Xiao
parent 4f79a1e22c
commit 07bfa32e87
2 changed files with 10 additions and 1 deletions

View File

@ -228,7 +228,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
* file.
*/
rf = kmm_zalloc(sizeof(struct romfs_file_s));
rf = kmm_zalloc(sizeof(struct romfs_file_s) + strlen(relpath));
if (!rf)
{
ferr("ERROR: Failed to allocate private data\n");
@ -242,6 +242,7 @@ 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);
strcpy(rf->rf_path, relpath);
/* Get the start of the file data */
@ -587,6 +588,13 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
*ppv = (FAR void *)(rm->rm_xipbase + rf->rf_startoffset);
return OK;
}
else if (cmd == FIOC_FILEPATH)
{
FAR char *ptr = (FAR char *)((uintptr_t)arg);
inode_getpath(filep->f_inode, ptr);
strcat(ptr, rf->rf_path);
return OK;
}
ferr("ERROR: Invalid cmd: %d\n", cmd);
return -ENOTTY;

View File

@ -151,6 +151,7 @@ struct romfs_file_s
uint32_t rf_cachesector; /* Current sector in the rf_buffer */
FAR uint8_t *rf_buffer; /* File sector buffer, allocated if rm_xipbase==0 */
uint8_t rf_type; /* File type (for fstat()) */
char rf_path[1]; /* Path of open file */
};
/* This structure is used internally for describing the result of