diff --git a/fs/dirent/fs_opendir.c b/fs/dirent/fs_opendir.c index 3f6c12cd6735c45a916bf0e355c1535d66723f72..dfa474d2708795c17cf36705c2051d24774e3fec 100644 --- a/fs/dirent/fs_opendir.c +++ b/fs/dirent/fs_opendir.c @@ -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; } diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index 8d4179b62d4aee40be2992892891e64d35319b78..03966622270eb17b9e59dc334081bb052924cea5 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -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); } diff --git a/fs/vfs/fs_fcntl.c b/fs/vfs/fs_fcntl.c index a7d753b220976d96b40f1652aa680c4bcbaab3bb..9b6c5a74cb9fdb1b3266fd972db0aaf1a26a7279 100644 --- a/fs/vfs/fs_fcntl.c +++ b/fs/vfs/fs_fcntl.c @@ -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 , 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: diff --git a/fs/vfs/fs_getfilep.c b/fs/vfs/fs_getfilep.c index 7e5c33788c991ebf08e0daaca8d160dba11e3a94..c0c6cb9e813ce4b1c853067a45a8e83b7140ff2b 100644 --- a/fs/vfs/fs_getfilep.c +++ b/fs/vfs/fs_getfilep.c @@ -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; diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index d637499e385dab13583d438dfb4d2c3333545208..e2bc2b46ae56f6cf7430a8a30497fa6b6b857ac9 100755 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -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) diff --git a/include/nuttx/fs/file.h b/include/nuttx/fs/file.h index a9e9b9f58c088b3c90919df47f379b857957ccd4..dfbb17abba2c4940baebf5ec0ecf8d35dd090c42 100644 --- a/include/nuttx/fs/file.h +++ b/include/nuttx/fs/file.h @@ -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); /****************************************************************************