Mazen hassan created a merge request: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1190

Project:Branches: Mazen_Hassan/rtems:fix/rename-posix-same-file to 
rtems/rtos/rtems:main
Author:   Mazen hassan



## Summary

## Problem

Closes #5487

POSIX 1003.1-2024 requires that rename() returns success when old and new 
resolve to the same file:

> "If the old argument and the new argument resolve to either the same existing 
> directory entry or different directory entries for the same existing file, 
> rename() shall return successfully and perform no other action."

The previous implementation evaluated the new path with RTEMS_FS_EXCLUSIVE, 
causing rename() to fail with EEXIST whenever the destination already existed - 
including the same-file case.

## Fix

Evaluate the new path without RTEMS_FS_EXCLUSIVE first. Compare the node_access 
pointers of both resolved locations - this is the filesystem node pointer (e.g. 
the IMFS jnode) and is the correct way to identify the same file within RTEMS. 
If both paths resolve to the same node, return 0 immediately as a no-op.

If they differ, clean up and re-evaluate the new path with the original flags 
so all existing rename behaviour is preserved.

## Testing

Built for riscv/rv64imafdc - compiles cleanly with no warnings.

## Known Limitation

Renaming over an existing destination (e.g. `mv a b` where `b` already exists) 
still fails with EEXIST. Full POSIX compliance for that case requires changes 
inside each filesystem's rename_h implementation (e.g. IMFS_rename) and is out 
of scope for this MR.

## Generative AI

Used Claude (Anthropic) as a coding assistant to help diagnose the root cause, 
understand the RTEMS filesystem path evaluation API 
(\`rtems_filesystem_eval_path_start\`, \`RTEMS_FS_EXCLUSIVE\`, 
\`node_access\`), and structure the fix. The approach - evaluating the 
destination path twice, with and without \`RTEMS_FS_EXCLUSIVE\` and comparing 
\`node_access\` pointers for same-file detection — was developed and verified 
by the contributor. All code was reviewed, understood, and tested manually 
before submission.

<!--Default settings, if it is a dropdown it will set after submission-->

-- 
View it on GitLab: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1190
You're receiving this email because of your account on gitlab.rtems.org.


_______________________________________________
bugs mailing list
[email protected]
http://lists.rtems.org/mailman/listinfo/bugs

Reply via email to