* @ingroup group_fs_file_descriptor * * This function will return whether this file has been opend. * * @param pathname the file path name. * * @return 0 on file has been open successfully, -1 on open failed. */
| 489 | * @return 0 on file has been open successfully, -1 on open failed. |
| 490 | */ |
| 491 | int fd_is_open(const char *pathname) |
| 492 | { |
| 493 | char *fullpath; |
| 494 | unsigned int index; |
| 495 | struct dfs_filesystem *fs; |
| 496 | struct dfs_file *fd; |
| 497 | struct dfs_fdtable *fdt; |
| 498 | |
| 499 | fdt = dfs_fdtable_get(); |
| 500 | fullpath = dfs_normalize_path(NULL, pathname); |
| 501 | if (fullpath != NULL) |
| 502 | { |
| 503 | char *mountpath; |
| 504 | fs = dfs_filesystem_lookup(fullpath); |
| 505 | if (fs == NULL) |
| 506 | { |
| 507 | /* can't find mounted file system */ |
| 508 | rt_free(fullpath); |
| 509 | |
| 510 | return -1; |
| 511 | } |
| 512 | |
| 513 | /* get file path name under mounted file system */ |
| 514 | if (fs->path[0] == '/' && fs->path[1] == '\0') |
| 515 | mountpath = fullpath; |
| 516 | else |
| 517 | mountpath = fullpath + strlen(fs->path); |
| 518 | |
| 519 | dfs_lock(); |
| 520 | |
| 521 | for (index = 0; index < fdt->maxfd; index++) |
| 522 | { |
| 523 | fd = fdt->fds[index]; |
| 524 | if (fd == NULL || fd->vnode->fops == NULL || fd->vnode->path == NULL) continue; |
| 525 | |
| 526 | if (fd->vnode->fs == fs && strcmp(fd->vnode->path, mountpath) == 0) |
| 527 | { |
| 528 | /* found file in file descriptor table */ |
| 529 | rt_free(fullpath); |
| 530 | dfs_unlock(); |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | } |
| 535 | dfs_unlock(); |
| 536 | |
| 537 | rt_free(fullpath); |
| 538 | } |
| 539 | |
| 540 | return -1; |
| 541 | } |
| 542 | |
| 543 | /** |
| 544 | * @brief Duplicates a file descriptor to a specified file descriptor. |
nothing calls this directly
no test coverage detected