Преглед изворни кода

修正当dfs系统修改后, channel的dfs_fd中的fnode没有申请空间的问题

shaojinchun пре 5 година
родитељ
комит
345a54fcea
1 измењених фајлова са 33 додато и 8 уклоњено
  1. 33 8
      components/lwp/lwp_ipc.c

+ 33 - 8
components/lwp/lwp_ipc.c

@@ -899,33 +899,44 @@ int lwp_channel_open(int fdt_type, const char *name, int flags)
 {
 {
     int fd;
     int fd;
     rt_channel_t ch = RT_NULL;
     rt_channel_t ch = RT_NULL;
+    struct dfs_fd *d;
 
 
     fd = _chfd_alloc(fdt_type);     /* allocate an IPC channel descriptor */
     fd = _chfd_alloc(fdt_type);     /* allocate an IPC channel descriptor */
     if (fd == -1)
     if (fd == -1)
     {
     {
         goto quit;
         goto quit;
     }
     }
+    d = lwp_fd_get(fdt_type, fd);
+    d->fnode = (struct dfs_fnode *)rt_malloc(sizeof(struct dfs_fnode));
+    if (!d->fnode)
+    {
+        _chfd_free(fd, fdt_type);
+        fd = -1;
+        goto quit;
+    }
+
     ch = rt_raw_channel_open(name, flags);
     ch = rt_raw_channel_open(name, flags);
     if (ch)
     if (ch)
     {
     {
-        struct dfs_fd *d;
-
-        d = lwp_fd_get(fdt_type, fd);
-
+        rt_memset(d->fnode, 0, sizeof(struct dfs_fnode));
+        rt_list_init(&d->fnode->list);
         d->fnode->type = FT_USER;
         d->fnode->type = FT_USER;
         d->fnode->path = NULL;
         d->fnode->path = NULL;
+        d->fnode->fullpath = NULL;
 
 
         d->fnode->fops = &channel_fops;
         d->fnode->fops = &channel_fops;
 
 
         d->fnode->flags = O_RDWR; /* set flags as read and write */
         d->fnode->flags = O_RDWR; /* set flags as read and write */
         d->fnode->size = 0;
         d->fnode->size = 0;
         d->pos = 0;
         d->pos = 0;
+        d->fnode->ref_count = 1;
 
 
         /* set socket to the data of dfs_fd */
         /* set socket to the data of dfs_fd */
         d->fnode->data = (void *)ch;
         d->fnode->data = (void *)ch;
     }
     }
     else
     else
     {
     {
+        rt_free(d->fnode);
         _chfd_free(fd, fdt_type);
         _chfd_free(fd, fdt_type);
         fd = -1;
         fd = -1;
     }
     }
@@ -954,14 +965,28 @@ static rt_channel_t fd_2_channel(int fdt_type, int fd)
 rt_err_t lwp_channel_close(int fdt_type, int fd)
 rt_err_t lwp_channel_close(int fdt_type, int fd)
 {
 {
     rt_channel_t ch;
     rt_channel_t ch;
+    struct dfs_fd *d;
+
+    d = lwp_fd_get(fdt_type, fd);
+    if (!d)
+    {
+        return -RT_EIO;
+    }
+
+    if (!d->fnode)
+    {
+        return -RT_EIO;
+    }
 
 
     ch = fd_2_channel(fdt_type, fd);
     ch = fd_2_channel(fdt_type, fd);
-    if (ch)
+    rt_free(d->fnode);
+    if (!ch)
     {
     {
-        _chfd_free(fd, fdt_type);
-        return rt_raw_channel_close(ch);
+        return -RT_EIO;
     }
     }
-    return -RT_EIO;
+    _chfd_free(fd, fdt_type);
+
+    return rt_raw_channel_close(ch);
 }
 }
 
 
 rt_err_t lwp_channel_send(int fdt_type, int fd, rt_channel_msg_t data)
 rt_err_t lwp_channel_send(int fdt_type, int fd, rt_channel_msg_t data)