From 07bfa32e87e7fc21d34629ca535acbec3ac8e56f Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Fri, 18 Feb 2022 20:36:52 +0800 Subject: [PATCH] fs/romfs: get file path by ioctl with FION_FILEPATH Signed-off-by: Jiuzhu Dong --- fs/romfs/fs_romfs.c | 10 +++++++++- fs/romfs/fs_romfs.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c index 5c20c9da27..c6332a801a 100644 --- a/fs/romfs/fs_romfs.c +++ b/fs/romfs/fs_romfs.c @@ -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; diff --git a/fs/romfs/fs_romfs.h b/fs/romfs/fs_romfs.h index 5fd2a63cc6..279ea99679 100644 --- a/fs/romfs/fs_romfs.h +++ b/fs/romfs/fs_romfs.h @@ -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