| 844 | #ifdef RT_USING_DFS_V2 |
| 845 | |
| 846 | static void directory_setattr(const char *pathname, struct dfs_attr *attr, char f, char v) |
| 847 | { |
| 848 | DIR *dir = NULL; |
| 849 | struct dirent *dirent = NULL; |
| 850 | char *full_path; |
| 851 | |
| 852 | if (pathname == RT_NULL) |
| 853 | return; |
| 854 | |
| 855 | full_path = (char *)rt_malloc(DFS_PATH_MAX); |
| 856 | if (full_path == RT_NULL) |
| 857 | return; |
| 858 | |
| 859 | dir = opendir(pathname); |
| 860 | if (dir == RT_NULL) |
| 861 | { |
| 862 | if (f == 0) |
| 863 | { |
| 864 | rt_kprintf("cannot open '%s'\n", pathname); |
| 865 | } |
| 866 | rt_free(full_path); |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | while (1) |
| 871 | { |
| 872 | dirent = readdir(dir); |
| 873 | if (dirent == RT_NULL) |
| 874 | break; |
| 875 | if (rt_strcmp(".", dirent->d_name) != 0 && |
| 876 | rt_strcmp("..", dirent->d_name) != 0) |
| 877 | { |
| 878 | if (strlen(pathname) + 1 + strlen(dirent->d_name) > DFS_PATH_MAX) |
| 879 | { |
| 880 | rt_kprintf("'%s/%s' setattr failed, path too long.\n", pathname, dirent->d_name); |
| 881 | continue; |
| 882 | } |
| 883 | rt_sprintf(full_path, "%s/%s", pathname, dirent->d_name); |
| 884 | if (dirent->d_type == DT_REG) |
| 885 | { |
| 886 | if (dfs_file_setattr(full_path, attr) != 0) |
| 887 | { |
| 888 | if (f == 0) |
| 889 | { |
| 890 | rt_kprintf("'%s' setattr failed, no such file or directory\n", full_path); |
| 891 | } |
| 892 | } |
| 893 | else if (v) |
| 894 | { |
| 895 | rt_kprintf("'%s' setattr 0x%X\n", full_path, attr->st_mode); |
| 896 | } |
| 897 | } |
| 898 | else if (dirent->d_type == DT_DIR) |
| 899 | { |
| 900 | directory_setattr(full_path, attr, f, v); |
| 901 | } |
| 902 | } |
| 903 | } |
no test coverage detected