libs/modlib: avoid seeking in each reading
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
13bdaaec99
commit
310ba09ed7
@ -50,23 +50,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef ELF_DUMP_READDATA
|
||||
static inline void modlib_dumpreaddata(FAR char *buffer, size_t buflen)
|
||||
{
|
||||
FAR uint32_t *buf32 = (FAR uint32_t *)buffer;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
for (i = 0; i < buflen; i += 32)
|
||||
{
|
||||
syslog(LOG_DEBUG, "%04zx:", i);
|
||||
for (j = 0; j < 32; j += sizeof(uint32_t))
|
||||
{
|
||||
syslog(LOG_DEBUG, " %08" PRIx32, *buf32++);
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG, "\n");
|
||||
}
|
||||
}
|
||||
# define modlib_dumpreaddata(b,n) binfodumpbuffer("modlib_read",b,n)
|
||||
#else
|
||||
# define modlib_dumpreaddata(b,n)
|
||||
#endif
|
||||
@ -94,38 +78,39 @@ int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
|
||||
size_t nsize = readsize;
|
||||
ssize_t nbytes; /* Number of bytes read */
|
||||
off_t rpos; /* Position returned by lseek */
|
||||
int errval;
|
||||
|
||||
binfo("Read %zu bytes from offset %" PRIdOFF "\n", readsize, offset);
|
||||
|
||||
/* Loop until all of the requested data has been read. */
|
||||
|
||||
/* Seek to the read position */
|
||||
|
||||
rpos = _NX_SEEK(loadinfo->filfd, offset, SEEK_SET);
|
||||
if (rpos != offset)
|
||||
{
|
||||
errval = _NX_GETERRNO(rpos);
|
||||
berr("ERROR: Failed to seek to position %" PRIdOFF ": %d\n",
|
||||
offset, errval);
|
||||
return -errval;
|
||||
}
|
||||
|
||||
while (readsize > 0)
|
||||
{
|
||||
/* Seek to the next read position */
|
||||
|
||||
rpos = _NX_SEEK(loadinfo->filfd, offset, SEEK_SET);
|
||||
if (rpos != offset)
|
||||
{
|
||||
int errval = _NX_GETERRNO(rpos);
|
||||
berr("ERROR: Failed to seek to position %" PRIdOFF ": %d\n",
|
||||
offset, errval);
|
||||
return -errval;
|
||||
}
|
||||
|
||||
/* Read the file data at offset into the user buffer */
|
||||
|
||||
nbytes = _NX_READ(loadinfo->filfd,
|
||||
buffer + nsize - readsize, readsize);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
int errval = _NX_GETERRNO(nbytes);
|
||||
errval = _NX_GETERRNO(nbytes);
|
||||
|
||||
/* EINTR just means that we received a signal */
|
||||
|
||||
if (errval != EINTR)
|
||||
{
|
||||
berr("ERROR: Read from offset %" PRIdOFF " failed: %d\n",
|
||||
offset, errval);
|
||||
(off_t)(offset + nsize - readsize), errval);
|
||||
return -errval;
|
||||
}
|
||||
}
|
||||
@ -137,7 +122,6 @@ int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
|
||||
else
|
||||
{
|
||||
readsize -= nbytes;
|
||||
offset += nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user