fs/vfs: file_write() and file_pwrite() are internal OS interfaces and should not report errors via the errno
This commit is contained in:
parent
e761b80ea7
commit
7b7ca87941
@ -155,6 +155,13 @@ static void aio_write_worker(FAR void *arg)
|
|||||||
aiocbp->aio_nbytes,
|
aiocbp->aio_nbytes,
|
||||||
aiocbp->aio_offset);
|
aiocbp->aio_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* errno is not set */
|
||||||
|
|
||||||
|
if (nwritten < 0)
|
||||||
|
{
|
||||||
|
ferr("ERROR: file_write/file_pwrite failed: %d\n", nwritten);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(AIO_HAVE_FILEP) && defined(AIO_HAVE_PSOCK)
|
#if defined(AIO_HAVE_FILEP) && defined(AIO_HAVE_PSOCK)
|
||||||
@ -172,22 +179,21 @@ static void aio_write_worker(FAR void *arg)
|
|||||||
nwritten = psock_send(aioc->u.aioc_psock,
|
nwritten = psock_send(aioc->u.aioc_psock,
|
||||||
(FAR const void *)aiocbp->aio_buf,
|
(FAR const void *)aiocbp->aio_buf,
|
||||||
aiocbp->aio_nbytes, 0);
|
aiocbp->aio_nbytes, 0);
|
||||||
|
/* errno is set */
|
||||||
|
|
||||||
|
if (nwritten < 0)
|
||||||
|
{
|
||||||
|
int errcode = get_errno();
|
||||||
|
ferr("ERROR: psock_send failed: %d\n", errcode);
|
||||||
|
DEBUGASSERT(errcode > 0);
|
||||||
|
nwritten = -errcode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Check the result of the write */
|
/* Save the result of the write */
|
||||||
|
|
||||||
if (nwritten < 0)
|
aiocbp->aio_result = nwritten;
|
||||||
{
|
|
||||||
int errcode = get_errno();
|
|
||||||
ferr("ERROR: write/pwrite failed: %d\n", errcode);
|
|
||||||
DEBUGASSERT(errcode > 0);
|
|
||||||
aiocbp->aio_result = -errcode;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
aiocbp->aio_result = nwritten;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef AIO_HAVE_FILEP
|
#ifdef AIO_HAVE_FILEP
|
||||||
errout:
|
errout:
|
||||||
|
@ -66,38 +66,32 @@ ssize_t file_pwrite(FAR struct file *filep, FAR const void *buf,
|
|||||||
off_t savepos;
|
off_t savepos;
|
||||||
off_t pos;
|
off_t pos;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
int errcode = 0;
|
|
||||||
|
|
||||||
/* Perform the seek to the current position. This will not move the
|
/* Perform the seek to the current position. This will not move the
|
||||||
* file pointer, but will return its current setting
|
* file pointer, but will return its current setting
|
||||||
*/
|
*/
|
||||||
|
|
||||||
savepos = file_seek(filep, 0, SEEK_CUR);
|
savepos = file_seek(filep, 0, SEEK_CUR);
|
||||||
if (savepos == (off_t)-1)
|
if (savepos < 0)
|
||||||
{
|
{
|
||||||
/* file_seek might fail if this if the media is not seekable */
|
/* file_seek might fail if this if the media is not seekable */
|
||||||
|
|
||||||
return ERROR;
|
return (ssize_t)savepos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Then seek to the correct position in the file */
|
/* Then seek to the correct position in the file */
|
||||||
|
|
||||||
pos = file_seek(filep, offset, SEEK_SET);
|
pos = file_seek(filep, offset, SEEK_SET);
|
||||||
if (pos == (off_t)-1)
|
if (pos < 0)
|
||||||
{
|
{
|
||||||
/* This might fail is the offset is beyond the end of file */
|
/* This might fail is the offset is beyond the end of file */
|
||||||
|
|
||||||
return ERROR;
|
return (ssize_t)pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Then perform the write operation */
|
/* Then perform the write operation */
|
||||||
|
|
||||||
ret = file_write(filep, buf, nbytes);
|
ret = file_write(filep, buf, nbytes);
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
errcode = get_errno();
|
|
||||||
ret = ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Restore the file position */
|
/* Restore the file position */
|
||||||
|
|
||||||
@ -106,13 +100,7 @@ ssize_t file_pwrite(FAR struct file *filep, FAR const void *buf,
|
|||||||
{
|
{
|
||||||
/* This really should not fail */
|
/* This really should not fail */
|
||||||
|
|
||||||
errcode = -pos;
|
ret = (ssize_t)pos;
|
||||||
ret = ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errcode != 0)
|
|
||||||
{
|
|
||||||
set_errno(errcode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -168,6 +156,11 @@ ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset)
|
|||||||
/* Let file_pread do the real work */
|
/* Let file_pread do the real work */
|
||||||
|
|
||||||
ret = file_pwrite(filep, buf, nbytes, offset);
|
ret = file_pwrite(filep, buf, nbytes, offset);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
set_errno((int)-ret);
|
||||||
|
ret = ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)enter_cancellation_point();
|
(void)enter_cancellation_point();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* fs/vfs/fs_write.c
|
* fs/vfs/fs_write.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2012-2014, 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2012-2014, 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -71,15 +71,12 @@
|
|||||||
ssize_t file_write(FAR struct file *filep, FAR const void *buf, size_t nbytes)
|
ssize_t file_write(FAR struct file *filep, FAR const void *buf, size_t nbytes)
|
||||||
{
|
{
|
||||||
FAR struct inode *inode;
|
FAR struct inode *inode;
|
||||||
ssize_t ret;
|
|
||||||
int errcode;
|
|
||||||
|
|
||||||
/* Was this file opened for write access? */
|
/* Was this file opened for write access? */
|
||||||
|
|
||||||
if ((filep->f_oflags & O_WROK) == 0)
|
if ((filep->f_oflags & O_WROK) == 0)
|
||||||
{
|
{
|
||||||
errcode = EBADF;
|
return -EBADF;
|
||||||
goto errout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is a driver registered? Does it support the write method? */
|
/* Is a driver registered? Does it support the write method? */
|
||||||
@ -87,24 +84,12 @@ ssize_t file_write(FAR struct file *filep, FAR const void *buf, size_t nbytes)
|
|||||||
inode = filep->f_inode;
|
inode = filep->f_inode;
|
||||||
if (!inode || !inode->u.i_ops || !inode->u.i_ops->write)
|
if (!inode || !inode->u.i_ops || !inode->u.i_ops->write)
|
||||||
{
|
{
|
||||||
errcode = EBADF;
|
return -EBADF;
|
||||||
goto errout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Yes, then let the driver perform the write */
|
/* Yes, then let the driver perform the write */
|
||||||
|
|
||||||
ret = inode->u.i_ops->write(filep, buf, nbytes);
|
return inode->u.i_ops->write(filep, buf, nbytes);
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
errcode = -ret;
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
errout:
|
|
||||||
set_errno(errcode);
|
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -208,6 +193,11 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ret = file_write(filep, buf, nbytes);
|
ret = file_write(filep, buf, nbytes);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
set_errno((int)-ret);
|
||||||
|
ret = ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user