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

Function dfs_file_stat

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

* @brief Get file status information * * @param[in] path The file path to get status for * @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 error codes from filesystem operations */

Source from the content-addressed store, hash-verified

1247 * Other negative error codes from filesystem operations
1248 */
1249int dfs_file_stat(const char *path, struct stat *buf)
1250{
1251 int ret = -ENOENT;
1252 char *fullpath = RT_NULL;
1253 struct dfs_mnt *mnt = RT_NULL;
1254 struct dfs_dentry *dentry = RT_NULL;
1255
1256 fullpath = dfs_normalize_path(NULL, path);
1257 if (fullpath)
1258 {
1259 DLOG(msg, "dfs_file", "mnt", DLOG_MSG, "dfs_mnt_lookup(%s)", fullpath);
1260 mnt = dfs_mnt_lookup(fullpath);
1261 if (mnt)
1262 {
1263 char *tmp = dfs_file_realpath(&mnt, fullpath, DFS_REALPATH_EXCEPT_NONE);
1264 if (tmp)
1265 {
1266 rt_free(fullpath);
1267 fullpath = tmp;
1268 }
1269
1270 DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dentry = dfs_dentry_lookup(mnt, %s)", fullpath);
1271 dentry = dfs_dentry_lookup(mnt, fullpath, 0);
1272 if (dentry)
1273 {
1274 DLOG(msg, "dentry", "dfs_file", DLOG_MSG_RET, "return dentry");
1275 if (mnt->fs_ops->stat)
1276 {
1277 DLOG(msg, "dfs_file", mnt->fs_ops->name, DLOG_MSG, "fs_ops->stat(dentry, buf)");
1278
1279 if (dfs_is_mounted(mnt) == 0)
1280 {
1281 ret = mnt->fs_ops->stat(dentry, buf);
1282 }
1283 }
1284
1285 /* unref dentry */
1286 DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dfs_dentry_unref(dentry)");
1287 dfs_dentry_unref(dentry);
1288 dentry = RT_NULL;
1289 }
1290 }
1291
1292 rt_free(fullpath);
1293 fullpath = RT_NULL;
1294 }
1295 else
1296 {
1297 ret = -ENOMEM;
1298 }
1299
1300 return ret;
1301}
1302
1303/**
1304 * @brief Get file status information without following symbolic links

Callers 4

utimensatFunction · 0.70
statFunction · 0.70
copyFunction · 0.70
dfs_remountFunction · 0.70

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