提交 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) ...@@ -186,14 +186,12 @@ int do_opendir(const char *path, int oflags)
ret = VnodeLookup(path, &vp, 0); ret = VnodeLookup(path, &vp, 0);
if (ret < 0) if (ret < 0)
{ {
PRINT_ERR("Failed to find vnode %s\n", path);
VnodeDrop(); VnodeDrop();
goto errout; goto errout;
} }
if (vp->type != VNODE_TYPE_DIR) if (vp->type != VNODE_TYPE_DIR)
{ {
ret = -ENOTDIR; ret = -ENOTDIR;
PRINT_ERR("opendir (%s) failed, err=%d\n", path, ret);
VnodeDrop(); VnodeDrop();
goto errout; goto errout;
} }
......
...@@ -701,13 +701,20 @@ int close_files(struct Vnode *vnode) ...@@ -701,13 +701,20 @@ int close_files(struct Vnode *vnode)
void files_refer(int fd) void files_refer(int fd)
{ {
struct file *filep = NULL;
FAR struct filelist *list = sched_getfiles(); FAR struct filelist *list = sched_getfiles();
if (!list || fd < 0 || fd >= CONFIG_NFILE_DESCRIPTORS) if (!list || fd < 0 || fd >= CONFIG_NFILE_DESCRIPTORS)
{ {
return; return;
} }
_files_semtake(list); _files_semtake(list);
list->fl_files[fd].f_refcount++; (void)fs_getfilep(fd, &filep);
if (filep != NULL)
{
filep->f_refcount++;
}
_files_semgive(list); _files_semgive(list);
} }
......
...@@ -121,6 +121,11 @@ int file_vfcntl(struct file *filep, int cmd, va_list ap) ...@@ -121,6 +121,11 @@ int file_vfcntl(struct file *filep, int cmd, va_list ap)
* that refer to the same file. * that refer to the same file.
*/ */
{
ret = (filep->f_oflags & O_CLOEXEC) ? FD_CLOEXEC : 0;
}
break;
case F_SETFD: case F_SETFD:
/* Set the file descriptor flags defined in <fcntl.h>, that are associated /* 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 * 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) ...@@ -129,7 +134,18 @@ int file_vfcntl(struct file *filep, int cmd, va_list ap)
* successful execution of one of the exec functions. * 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; break;
case F_GETFL: case F_GETFL:
......
...@@ -37,9 +37,6 @@ ...@@ -37,9 +37,6 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include "vfs_config.h"
#include "sys/types.h"
#include "errno.h" #include "errno.h"
#include "unistd.h" #include "unistd.h"
#include "console.h" #include "console.h"
...@@ -76,6 +73,11 @@ static int fs_getfilep_normal(int fd, struct file **filep) ...@@ -76,6 +73,11 @@ static int fs_getfilep_normal(int fd, struct file **filep)
*filep = (struct file *)NULL; *filep = (struct file *)NULL;
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
{
fd = ConsoleUpdateFd();
}
if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS) if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
{ {
return -EBADF; return -EBADF;
......
...@@ -124,23 +124,8 @@ int get_path_from_fd(int fd, char **path) ...@@ -124,23 +124,8 @@ int get_path_from_fd(int fd, char **path)
return VFS_ERROR; 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; *path = copypath;
return OK; return OK;
}
endptr--;
}
free(copypath);
return -ENOENT;
} }
static int do_creat(struct Vnode **node, char *fullpath, mode_t mode) 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); ...@@ -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_fd(int fd, char **path);
extern int get_path_from_dirfd(int fd, char **path);
bool get_bit(int i); bool get_bit(int i);
/**************************************************************************** /****************************************************************************
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册