mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-13 21:29:45 +08:00
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
This commit is contained in:
parent
60e40e9b83
commit
65913f4b3b
@ -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);
|
||||
|
@ -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)) { \
|
||||
@ -328,10 +337,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, &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));
|
||||
@ -339,30 +384,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);
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user