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

Function dfs_file_setattr

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

* @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

Source from the content-addressed store, hash-verified

1425 * @note The actual supported attributes depend on the underlying filesystem
1426 */
1427int 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

Callers 5

directory_setattrFunction · 0.85
cmd_chmodFunction · 0.85
sys_chmodFunction · 0.85
sys_chownFunction · 0.85
utimensatFunction · 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