* @brief Change the ownership of a file or directory. * * This function changes the owner and/or group of the file or directory specified by `pathname`. * The `owner` and `group` parameters represent the new owner and group IDs, respectively. If either * parameter is set to `-1`, that aspect (owner or group) will remain unchanged. * * @param[in] pathname The path to the file or directory wh
| 10377 | * to change the ownership of a file or directory. |
| 10378 | */ |
| 10379 | sysret_t sys_chown(const char *pathname, uid_t owner, gid_t group) |
| 10380 | { |
| 10381 | char *copy_file; |
| 10382 | size_t len_file, copy_len_file; |
| 10383 | struct dfs_attr attr = {0}; |
| 10384 | int ret = 0; |
| 10385 | |
| 10386 | len_file = lwp_user_strlen(pathname); |
| 10387 | if (len_file <= 0) |
| 10388 | { |
| 10389 | return -EFAULT; |
| 10390 | } |
| 10391 | |
| 10392 | copy_file = (char*)rt_malloc(len_file + 1); |
| 10393 | if (!copy_file) |
| 10394 | { |
| 10395 | return -ENOMEM; |
| 10396 | } |
| 10397 | |
| 10398 | copy_len_file = lwp_get_from_user(copy_file, (void *)pathname, len_file); |
| 10399 | |
| 10400 | if(owner >= 0) |
| 10401 | { |
| 10402 | attr.st_uid = owner; |
| 10403 | attr.ia_valid |= ATTR_UID_SET; |
| 10404 | } |
| 10405 | |
| 10406 | if(group >= 0) |
| 10407 | { |
| 10408 | attr.st_gid = group; |
| 10409 | attr.ia_valid |= ATTR_GID_SET; |
| 10410 | } |
| 10411 | |
| 10412 | copy_file[copy_len_file] = '\0'; |
| 10413 | ret = dfs_file_setattr(copy_file, &attr); |
| 10414 | rt_free(copy_file); |
| 10415 | |
| 10416 | return (ret < 0 ? GET_ERRNO() : ret); |
| 10417 | } |
| 10418 | |
| 10419 | #ifndef LWP_USING_RUNTIME |
| 10420 | sysret_t lwp_teardown(struct rt_lwp *lwp, void (*cb)(void)) |
nothing calls this directly
no test coverage detected