* @brief List all open file descriptors in the current process * * @return int 0 on success, -1 if failed to get file descriptor table */
| 1105 | * @return int 0 on success, -1 if failed to get file descriptor table |
| 1106 | */ |
| 1107 | int list_fd(void) |
| 1108 | { |
| 1109 | int index; |
| 1110 | struct dfs_fdtable *fd_table; |
| 1111 | |
| 1112 | fd_table = dfs_fdtable_get(); |
| 1113 | if (!fd_table) return -1; |
| 1114 | |
| 1115 | rt_enter_critical(); |
| 1116 | |
| 1117 | rt_kprintf("fd type ref magic path\n"); |
| 1118 | rt_kprintf("-- ------ --- ----- ------\n"); |
| 1119 | for (index = 0; index < (int)fd_table->maxfd; index++) |
| 1120 | { |
| 1121 | struct dfs_file *file = fd_table->fds[index]; |
| 1122 | |
| 1123 | if (file && file->vnode) |
| 1124 | { |
| 1125 | rt_kprintf("%2d ", index); |
| 1126 | if (file->vnode->type == FT_DIRECTORY) rt_kprintf("%-7.7s ", "dir"); |
| 1127 | else if (file->vnode->type == FT_REGULAR) rt_kprintf("%-7.7s ", "file"); |
| 1128 | else if (file->vnode->type == FT_SOCKET) rt_kprintf("%-7.7s ", "socket"); |
| 1129 | else if (file->vnode->type == FT_USER) rt_kprintf("%-7.7s ", "user"); |
| 1130 | else if (file->vnode->type == FT_DEVICE) rt_kprintf("%-7.7s ", "device"); |
| 1131 | else rt_kprintf("%-8.8s ", "unknown"); |
| 1132 | rt_kprintf("%3d ", file->ref_count); |
| 1133 | rt_kprintf("%04x ", file->magic); |
| 1134 | |
| 1135 | if (file->dentry) |
| 1136 | { |
| 1137 | rt_kprintf("%s%s\n", file->dentry->mnt->fullpath, file->dentry->pathname); |
| 1138 | } |
| 1139 | else |
| 1140 | { |
| 1141 | rt_kprintf("\n"); |
| 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | rt_exit_critical(); |
| 1146 | |
| 1147 | return 0; |
| 1148 | } |
| 1149 | MSH_CMD_EXPORT(list_fd, list file descriptor); |
| 1150 | |
| 1151 | /** |
nothing calls this directly
no test coverage detected