xiaoxiang781216 commented on code in PR #20820:
URL: https://github.com/apache/nuttx/pull/20820#discussion_r4359889437
##########
fs/vfs/fs_write.c:
##########
@@ -333,11 +405,23 @@ ssize_t nx_writev(int fd, FAR const struct iovec *iov,
int iovcnt)
ssize_t nx_write(int fd, FAR const void *buf, size_t nbytes)
{
- struct iovec iov;
+ FAR struct file *filep;
+ ssize_t ret;
- iov.iov_base = (void *)buf;
- iov.iov_len = nbytes;
- return nx_writev(fd, &iov, 1);
+ /* First, get the file structure. Note that on failure,
+ * file_get() will return the errno.
+ */
+
+ ret = (ssize_t)file_get(fd, &filep);
Review Comment:
remove the cast
##########
fs/vfs/fs_write.c:
##########
Review Comment:
```suggestion
else
if (inode->u.i_ops->write)
#endif
```
and remove line 211-215
##########
fs/vfs/fs_read.c:
##########
@@ -233,6 +235,12 @@ ssize_t file_readv(FAR struct file *filep,
{
ret = file_readv_compat(filep, iov, iovcnt);
}
+#else
Review Comment:
ditto
##########
fs/vfs/fs_read.c:
##########
@@ -274,12 +282,85 @@ ssize_t file_readv(FAR struct file *filep,
ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes)
{
+#ifdef CONFIG_FS_UIO
struct iovec iov;
iov.iov_base = buf;
iov.iov_len = nbytes;
return file_readv(filep, &iov, 1);
+#else
+ FAR struct inode *inode;
+ ssize_t ret;
+
+ DEBUGASSERT(filep);
+
+ /* Was this file opened for read access? */
+
+ if ((filep->f_oflags & O_ACCMODE) == O_WRONLY)
+ {
+ /* No.. File is not read-able */
+
+ return -EACCES;
+ }
+
+ if (nbytes == 0)
+ {
+ return 0;
+ }
+
+ if (nbytes > SSIZE_MAX)
+ {
+ return -EINVAL;
+ }
+
+ /* -------------------- DO NOT REMOVE --------------------
+ * Only for kernel builds with CONFIG_ARCH_TEXT_VBASE == 0.
+ * In this case we have to allow the NULL buffer otherwise
+ * kernel builds will fail to load elf binaries found at 0.
+ */
+
+#if !defined(CONFIG_BUILD_KERNEL) || CONFIG_ARCH_TEXT_VBASE != 0
+ if (buf == NULL)
+ {
+ return -EFAULT;
+ }
+#endif
+
+ inode = filep->f_inode;
+ ret = -EBADF;
Review Comment:
ditto
##########
fs/vfs/fs_read.c:
##########
@@ -348,11 +429,23 @@ ssize_t nx_readv(int fd, FAR const struct iovec *iov, int
iovcnt)
ssize_t nx_read(int fd, FAR void *buf, size_t nbytes)
{
- struct iovec iov;
+ FAR struct file *filep;
+ ssize_t ret;
- iov.iov_base = buf;
- iov.iov_len = nbytes;
- return nx_readv(fd, &iov, 1);
+ /* First, get the file structure. Note that on failure,
+ * file_get() will return the errno.
+ */
+
+ ret = (ssize_t)file_get(fd, &filep);
Review Comment:
remove the cast
##########
fs/vfs/fs_write.c:
##########
@@ -249,12 +257,76 @@ ssize_t file_writev(FAR struct file *filep,
ssize_t file_write(FAR struct file *filep, FAR const void *buf,
size_t nbytes)
{
+#ifdef CONFIG_FS_UIO
struct iovec iov;
iov.iov_base = (FAR void *)buf;
iov.iov_len = nbytes;
return file_writev(filep, &iov, 1);
+#else
+ FAR struct inode *inode;
+ ssize_t ret;
+
+ DEBUGASSERT(filep);
+
+ /* Was this file opened for write access? */
+
+ if ((filep->f_oflags & O_ACCMODE) == O_RDONLY)
+ {
+ /* No.. File is not writable */
+
+ return -EACCES;
+ }
+
+ if (nbytes == 0)
+ {
+ return 0;
+ }
+
+ if (nbytes > SSIZE_MAX)
+ {
+ return -EINVAL;
+ }
+
+ if (buf == NULL)
+ {
+ return -EFAULT;
+ }
+
+ inode = filep->f_inode;
+ ret = -EBADF;
Review Comment:
merge to line 268-269
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]