* @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 */
| 1247 | * Other negative error codes from filesystem operations |
| 1248 | */ |
| 1249 | int 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 |
no test coverage detected