binfmt/elf: Replace nx_stat with file_stat
since kernel code prefer to use file_ API Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
7bb97f7e22
commit
1b2f37259a
@ -75,15 +75,14 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const char *filename)
|
||||
static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
struct stat buf;
|
||||
int ret;
|
||||
|
||||
/* Get the file stats */
|
||||
|
||||
ret = nx_stat(filename, &buf, 1);
|
||||
ret = file_fstat(&loadinfo->file, &buf);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("Failed to stat file: %d\n", ret);
|
||||
@ -98,10 +97,6 @@ static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo,
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* TODO: Verify that the file is readable. Not really important because
|
||||
* we will detect this when we try to open the file read-only.
|
||||
*/
|
||||
|
||||
/* Return the size of the file in the loadinfo structure */
|
||||
|
||||
loadinfo->filelen = buf.st_size;
|
||||
@ -135,15 +130,6 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
|
||||
|
||||
memset(loadinfo, 0, sizeof(struct elf_loadinfo_s));
|
||||
|
||||
/* Get the length of the file. */
|
||||
|
||||
ret = elf_filelen(loadinfo, filename);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("elf_filelen failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Open the binary file for reading (only) */
|
||||
|
||||
ret = file_open(&loadinfo->file, filename, O_RDONLY);
|
||||
@ -153,6 +139,15 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get the length of the file. */
|
||||
|
||||
ret = elf_filelen(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("elf_filelen failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Read the ELF ehdr from offset 0 */
|
||||
|
||||
ret = elf_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr,
|
||||
|
Loading…
Reference in New Issue
Block a user