提交 6314fde1 编写于 作者: M maguangyao 提交者: YOUR_NAME

feat: Nuttx adapt for mksh & toybox

Change-Id: Ia46512ceb07333b3c51ff57d41ef8993f1ca6495
上级 bf2478ca
......@@ -186,14 +186,12 @@ int do_opendir(const char *path, int oflags)
ret = VnodeLookup(path, &vp, 0);
if (ret < 0)
{
PRINT_ERR("Failed to find vnode %s\n", path);
VnodeDrop();
goto errout;
}
if (vp->type != VNODE_TYPE_DIR)
{
ret = -ENOTDIR;
PRINT_ERR("opendir (%s) failed, err=%d\n", path, ret);
VnodeDrop();
goto errout;
}
......
......@@ -701,13 +701,20 @@ int close_files(struct Vnode *vnode)
void files_refer(int fd)
{
struct file *filep = NULL;
FAR struct filelist *list = sched_getfiles();
if (!list || fd < 0 || fd >= CONFIG_NFILE_DESCRIPTORS)
{
return;
}
_files_semtake(list);
list->fl_files[fd].f_refcount++;
(void)fs_getfilep(fd, &filep);
if (filep != NULL)
{
filep->f_refcount++;
}
_files_semgive(list);
}
......
......@@ -121,6 +121,11 @@ int file_vfcntl(struct file *filep, int cmd, va_list ap)
* that refer to the same file.
*/
{
ret = (filep->f_oflags & O_CLOEXEC) ? FD_CLOEXEC : 0;
}
break;
case F_SETFD:
/* Set the file descriptor flags defined in <fcntl.h>, that are associated
* with fd, to the third argument, arg, taken as type int. If the
......@@ -129,7 +134,18 @@ int file_vfcntl(struct file *filep, int cmd, va_list ap)
* successful execution of one of the exec functions.
*/
err = ENOSYS;
{
int oflags = va_arg(ap, int);
if (oflags & FD_CLOEXEC)
{
filep->f_oflags |= O_CLOEXEC;
}
else
{
err = EPERM; /* Not support */
}
}
break;
case F_GETFL:
......
......@@ -37,9 +37,6 @@
* Included Files
****************************************************************************/
#include "vfs_config.h"
#include "sys/types.h"
#include "errno.h"
#include "unistd.h"
#include "console.h"
......@@ -76,6 +73,11 @@ static int fs_getfilep_normal(int fd, struct file **filep)
*filep = (struct file *)NULL;
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
{
fd = ConsoleUpdateFd();
}
if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
{
return -EBADF;
......
......@@ -99,8 +99,8 @@ static int oflag_convert_mode(int oflags)
int get_path_from_fd(int fd, char **path)
{
struct file *file = NULL;
char *copypath = NULL;
struct file *file = NULL;
char *copypath = NULL;
if (fd == AT_FDCWD)
{
......@@ -124,23 +124,8 @@ int get_path_from_fd(int fd, char **path)
return VFS_ERROR;
}
char *endptr = copypath + strlen(copypath)-1;//the ptr before '\0'
/* strip out the file name, for example:/usr/lib/xx.so, final get /usr/lib/ */
while (endptr > copypath)
{
if(*endptr == '/' && endptr > copypath)
{
*(endptr + 1) = '\0';
*path = copypath;
return OK;
}
endptr--;
}
free(copypath);
return -ENOENT;
*path = copypath;
return OK;
}
static int do_creat(struct Vnode **node, char *fullpath, mode_t mode)
......
......@@ -110,7 +110,6 @@ ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count);
*/
extern int get_path_from_fd(int fd, char **path);
extern int get_path_from_dirfd(int fd, char **path);
bool get_bit(int i);
/****************************************************************************
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册