hostfs:support SEEK_CUR
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
parent
d8f316b998
commit
709301cbfd
@ -185,7 +185,7 @@ ssize_t host_write(int fd, const void *buf, size_t count)
|
|||||||
return ret < 0 ? ret : count - ret;
|
return ret < 0 ? ret : count - ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t host_lseek(int fd, off_t offset, int whence)
|
off_t host_lseek(int fd, off_t pos, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
off_t ret = -ENOSYS;
|
off_t ret = -ENOSYS;
|
||||||
|
|
||||||
@ -198,6 +198,11 @@ off_t host_lseek(int fd, off_t offset, int whence)
|
|||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (whence == SEEK_CUR)
|
||||||
|
{
|
||||||
|
offset += pos;
|
||||||
|
whence = SEEK_SET;
|
||||||
|
}
|
||||||
|
|
||||||
if (whence == SEEK_SET)
|
if (whence == SEEK_SET)
|
||||||
{
|
{
|
||||||
|
@ -185,7 +185,7 @@ ssize_t host_write(int fd, const void *buf, size_t count)
|
|||||||
return ret < 0 ? ret : count - ret;
|
return ret < 0 ? ret : count - ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t host_lseek(int fd, off_t offset, int whence)
|
off_t host_lseek(int fd, off_t pos, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
off_t ret = -ENOSYS;
|
off_t ret = -ENOSYS;
|
||||||
|
|
||||||
@ -198,6 +198,11 @@ off_t host_lseek(int fd, off_t offset, int whence)
|
|||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (whence == SEEK_CUR)
|
||||||
|
{
|
||||||
|
offset += pos;
|
||||||
|
whence = SEEK_SET;
|
||||||
|
}
|
||||||
|
|
||||||
if (whence == SEEK_SET)
|
if (whence == SEEK_SET)
|
||||||
{
|
{
|
||||||
|
@ -185,7 +185,7 @@ ssize_t host_write(int fd, const void *buf, size_t count)
|
|||||||
return ret < 0 ? ret : count - ret;
|
return ret < 0 ? ret : count - ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t host_lseek(int fd, off_t offset, int whence)
|
off_t host_lseek(int fd, off_t pos, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
off_t ret = -ENOSYS;
|
off_t ret = -ENOSYS;
|
||||||
|
|
||||||
@ -198,6 +198,11 @@ off_t host_lseek(int fd, off_t offset, int whence)
|
|||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (whence == SEEK_CUR)
|
||||||
|
{
|
||||||
|
offset += pos;
|
||||||
|
whence = SEEK_SET;
|
||||||
|
}
|
||||||
|
|
||||||
if (whence == SEEK_SET)
|
if (whence == SEEK_SET)
|
||||||
{
|
{
|
||||||
|
@ -255,7 +255,8 @@ nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
|
|||||||
* Name: host_lseek
|
* Name: host_lseek
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
|
nuttx_off_t host_lseek(int fd, nuttx_off_t pos, nuttx_off_t offset,
|
||||||
|
int whence)
|
||||||
{
|
{
|
||||||
/* Just call the lseek routine */
|
/* Just call the lseek routine */
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ ssize_t up_show_cpuinfo(char *buf, size_t buf_size, off_t file_off)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = host_lseek(fd, file_off, SEEK_SET);
|
ret = host_lseek(fd, 0, file_off, SEEK_SET);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
host_close(fd);
|
host_close(fd);
|
||||||
|
@ -200,7 +200,8 @@ nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
|
|||||||
* Name: host_lseek
|
* Name: host_lseek
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
|
nuttx_off_t host_lseek(int fd, nuttx_off_t pos, nuttx_off_t offset,
|
||||||
|
int whence)
|
||||||
{
|
{
|
||||||
/* Just call the lseek routine */
|
/* Just call the lseek routine */
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ ssize_t host_write(int fd, const void *buf, size_t count)
|
|||||||
return host_call(SIMCALL_SYS_WRITE, fd, (int)buf, count);
|
return host_call(SIMCALL_SYS_WRITE, fd, (int)buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t host_lseek(int fd, off_t offset, int whence)
|
off_t host_lseek(int fd, off_t pos, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
return host_call(SIMCALL_SYS_LSEEK, fd, offset, whence);
|
return host_call(SIMCALL_SYS_LSEEK, fd, offset, whence);
|
||||||
}
|
}
|
||||||
@ -155,9 +155,9 @@ int host_fstat(int fd, struct stat *buf)
|
|||||||
* hostfs_lock provides enough serialization.
|
* hostfs_lock provides enough serialization.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
off_t saved_off = host_lseek(fd, 0, SEEK_CUR);
|
off_t saved_off = host_lseek(fd, 0, 0, SEEK_CUR);
|
||||||
off_t size = host_lseek(fd, 0, SEEK_END);
|
off_t size = host_lseek(fd, 0, 0, SEEK_END);
|
||||||
host_lseek(fd, saved_off, SEEK_SET);
|
host_lseek(fd, 0, saved_off, SEEK_SET);
|
||||||
|
|
||||||
memset(buf, 0, sizeof(*buf));
|
memset(buf, 0, sizeof(*buf));
|
||||||
buf->st_mode = S_IFREG | 0777;
|
buf->st_mode = S_IFREG | 0777;
|
||||||
|
@ -296,7 +296,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
|
|
||||||
if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY))
|
if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY))
|
||||||
{
|
{
|
||||||
ret = host_lseek(hf->fd, 0, SEEK_END);
|
ret = host_lseek(hf->fd, 0, 0, SEEK_END);
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
filep->f_pos = ret;
|
filep->f_pos = ret;
|
||||||
@ -557,7 +557,7 @@ static off_t hostfs_seek(FAR struct file *filep, off_t offset, int whence)
|
|||||||
|
|
||||||
/* Call our internal routine to perform the seek */
|
/* Call our internal routine to perform the seek */
|
||||||
|
|
||||||
ret = host_lseek(hf->fd, offset, whence);
|
ret = host_lseek(hf->fd, filep->f_pos, offset, whence);
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
filep->f_pos = ret;
|
filep->f_pos = ret;
|
||||||
|
@ -186,7 +186,8 @@ int host_open(const char *pathname, int flags, nuttx_mode_t mode);
|
|||||||
int host_close(int fd);
|
int host_close(int fd);
|
||||||
nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count);
|
nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count);
|
||||||
nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count);
|
nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count);
|
||||||
nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence);
|
nuttx_off_t host_lseek(int fd, nuttx_off_t pos, nuttx_off_t offset,
|
||||||
|
int whence);
|
||||||
int host_ioctl(int fd, int request, unsigned long arg);
|
int host_ioctl(int fd, int request, unsigned long arg);
|
||||||
void host_sync(int fd);
|
void host_sync(int fd);
|
||||||
int host_dup(int fd);
|
int host_dup(int fd);
|
||||||
@ -211,7 +212,7 @@ int host_open(const char *pathname, int flags, int mode);
|
|||||||
int host_close(int fd);
|
int host_close(int fd);
|
||||||
ssize_t host_read(int fd, void *buf, size_t count);
|
ssize_t host_read(int fd, void *buf, size_t count);
|
||||||
ssize_t host_write(int fd, const void *buf, size_t count);
|
ssize_t host_write(int fd, const void *buf, size_t count);
|
||||||
off_t host_lseek(int fd, off_t offset, int whence);
|
off_t host_lseek(int fd, off_t pos, off_t offset, int whence);
|
||||||
int host_ioctl(int fd, int request, unsigned long arg);
|
int host_ioctl(int fd, int request, unsigned long arg);
|
||||||
void host_sync(int fd);
|
void host_sync(int fd);
|
||||||
int host_dup(int fd);
|
int host_dup(int fd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user