You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2021/07/06 02:18:26 UTC
[incubator-nuttx] 03/03: binfmt: Replace all nx_ API with file_ API
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 841a4922aacaee45ee0c456bfaf1c1355ccc9770
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Feb 16 01:15:08 2021 +0800
binfmt: Replace all nx_ API with file_ API
since binfmt is a kernel component
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
binfmt/binfmt_unloadmodule.c | 2 +-
binfmt/builtin.c | 19 ++++++++++---------
binfmt/elf.c | 1 -
binfmt/libelf/libelf_init.c | 6 ++----
binfmt/libelf/libelf_load.c | 2 +-
binfmt/libelf/libelf_read.c | 4 ++--
binfmt/libelf/libelf_uninit.c | 4 ++--
binfmt/libnxflat/libnxflat_init.c | 9 ++++-----
binfmt/libnxflat/libnxflat_load.c | 11 +++++------
binfmt/libnxflat/libnxflat_read.c | 4 ++--
binfmt/libnxflat/libnxflat_uninit.c | 4 ++--
binfmt/libnxflat/libnxflat_unload.c | 2 +-
binfmt/nxflat.c | 3 ---
include/nuttx/binfmt/elf.h | 2 +-
include/nuttx/binfmt/nxflat.h | 2 +-
15 files changed, 34 insertions(+), 41 deletions(-)
diff --git a/binfmt/binfmt_unloadmodule.c b/binfmt/binfmt_unloadmodule.c
index 5baac9e..e9b4455 100644
--- a/binfmt/binfmt_unloadmodule.c
+++ b/binfmt/binfmt_unloadmodule.c
@@ -156,7 +156,7 @@ int unload_module(FAR struct binary_s *binp)
{
binfo("Unmapping address space: %p\n", binp->mapped);
- munmap(binp->mapped, binp->mapsize);
+ file_munmap(binp->mapped, binp->mapsize);
}
/* Free allocated address spaces */
diff --git a/binfmt/builtin.c b/binfmt/builtin.c
index 2bb7826..d6d79c1 100644
--- a/binfmt/builtin.c
+++ b/binfmt/builtin.c
@@ -78,7 +78,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
int nexports)
{
FAR const struct builtin_s *builtin;
- int fd;
+ struct file file;
int index;
int ret;
@@ -86,22 +86,23 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
/* Open the binary file for reading (only) */
- fd = nx_open(filename, O_RDONLY);
- if (fd < 0)
+ ret = file_open(&file, filename, O_RDONLY);
+ if (ret < 0)
{
- berr("ERROR: Failed to open binary %s: %d\n", filename, fd);
- return fd;
+ berr("ERROR: Failed to open binary %s: %d\n", filename, ret);
+ return ret;
}
/* If this file is a BINFS file system, then we can recover the name of
* the file using the FIOC_FILENAME ioctl() call.
*/
- ret = nx_ioctl(fd, FIOC_FILENAME, (unsigned long)((uintptr_t)&filename));
+ ret = file_ioctl(&file, FIOC_FILENAME,
+ (unsigned long)((uintptr_t)&filename));
if (ret < 0)
{
berr("ERROR: FIOC_FILENAME ioctl failed: %d\n", ret);
- nx_close(fd);
+ file_close(&file);
return ret;
}
@@ -113,7 +114,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
if (index < 0)
{
berr("ERROR: %s is not a builtin application\n", filename);
- nx_close(fd);
+ file_close(&file);
return index;
}
@@ -125,7 +126,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
binp->entrypt = builtin->main;
binp->stacksize = builtin->stacksize;
binp->priority = builtin->priority;
- nx_close(fd);
+ file_close(&file);
return OK;
}
diff --git a/binfmt/elf.c b/binfmt/elf.c
index 9443aab..fd99c3d 100644
--- a/binfmt/elf.c
+++ b/binfmt/elf.c
@@ -114,7 +114,6 @@ static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo)
binfo(" dtors: %08lx\n", (long)loadinfo->dtors);
binfo(" ndtors: %d\n", loadinfo->ndtors);
#endif
- binfo(" filfd: %d\n", loadinfo->filfd);
binfo(" symtabidx: %d\n", loadinfo->symtabidx);
binfo(" strtabidx: %d\n", loadinfo->strtabidx);
diff --git a/binfmt/libelf/libelf_init.c b/binfmt/libelf/libelf_init.c
index f2da035..d2c1ba4 100644
--- a/binfmt/libelf/libelf_init.c
+++ b/binfmt/libelf/libelf_init.c
@@ -134,7 +134,6 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
/* Clear the load info structure */
memset(loadinfo, 0, sizeof(struct elf_loadinfo_s));
- loadinfo->filfd = -1;
/* Get the length of the file. */
@@ -147,10 +146,9 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
/* Open the binary file for reading (only) */
- loadinfo->filfd = nx_open(filename, O_RDONLY);
- if (loadinfo->filfd < 0)
+ ret = file_open(&loadinfo->file, filename, O_RDONLY);
+ if (ret < 0)
{
- ret = loadinfo->filfd;
berr("Failed to open ELF binary %s: %d\n", filename, ret);
return ret;
}
diff --git a/binfmt/libelf/libelf_load.c b/binfmt/libelf/libelf_load.c
index 0885b0e..e2c8d39 100644
--- a/binfmt/libelf/libelf_load.c
+++ b/binfmt/libelf/libelf_load.c
@@ -239,7 +239,7 @@ int elf_load(FAR struct elf_loadinfo_s *loadinfo)
int ret;
binfo("loadinfo: %p\n", loadinfo);
- DEBUGASSERT(loadinfo && loadinfo->filfd >= 0);
+ DEBUGASSERT(loadinfo && loadinfo->file.f_inode);
/* Load section headers into memory */
diff --git a/binfmt/libelf/libelf_read.c b/binfmt/libelf/libelf_read.c
index f3b3469..b05cda2 100644
--- a/binfmt/libelf/libelf_read.c
+++ b/binfmt/libelf/libelf_read.c
@@ -108,7 +108,7 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
{
/* Seek to the next read position */
- rpos = nx_seek(loadinfo->filfd, offset, SEEK_SET);
+ rpos = file_seek(&loadinfo->file, offset, SEEK_SET);
if (rpos != offset)
{
berr("Failed to seek to position %lu: %d\n",
@@ -118,7 +118,7 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
/* Read the file data at offset into the user buffer */
- nbytes = nx_read(loadinfo->filfd, buffer, readsize);
+ nbytes = file_read(&loadinfo->file, buffer, readsize);
if (nbytes < 0)
{
/* EINTR just means that we received a signal */
diff --git a/binfmt/libelf/libelf_uninit.c b/binfmt/libelf/libelf_uninit.c
index 16552d3..54ebee6 100644
--- a/binfmt/libelf/libelf_uninit.c
+++ b/binfmt/libelf/libelf_uninit.c
@@ -70,9 +70,9 @@ int elf_uninit(struct elf_loadinfo_s *loadinfo)
/* Close the ELF file */
- if (loadinfo->filfd >= 0)
+ if (loadinfo->file.f_inode)
{
- nx_close(loadinfo->filfd);
+ file_close(&loadinfo->file);
}
return OK;
diff --git a/binfmt/libnxflat/libnxflat_init.c b/binfmt/libnxflat/libnxflat_init.c
index 0f077ec..c7aba4f 100644
--- a/binfmt/libnxflat/libnxflat_init.c
+++ b/binfmt/libnxflat/libnxflat_init.c
@@ -94,10 +94,9 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
/* Open the binary file */
- loadinfo->filfd = nx_open(filename, O_RDONLY);
- if (loadinfo->filfd < 0)
+ ret = file_open(&loadinfo->file, filename, O_RDONLY);
+ if (ret < 0)
{
- ret = loadinfo->filfd;
berr("ERROR: Failed to open NXFLAT binary %s: %d\n", filename, ret);
return ret;
}
@@ -109,7 +108,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
if (ret < 0)
{
berr("ERROR: Failed to read NXFLAT header: %d\n", ret);
- nx_close(loadinfo->filfd);
+ file_close(&loadinfo->file);
return ret;
}
@@ -128,7 +127,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
*/
berr("ERROR: Bad NXFLAT header\n");
- nx_close(loadinfo->filfd);
+ file_close(&loadinfo->file);
return -ENOEXEC;
}
diff --git a/binfmt/libnxflat/libnxflat_load.c b/binfmt/libnxflat/libnxflat_load.c
index 65c4061..ffbc24c 100644
--- a/binfmt/libnxflat/libnxflat_load.c
+++ b/binfmt/libnxflat/libnxflat_load.c
@@ -132,13 +132,12 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
* memory resides as long as it is fully initialized and ready to execute.
*/
- loadinfo->ispace = (uint32_t)mmap(NULL, loadinfo->isize, PROT_READ,
- MAP_SHARED | MAP_FILE, loadinfo->filfd,
- 0);
- if (loadinfo->ispace == (uint32_t)MAP_FAILED)
+ ret = file_mmap(&loadinfo->file, NULL, loadinfo->isize, PROT_READ,
+ MAP_SHARED | MAP_FILE, 0, (FAR void **)&loadinfo->ispace);
+ if (ret < 0)
{
- berr("Failed to map NXFLAT ISpace: %d\n", errno);
- return -errno;
+ berr("Failed to map NXFLAT ISpace: %d\n", ret);
+ return ret;
}
binfo("Mapped ISpace (%" PRId32 " bytes) at %08x\n",
diff --git a/binfmt/libnxflat/libnxflat_read.c b/binfmt/libnxflat/libnxflat_read.c
index e90ce4a..084e713 100644
--- a/binfmt/libnxflat/libnxflat_read.c
+++ b/binfmt/libnxflat/libnxflat_read.c
@@ -113,7 +113,7 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
bytesleft = readsize;
do
{
- rpos = nx_seek(loadinfo->filfd, offset, SEEK_SET);
+ rpos = file_seek(&loadinfo->file, offset, SEEK_SET);
if (rpos != offset)
{
berr("Failed to seek to position %d: %d\n", offset, (int)rpos);
@@ -122,7 +122,7 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
/* Read the file data at offset into the user buffer */
- nbytes = nx_read(loadinfo->filfd, bufptr, bytesleft);
+ nbytes = file_read(&loadinfo->file, bufptr, bytesleft);
if (nbytes < 0)
{
if (nbytes != -EINTR)
diff --git a/binfmt/libnxflat/libnxflat_uninit.c b/binfmt/libnxflat/libnxflat_uninit.c
index 5ea6b17..3c2eb63 100644
--- a/binfmt/libnxflat/libnxflat_uninit.c
+++ b/binfmt/libnxflat/libnxflat_uninit.c
@@ -61,9 +61,9 @@
int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo)
{
- if (loadinfo->filfd >= 0)
+ if (loadinfo->file.f_inode)
{
- nx_close(loadinfo->filfd);
+ file_close(&loadinfo->file);
}
return OK;
diff --git a/binfmt/libnxflat/libnxflat_unload.c b/binfmt/libnxflat/libnxflat_unload.c
index e8da56f..cae6e3b 100644
--- a/binfmt/libnxflat/libnxflat_unload.c
+++ b/binfmt/libnxflat/libnxflat_unload.c
@@ -72,7 +72,7 @@ int nxflat_unload(FAR struct nxflat_loadinfo_s *loadinfo)
if (loadinfo->ispace)
{
- munmap((FAR void *)loadinfo->ispace, loadinfo->isize);
+ file_munmap((FAR void *)loadinfo->ispace, loadinfo->isize);
loadinfo->ispace = 0;
}
diff --git a/binfmt/nxflat.c b/binfmt/nxflat.c
index 3be1d4a..476a04a 100644
--- a/binfmt/nxflat.c
+++ b/binfmt/nxflat.c
@@ -123,9 +123,6 @@ static void nxflat_dumploadinfo(FAR struct nxflat_loadinfo_s *loadinfo)
binfo(" RELOCS:\n");
binfo(" relocstart: %08lx\n", loadinfo->relocstart);
binfo(" reloccount: %d\n", loadinfo->reloccount);
-
- binfo(" HANDLES:\n");
- binfo(" filfd: %d\n", loadinfo->filfd);
}
#else
# define nxflat_dumploadinfo(i)
diff --git a/include/nuttx/binfmt/elf.h b/include/nuttx/binfmt/elf.h
index a42c483..7d59f28 100644
--- a/include/nuttx/binfmt/elf.h
+++ b/include/nuttx/binfmt/elf.h
@@ -132,7 +132,7 @@ struct elf_loadinfo_s
uint16_t symtabidx; /* Symbol table section index */
uint16_t strtabidx; /* String table section index */
uint16_t buflen; /* size of iobuffer[] */
- int filfd; /* Descriptor for the file being loaded */
+ struct file file; /* Descriptor for the file being loaded */
};
/****************************************************************************
diff --git a/include/nuttx/binfmt/nxflat.h b/include/nuttx/binfmt/nxflat.h
index c901570..04ce553 100644
--- a/include/nuttx/binfmt/nxflat.h
+++ b/include/nuttx/binfmt/nxflat.h
@@ -95,7 +95,7 @@ struct nxflat_loadinfo_s
/* File descriptors */
- int filfd; /* Descriptor for the file being loaded */
+ struct file file; /* Descriptor for the file being loaded */
/* This is a copy of the NXFLAT header (still in network order) */