| 1079 | }; |
| 1080 | |
| 1081 | int lwp_channel_open(int fdt_type, const char *name, int flags) |
| 1082 | { |
| 1083 | int fd; |
| 1084 | rt_channel_t ch = RT_NULL; |
| 1085 | struct dfs_file *d; |
| 1086 | |
| 1087 | fd = _chfd_alloc(fdt_type); /* allocate an IPC channel descriptor */ |
| 1088 | if (fd == -1) |
| 1089 | { |
| 1090 | goto quit; |
| 1091 | } |
| 1092 | |
| 1093 | d = lwp_fd_get(fdt_type, fd); |
| 1094 | d->vnode = (struct dfs_vnode *)rt_malloc(sizeof(struct dfs_vnode)); |
| 1095 | if (!d->vnode) |
| 1096 | { |
| 1097 | _chfd_free(fd, fdt_type); |
| 1098 | fd = -1; |
| 1099 | goto quit; |
| 1100 | } |
| 1101 | |
| 1102 | ch = rt_raw_channel_open(name, flags); |
| 1103 | if (ch) |
| 1104 | { |
| 1105 | /* initialize vnode */ |
| 1106 | dfs_vnode_init(d->vnode, FT_USER, &channel_fops); |
| 1107 | d->flags = O_RDWR; /* set flags as read and write */ |
| 1108 | |
| 1109 | /* set socket to the data of dfs_file */ |
| 1110 | d->vnode->data = (void *)ch; |
| 1111 | } |
| 1112 | else |
| 1113 | { |
| 1114 | rt_free(d->vnode); |
| 1115 | d->vnode = RT_NULL; |
| 1116 | _chfd_free(fd, fdt_type); |
| 1117 | fd = -1; |
| 1118 | } |
| 1119 | quit: |
| 1120 | return fd; |
| 1121 | } |
| 1122 | |
| 1123 | static rt_channel_t fd_2_channel(int fdt_type, int fd) |
| 1124 | { |
no test coverage detected