* @brief Set file attributes for the specified path * * This function sets file attributes (permissions, ownership, timestamps, etc.) * for the file specified by path. * * @param[in] path The file path to set attributes for * @param[in] attr Pointer to attribute structure containing new attributes * * @return int Operation result: * - 0 on success * -RT_ERROR if general e
| 1425 | * @note The actual supported attributes depend on the underlying filesystem |
| 1426 | */ |
| 1427 | int dfs_file_setattr(const char *path, struct dfs_attr *attr) |
| 1428 | { |
| 1429 | int ret = -RT_ERROR; |
| 1430 | char *fullpath = RT_NULL; |
| 1431 | struct dfs_mnt *mnt = RT_NULL; |
| 1432 | struct dfs_dentry *dentry = RT_NULL; |
| 1433 | |
| 1434 | fullpath = dfs_normalize_path(NULL, path); |
| 1435 | if (fullpath) |
| 1436 | { |
| 1437 | DLOG(msg, "dfs_file", "mnt", DLOG_MSG, "dfs_mnt_lookup(%s)", fullpath); |
| 1438 | mnt = dfs_mnt_lookup(fullpath); |
| 1439 | if (mnt) |
| 1440 | { |
| 1441 | char *tmp = dfs_file_realpath(&mnt, fullpath, DFS_REALPATH_EXCEPT_LAST); |
| 1442 | if (tmp) |
| 1443 | { |
| 1444 | rt_free(fullpath); |
| 1445 | fullpath = tmp; |
| 1446 | } |
| 1447 | |
| 1448 | DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dentry = dfs_dentry_lookup(mnt, %s)", fullpath); |
| 1449 | dentry = dfs_dentry_lookup(mnt, fullpath, 0); |
| 1450 | if (dentry) |
| 1451 | { |
| 1452 | DLOG(msg, "dentry", "dfs_file", DLOG_MSG_RET, "return dentry"); |
| 1453 | if (mnt->fs_ops->setattr) |
| 1454 | { |
| 1455 | DLOG(msg, "dfs_file", mnt->fs_ops->name, DLOG_MSG, "fs_ops->setattr(dentry, attr)"); |
| 1456 | |
| 1457 | if (dfs_is_mounted(mnt) == 0) |
| 1458 | { |
| 1459 | ret = mnt->fs_ops->setattr(dentry, attr); |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | /* unref dentry */ |
| 1464 | DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dfs_dentry_unref(dentry)"); |
| 1465 | dfs_dentry_unref(dentry); |
| 1466 | dentry = RT_NULL; |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | rt_free(fullpath); |
| 1471 | fullpath = RT_NULL; |
| 1472 | } |
| 1473 | |
| 1474 | return ret; |
| 1475 | } |
| 1476 | |
| 1477 | /** |
| 1478 | * @brief Perform device-specific control operations |
no test coverage detected