This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 489223f0d588a72a63f82105ecffdb3b5cbe6889 Author: anjiahao <anjia...@xiaomi.com> AuthorDate: Tue Jul 2 12:07:07 2024 +0800 modlib:move get file info logic to modlib Signed-off-by: anjiahao <anjia...@xiaomi.com> --- include/nuttx/lib/modlib.h | 3 +++ libs/libc/modlib/modlib_init.c | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/nuttx/lib/modlib.h b/include/nuttx/lib/modlib.h index a18a224ba2..2a9c24b5b5 100644 --- a/include/nuttx/lib/modlib.h +++ b/include/nuttx/lib/modlib.h @@ -205,6 +205,9 @@ struct mod_loadinfo_s size_t textalign; /* Necessary alignment of .text */ size_t dataalign; /* Necessary alignment of .bss/.text */ off_t filelen; /* Length of the entire module file */ + uid_t fileuid; /* Uid of the file system */ + gid_t filegid; /* Gid of the file system */ + int filemode; /* Mode of the file system */ Elf_Ehdr ehdr; /* Buffered module file header */ FAR Elf_Phdr *phdr; /* Buffered module program headers */ FAR Elf_Shdr *shdr; /* Buffered module section headers */ diff --git a/libs/libc/modlib/modlib_init.c b/libs/libc/modlib/modlib_init.c index 6f1c709cdb..9b092fc583 100644 --- a/libs/libc/modlib/modlib_init.c +++ b/libs/libc/modlib/modlib_init.c @@ -44,10 +44,10 @@ ****************************************************************************/ /**************************************************************************** - * Name: modlib_filelen + * Name: modlib_fileinfo * * Description: - * Get the size of the ELF file + * Get the info of the ELF file * * Returned Value: * 0 (OK) is returned on success and a negated errno is returned on @@ -55,7 +55,7 @@ * ****************************************************************************/ -static inline int modlib_filelen(FAR struct mod_loadinfo_s *loadinfo) +static inline int modlib_fileinfo(FAR struct mod_loadinfo_s *loadinfo) { struct stat buf; int ret; @@ -78,9 +78,12 @@ static inline int modlib_filelen(FAR struct mod_loadinfo_s *loadinfo) return -ENOENT; } - /* Return the size of the file in the loadinfo structure */ + /* Return some stats info of the file in the loadinfo structure */ - loadinfo->filelen = buf.st_size; + loadinfo->filelen = buf.st_size; + loadinfo->fileuid = buf.st_uid; + loadinfo->filegid = buf.st_gid; + loadinfo->filemode = buf.st_mode; return OK; } @@ -122,12 +125,12 @@ int modlib_initialize(FAR const char *filename, return -errval; } - /* Get the length of the file. */ + /* Get some stats info of the file. */ - ret = modlib_filelen(loadinfo); + ret = modlib_fileinfo(loadinfo); if (ret < 0) { - berr("ERROR: modlib_filelen failed: %d\n", ret); + berr("ERROR: modlib_fileinfo failed: %d\n", ret); return ret; }