MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_file_isdir

Function dfs_file_isdir

components/dfs/dfs_v2/src/dfs_file.c:2358–2416  ·  view source on GitHub ↗

* @brief Check if a path refers to a directory * * This function checks whether the specified path exists and is a directory. * * @param[in] path The filesystem path to check * * @return int Operation result: * - 0 if path exists and is a directory * -RT_ERROR if path doesn't exist or isn't a directory */

Source from the content-addressed store, hash-verified

2356 * -RT_ERROR if path doesn't exist or isn't a directory
2357 */
2358int dfs_file_isdir(const char *path)
2359{
2360 int ret = -RT_ERROR;
2361 char *fullpath = RT_NULL;
2362 struct dfs_mnt *mnt = RT_NULL;
2363 struct dfs_dentry *dentry = RT_NULL;
2364
2365 fullpath = dfs_normalize_path(NULL, path);
2366 if (fullpath)
2367 {
2368 DLOG(msg, "dfs_file", "mnt", DLOG_MSG, "dfs_mnt_lookup(%s)", fullpath);
2369 mnt = dfs_mnt_lookup(fullpath);
2370 if (mnt)
2371 {
2372 char *tmp = dfs_file_realpath(&mnt, fullpath, DFS_REALPATH_EXCEPT_NONE);
2373 if (tmp)
2374 {
2375 rt_free(fullpath);
2376 fullpath = tmp;
2377 }
2378
2379 DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dentry = dfs_dentry_lookup(mnt, %s)", fullpath);
2380 dentry = dfs_dentry_lookup(mnt, fullpath, 0);
2381 if (dentry)
2382 {
2383 DLOG(msg, "dentry", "dfs_file", DLOG_MSG_RET, "return dentry");
2384 if (mnt->fs_ops->stat)
2385 {
2386 struct stat stat = {0};
2387 DLOG(msg, "dfs_file", mnt->fs_ops->name, DLOG_MSG, "fs_ops->stat(dentry, buf)");
2388
2389 if (dfs_is_mounted(mnt) == 0)
2390 {
2391 ret = mnt->fs_ops->stat(dentry, &stat);
2392 }
2393
2394 if (ret == RT_EOK && S_ISDIR(stat.st_mode))
2395 {
2396 ret = RT_EOK;
2397 }
2398 else
2399 {
2400 ret = -RT_ERROR;
2401 }
2402 }
2403
2404 /* unref dentry */
2405 DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dfs_dentry_unref(dentry)");
2406 dfs_dentry_unref(dentry);
2407 dentry = RT_NULL;
2408 }
2409 }
2410
2411 rt_free(fullpath);
2412 fullpath = RT_NULL;
2413 }
2414
2415 return ret;

Callers 3

opendirFunction · 0.85
dfs_file_linkFunction · 0.85
catFunction · 0.85

Calls 7

dfs_mnt_lookupFunction · 0.85
dfs_file_realpathFunction · 0.85
rt_freeFunction · 0.85
dfs_dentry_lookupFunction · 0.85
dfs_is_mountedFunction · 0.85
dfs_dentry_unrefFunction · 0.85
dfs_normalize_pathFunction · 0.70

Tested by

no test coverage detected