Fix read() return value for the case of permissions problem
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4545 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
466b008cb5
commit
a4e8ceb39f
|
@ -149,7 +149,8 @@ int nsh_consolemain(int argc, char *argv[])
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "readline", NSH_ERRNO_OF(-ret));
|
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_consolemain",
|
||||||
|
"readline", NSH_ERRNO_OF(-ret));
|
||||||
nsh_exit(&pstate->cn_vtbl, 1);
|
nsh_exit(&pstate->cn_vtbl, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,8 @@ int nsh_telnetmain(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "fgets", NSH_ERRNO);
|
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_telnetmain",
|
||||||
|
"fgets", NSH_ERRNO);
|
||||||
nsh_exit(&pstate->cn_vtbl, 1);
|
nsh_exit(&pstate->cn_vtbl, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ static inline void readline_consolewrite(int outfd, FAR const char *buffer, size
|
||||||
*
|
*
|
||||||
* Returned values:
|
* Returned values:
|
||||||
* On success, the (positive) number of bytes transferred is returned.
|
* On success, the (positive) number of bytes transferred is returned.
|
||||||
* A length of zero would indicated an end of file condition. An failure,
|
* A length of zero would indicate an end of file condition. On failure,
|
||||||
* a negated errno value is returned.
|
* a negated errno value is returned.
|
||||||
*
|
*
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* fs_read.c
|
* fs_read.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* 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
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -63,35 +63,39 @@ static inline ssize_t file_read(int fd, FAR void *buf, size_t nbytes)
|
||||||
list = sched_getfiles();
|
list = sched_getfiles();
|
||||||
if (!list)
|
if (!list)
|
||||||
{
|
{
|
||||||
errno = EMFILE;
|
/* Failed to get the file list */
|
||||||
return ERROR;
|
|
||||||
|
ret = -EMFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Were we given a valid file descriptor? */
|
/* Were we given a valid file descriptor? */
|
||||||
|
|
||||||
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
|
else if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
|
||||||
{
|
{
|
||||||
FAR struct file *this_file = &list->fl_files[fd];
|
FAR struct file *this_file = &list->fl_files[fd];
|
||||||
|
FAR struct inode *inode = this_file->f_inode;
|
||||||
|
|
||||||
/* Was this file opened for read access? */
|
/* Yes.. Was this file opened for read access? */
|
||||||
|
|
||||||
if ((this_file->f_oflags & O_RDOK) != 0)
|
if ((this_file->f_oflags & O_RDOK) == 0)
|
||||||
{
|
{
|
||||||
struct inode *inode = this_file->f_inode;
|
/* No.. File is not read-able */
|
||||||
|
|
||||||
/* Is a driver or mountpoint registered? If so, does it support
|
ret = -EACCES;
|
||||||
* the read method?
|
}
|
||||||
|
|
||||||
|
/* Is a driver or mountpoint registered? If so, does it support
|
||||||
|
* the read method?
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (inode && inode->u.i_ops && inode->u.i_ops->read)
|
||||||
|
{
|
||||||
|
/* Yes.. then let it perform the read. NOTE that for the case
|
||||||
|
* of the mountpoint, we depend on the read methods bing
|
||||||
|
* identical in signature and position in the operations vtable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (inode && inode->u.i_ops && inode->u.i_ops->read)
|
ret = (int)inode->u.i_ops->read(this_file, (char*)buf, (size_t)nbytes);
|
||||||
{
|
|
||||||
/* Yes, then let it perform the read. NOTE that for the case
|
|
||||||
* of the mountpoint, we depend on the read methods bing
|
|
||||||
* identical in signature and position in the operations vtable.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = (int)inode->u.i_ops->read(this_file, (char*)buf, (size_t)nbytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +103,7 @@ static inline ssize_t file_read(int fd, FAR void *buf, size_t nbytes)
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errno = -ret;
|
set_errno(-ret);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ int sched_setupidlefiles(FAR _TCB *tcb)
|
||||||
* it and got some file descriptor other than 0.
|
* it and got some file descriptor other than 0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (fd >- 0)
|
if (fd > 0)
|
||||||
{
|
{
|
||||||
slldbg("Open /dev/console fd: %d\n", fd);
|
slldbg("Open /dev/console fd: %d\n", fd);
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
|
|
Loading…
Reference in New Issue