* @brief Get file status information without following symbolic links * * @param[in] path The file path to get status for (does not follow symlinks) * @param[out] buf Pointer to stat structure to store the status information * * @return int Operation result: * - 0 on success * -ENOENT if file not found * -ENOMEM if memory allocation failed * Other negative
| 1316 | * @see dfs_file_stat() |
| 1317 | */ |
| 1318 | int dfs_file_lstat(const char *path, struct stat *buf) |
| 1319 | { |
| 1320 | int ret = -ENOENT; |
| 1321 | char *fullpath = RT_NULL; |
| 1322 | struct dfs_mnt *mnt = RT_NULL; |
| 1323 | struct dfs_dentry *dentry = RT_NULL; |
| 1324 | |
| 1325 | fullpath = dfs_normalize_path(NULL, path); |
| 1326 | if (fullpath) |
| 1327 | { |
| 1328 | DLOG(msg, "dfs_file", "mnt", DLOG_MSG, "dfs_mnt_lookup(%s)", fullpath); |
| 1329 | mnt = dfs_mnt_lookup(fullpath); |
| 1330 | if (mnt) |
| 1331 | { |
| 1332 | char *tmp = dfs_file_realpath(&mnt, fullpath, DFS_REALPATH_EXCEPT_LAST); |
| 1333 | if (tmp) |
| 1334 | { |
| 1335 | rt_free(fullpath); |
| 1336 | fullpath = tmp; |
| 1337 | } |
| 1338 | |
| 1339 | DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dentry = dfs_dentry_lookup(mnt, %s)", fullpath); |
| 1340 | dentry = dfs_dentry_lookup(mnt, fullpath, 0); |
| 1341 | if (dentry) |
| 1342 | { |
| 1343 | DLOG(msg, "dentry", "dfs_file", DLOG_MSG_RET, "return dentry"); |
| 1344 | if (mnt->fs_ops->stat) |
| 1345 | { |
| 1346 | DLOG(msg, "dfs_file", mnt->fs_ops->name, DLOG_MSG, "fs_ops->stat(dentry, buf)"); |
| 1347 | |
| 1348 | if (dfs_is_mounted(mnt) == 0) |
| 1349 | { |
| 1350 | ret = mnt->fs_ops->stat(dentry, buf); |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | /* unref dentry */ |
| 1355 | DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dfs_dentry_unref(dentry)"); |
| 1356 | dfs_dentry_unref(dentry); |
| 1357 | dentry = RT_NULL; |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | rt_free(fullpath); |
| 1362 | fullpath = RT_NULL; |
| 1363 | } |
| 1364 | else |
| 1365 | { |
| 1366 | ret = -ENOMEM; |
| 1367 | } |
| 1368 | |
| 1369 | rt_set_errno(-ret); |
| 1370 | |
| 1371 | return ret; |
| 1372 | } |
| 1373 | |
| 1374 | /** |
| 1375 | * @brief Get file status information using file descriptor |
no test coverage detected