Re: [PATCH rtems-libbsd/6-freebsd-12 2/3] syscall/open: Reference the path info directory vnode

2023-07-20 Thread Cedric Berger

On 20.07.23 09:52, Chris Johns wrote:

On 20/7/2023 5:24 pm, Cedric Berger wrote:

On 20.07.23 07:45, chr...@rtems.org wrote:


From: Chris Johns 

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
---
   rtemsbsd/rtems/rtems-bsd-syscall-api.c | 24 ++---
   testsuite/nfs01/test_main.c    | 75 --
   2 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 76fc8ad7..cfceb768 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 =
   >pathinfo.mt_entry->mt_fs_root->location;
+    /*
+ * We need the parent directory so open can find the
+ * the entry. If we are creating the file the pathinfo

the the

Yeah and thanks for the review. I think this should be:

/*
  * We need the parent directory so open can find the
  * entry. If we are creating the file the pathinfo
  * vnode entry is the directory to open uses to create
  * the file in.
  */


Yes,

Cedric


___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH rtems-libbsd/6-freebsd-12 2/3] syscall/open: Reference the path info directory vnode

2023-07-20 Thread Chris Johns
On 20/7/2023 5:24 pm, Cedric Berger wrote:
> On 20.07.23 07:45, chr...@rtems.org wrote:
> 
>> From: Chris Johns 
>>
>> 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
>> ---
>>   rtemsbsd/rtems/rtems-bsd-syscall-api.c | 24 ++---
>>   testsuite/nfs01/test_main.c    | 75 --
>>   2 files changed, 64 insertions(+), 35 deletions(-)
>>
>> diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
>> b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
>> index 76fc8ad7..cfceb768 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 =
>>   >pathinfo.mt_entry->mt_fs_root->location;
>> +    /*
>> + * We need the parent directory so open can find the
>> + * the entry. If we are creating the file the pathinfo
> 
> the the

Yeah and thanks for the review. I think this should be:

/*
 * We need the parent directory so open can find the
 * entry. If we are creating the file the pathinfo
 * vnode entry is the directory to open uses to create
 * the file in.
 */

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH rtems-libbsd/6-freebsd-12 2/3] syscall/open: Reference the path info directory vnode

2023-07-20 Thread Cedric Berger

On 20.07.23 07:45, chr...@rtems.org wrote:


From: Chris Johns 

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
---
  rtemsbsd/rtems/rtems-bsd-syscall-api.c | 24 ++---
  testsuite/nfs01/test_main.c| 75 --
  2 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c 
b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 76fc8ad7..cfceb768 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 =
>pathinfo.mt_entry->mt_fs_root->location;
+   /*
+* We need the parent directory so open can find the
+* the entry. If we are creating the file the pathinfo


the the

Cedric
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH rtems-libbsd/6-freebsd-12 2/3] syscall/open: Reference the path info directory vnode

2023-07-19 Thread chrisj
From: Chris Johns 

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
---
 rtemsbsd/rtems/rtems-bsd-syscall-api.c | 24 ++---
 testsuite/nfs01/test_main.c| 75 --
 2 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c 
b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 76fc8ad7..cfceb768 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 =
>pathinfo.mt_entry->mt_fs_root->location;
+   /*
+* We need the parent directory so open can find the
+* the entry. If we are creating the file the pathinfo
+* vnode entry is the directory to create open the
+* file in.
+*/
cdir = rtems_bsd_libio_loc_to_vnode_dir(>pathinfo);
+   if (cdir == NULL || creat) {
+   cdir = rtems_bsd_libio_loc_to_vnode(>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(>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(>pathinfo),
-   fdp->fd_cdir, oflag, mode, isdir ? "yes" : "no");
+   struct vnode* _vn = 
rtems_bsd_libio_loc_to_vnode(>pathinfo);
+   struct vnode* _dvn = 
rtems_bsd_libio_loc_to_vnode_dir(>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..4ef82b44 100644
--- a/testsuite/nfs01/test_main.c
+++ b/testsuite/nfs01/test_main.c
@@ -46,7 +46,6 @@
 
 #include 
 #include 
-#include 
 
 #include 
 
@@ -58,6 +57,14 @@
 
 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)) { \
@@ -328,10 +335,46 @@ test_path_eval(const char *base, int depth)
test_cleanup(base);
 }
 
+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, ) == 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(, 0, sizeof(pd));
@@ -339,30 +382,6 @@ test_nfs(const char *base)
 #endif
 }
 
-static void
-telnet_shell(char *name, void *arg)
-{
-   rtems_shell_env_t env;
-
-   rtems_shell_dup_current_env();
-
-   env.devname = name;
-   env.taskname = "TLNT";
-   env.login_check = NULL;
-   env.forever =