فهرست منبع

修改每个进程都有独自的工作目录

@lin12345678 4 سال پیش
والد
کامیت
aa31072e3c
5فایلهای تغییر یافته به همراه75 افزوده شده و 40 حذف شده
  1. 0 2
      components/dfs/include/dfs.h
  2. 1 37
      components/dfs/src/dfs.c
  3. 1 1
      components/dfs/src/dfs_posix.c
  4. 57 0
      components/lwp/lwp_dir.c
  5. 16 0
      components/lwp/lwp_dir.h

+ 0 - 2
components/dfs/include/dfs.h

@@ -117,8 +117,6 @@ void fd_init(struct dfs_fd *fd);
 
 struct dfs_fdtable *dfs_fdtable_get(void);
 struct dfs_fdtable *dfs_fdtable_get_global(void);
-void lwp_dir_set(char *buf);
-char *lwp_dir_get(void);
 
 #ifdef __cplusplus
 }

+ 1 - 37
components/dfs/src/dfs.c

@@ -14,6 +14,7 @@
 #include <dfs_fs.h>
 #include <dfs_file.h>
 #include "dfs_private.h"
+#include "lwp_dir.h"
 #ifdef RT_USING_LWP
 #include <lwp.h>
 #endif
@@ -723,44 +724,7 @@ struct dfs_fdtable *dfs_fdtable_get_global(void)
 {
     return &_fdtab;
 }
-void lwp_dir_set(char *buf)
-{
-    if(strlen(buf) >= DFS_PATH_MAX)
-    {
-        rt_kprintf("buf too long!\n");
-        return ;
-    }
-
-#ifdef RT_USING_LWP
-    struct rt_lwp *lwp;
 
-    lwp = (struct rt_lwp *)rt_thread_self()->lwp;
-    if (lwp)
-        rt_strncpy(lwp->working_directory, buf, DFS_PATH_MAX);
-    else
-        rt_strncpy(working_directory, buf, DFS_PATH_MAX);
-#else
-    rt_strncpy(working_directory, buf, DFS_PATH_MAX);
-#endif
-    return ;
-}
-
-char *lwp_dir_get(void)
-{
-    char *dir_buf = RT_NULL;
-#ifdef RT_USING_LWP
-    struct rt_lwp *lwp;
-
-    lwp = (struct rt_lwp *)rt_thread_self()->lwp;
-    if (lwp)
-        dir_buf = &lwp->working_directory[0];
-    else
-        dir_buf = &working_directory[0];
-#else
-    dir_buf =  &working_directory[0];
-#endif
-    return dir_buf;
-}
 #ifdef RT_USING_FINSH
 #include <finsh.h>
 int list_fd(void)

+ 1 - 1
components/dfs/src/dfs_posix.c

@@ -12,7 +12,7 @@
 #include <dfs.h>
 #include <dfs_posix.h>
 #include "dfs_private.h"
-
+#include "lwp_dir.h"
 /**
  * @addtogroup FsPosixApi
  */

+ 57 - 0
components/lwp/lwp_dir.c

@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2021-08-24     linzhenxing  the first version
+ */
+#include <dfs.h>
+#include "lwp_dir.h"
+#ifdef RT_USING_LWP
+#include <lwp.h>
+#endif
+
+#ifdef DFS_USING_WORKDIR
+extern char working_directory[];
+#endif
+
+void lwp_dir_set(char *buf)
+{
+    if(strlen(buf) >= DFS_PATH_MAX)
+    {
+        rt_kprintf("buf too long!\n");
+        return ;
+    }
+
+#ifdef RT_USING_LWP
+    struct rt_lwp *lwp;
+
+    lwp = (struct rt_lwp *)rt_thread_self()->lwp;
+    if (lwp)
+        rt_strncpy(lwp->working_directory, buf, DFS_PATH_MAX);
+    else
+        rt_strncpy(working_directory, buf, DFS_PATH_MAX);
+#else
+    rt_strncpy(working_directory, buf, DFS_PATH_MAX);
+#endif
+    return ;
+}
+
+char *lwp_dir_get(void)
+{
+    char *dir_buf = RT_NULL;
+#ifdef RT_USING_LWP
+    struct rt_lwp *lwp;
+
+    lwp = (struct rt_lwp *)rt_thread_self()->lwp;
+    if (lwp)
+        dir_buf = &lwp->working_directory[0];
+    else
+        dir_buf = &working_directory[0];
+#else
+    dir_buf =  &working_directory[0];
+#endif
+    return dir_buf;
+}

+ 16 - 0
components/lwp/lwp_dir.h

@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2021-08-24     linzhenxing      The first version.
+ */
+
+#ifndef __LWP_DIR_H__
+#define __LWP_DIR_H__
+
+void lwp_dir_set(char *buf);
+char *lwp_dir_get(void);
+#endif