summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2023-07-20 15:18:38 +1000
committerChris Johns <chrisj@rtems.org>2023-07-21 14:56:02 +1000
commit65913f4b3bc6589c4534daf4a7c16f3c2c938aaa (patch)
tree248dfa3ed231131aeae02a828e2bc33006a49be7
parentfreenbsd/vfs: VFS attributes need to have the same size mode_t variable (diff)
downloadrtems-libbsd-65913f4b3bc6589c4534daf4a7c16f3c2c938aaa.tar.bz2
syscall/open: Reference the path info directory vnode
The kernel open call requires a path so to open a file we need to set the current directory to the parent vnode. If the open mode is create the path info vnode is the directory to perform the open create in. Using the parent node creates the file in wrong path. Updates #4723
-rw-r--r--rtemsbsd/rtems/rtems-bsd-syscall-api.c24
-rw-r--r--testsuite/nfs01/test_main.c81
2 files changed, 71 insertions, 34 deletions
diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 76fc8ad7..142e4faf 100644
--- a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
+++ b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
@@ -931,9 +931,18 @@ rtems_bsd_sysgen_open_node(
} else {
rtems_filesystem_location_info_t *rootloc =
&iop->pathinfo.mt_entry->mt_fs_root->location;
+ /*
+ * We need the parent directory so open can find the
+ * entry. If we are creating the file the pathinfo
+ * vnode entry is the directory open uses to create
+ * the file in.
+ */
cdir = rtems_bsd_libio_loc_to_vnode_dir(&iop->pathinfo);
+ if (cdir == NULL || creat) {
+ cdir = rtems_bsd_libio_loc_to_vnode(&iop->pathinfo);
+ }
if (fdp->fd_cdir == NULL) {
- cdir = rtems_bsd_libio_loc_to_vnode(rootloc);
+ cdir = rtems_bsd_libio_loc_to_vnode_dir(rootloc);
} else if (rtems_bsd_libio_loc_to_vnode(&iop->pathinfo) ==
rtems_bsd_libio_loc_to_vnode(rootloc)) {
/*
@@ -958,11 +967,14 @@ rtems_bsd_sysgen_open_node(
FILEDESC_XUNLOCK(fdp);
if (RTEMS_BSD_SYSCALL_TRACE) {
- printf("bsd: sys: open: path=%s opath=%s vn=%p cwd=%p"
- " flags=%08x mode=%08x isdir=%s\n",
- path, opath,
- creat ? NULL : rtems_bsd_libio_loc_to_vnode(&iop->pathinfo),
- fdp->fd_cdir, oflag, mode, isdir ? "yes" : "no");
+ struct vnode* _vn = rtems_bsd_libio_loc_to_vnode(&iop->pathinfo);
+ struct vnode* _dvn = rtems_bsd_libio_loc_to_vnode_dir(&iop->pathinfo);
+ printf("bsd: sys: open: path=%s opath=%s vn=%p (%c) dvn=%p (%c) cwd=%p"
+ " flags=%08x mode=%o isdir=%s\n",
+ path, opath,
+ _vn, creat ? 'c' : _vn ? (_vn->v_type == VDIR ? 'd' : 'r') : 'n',
+ _dvn, _dvn ? (_dvn->v_type == VDIR ? 'd' : 'r') : 'n',
+ fdp->fd_cdir, oflag, mode, isdir ? "yes" : "no");
}
VREF(fdp->fd_cdir);
diff --git a/testsuite/nfs01/test_main.c b/testsuite/nfs01/test_main.c
index cfa163e1..cdcbb1cd 100644
--- a/testsuite/nfs01/test_main.c
+++ b/testsuite/nfs01/test_main.c
@@ -46,18 +46,27 @@
#include <rtems/console.h>
#include <rtems/shell.h>
-#include <rtems/telnetd.h>
#include <librtemsNfs.h>
#include <rtems/bsd/test/network-config.h>
+#define END_TEST_IN_SHELL 0
+
#define TEST_NAME "LIBBSD NFS 1"
#define TEST_STATE_USER_INPUT 1
#define TEST_WAIT_FOR_LINK NET_CFG_INTERFACE_0
static const char *test_top = "test-nfs01";
+#define rtems_test_assert(__exp) \
+ do { \
+ if (!(__exp)) { \
+ printf( "%s: %d %s\n", __FILE__, __LINE__, #__exp ); \
+ assert(1 == 0); \
+ } \
+ } while (0)
+
#define rtems_test_errno_assert(__exp) \
do { \
if (!(__exp)) { \
@@ -329,9 +338,45 @@ test_path_eval(const char *base, int depth)
}
static void
+test_path_file_copy(const char *base, int depth)
+{
+ char path[MAXPATHLEN];
+ struct stat sb;
+ FILE* f;
+ int l;
+
+ printf("test path eval\n");
+
+ test_setup(base);
+
+ memset(path, 0, sizeof(path));
+
+ for (l = 1; l <= depth; ++l) {
+ char* p = path + strlen(path);
+ if (l > 1) {
+ *p++ = '/';
+ }
+ snprintf(p, sizeof(path), "%d", l);
+ printf("test: nfs: mkdir: %s\n", path);
+ rtems_test_errno_assert(mkdir(path, 0777) == 0);
+ }
+
+ strlcat(path, "/test-file.txt", sizeof(path));
+ printf("Create file %s\n", path);
+ rtems_test_errno_assert((f = fopen(path, "w")) != NULL);
+ rtems_test_errno_assert(fprintf(f, "The contents of %s\nNFS test\n", path) > 0);
+ rtems_test_errno_assert(fclose(f) == 0);
+ printf("Checking %s has been copied\n", path);
+ rtems_test_errno_assert(stat(path, &sb) == 0);
+
+ test_cleanup(base);
+}
+
+static void
test_nfs(const char *base)
{
test_path_eval(base, 5);
+ test_path_file_copy(base, 3);
#if NFS_TREE_WALK
test_printer_data pd;
memset(&pd, 0, sizeof(pd));
@@ -340,30 +385,6 @@ test_nfs(const char *base)
}
static void
-telnet_shell(char *name, void *arg)
-{
- rtems_shell_env_t env;
-
- rtems_shell_dup_current_env(&env);
-
- env.devname = name;
- env.taskname = "TLNT";
- env.login_check = NULL;
- env.forever = false;
-
- rtems_shell_main_loop(&env);
-}
-
-rtems_telnetd_config_table rtems_telnetd_config = {
- .command = telnet_shell,
- .arg = NULL,
- .priority = 0,
- .stack_size = 0,
- .login_check = NULL,
- .keep_stdio = false
-};
-
-static void
test_main(void)
{
const char remote_target[] = NET_CFG_NFS_MOUNT_PATH;
@@ -373,8 +394,6 @@ test_main(void)
int retries = 0;
int rv;
- assert(rtems_telnetd_initialize() == RTEMS_SUCCESSFUL);
-
if (strlen(options) != 0) {
mount_options = options;
}
@@ -399,11 +418,17 @@ test_main(void)
test_nfs(mount_point);
+#if END_TEST_IN_SHELL
rtems_task_exit();
+#else
+ exit(0);
+#endif
}
#define CONFIGURE_SHELL_COMMANDS_ALL
-#define DEFAULT_NETWORK_SHELL
+#if END_TEST_IN_SHELL
+ #define DEFAULT_NETWORK_SHELL */
+#endif
#define CONFIGURE_FILESYSTEM_NFS