<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style="--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>
GitLab
</title>
<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>
<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style="font-size: inherit; -webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";">
<div class="content">
<p class="details" style="font-style: italic; color: #626168;">
<a href="https://gitlab.rtems.org/Mazen_Hassan">Mazen hassan</a> created a merge request: <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1190">!1190</a>
</p>
<div class="branch">
Project:Branches: Mazen_Hassan/rtems:fix/rename-posix-same-file to rtems/rtos/rtems:main
</div>
<div class="author">
Author: Mazen hassan
</div>
<div class="assignee">
Assignees:
</div>
<div class="reviewer">
Reviewers:
</div>
<div class="md gl-mt-5" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word; margin-top: 1rem;">
<h2 id="user-content-summary" dir="auto" style="margin-top: 0; margin-bottom: 10px;" align="initial">Summary<a href="#summary" aria-label="Link to heading 'Summary'" data-heading-content="Summary" class="anchor" style="margin-top: 0;"></a>
</h2>
<h2 id="user-content-problem" dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">Problem<a href="#problem" aria-label="Link to heading 'Problem'" data-heading-content="Problem" class="anchor" style="margin-top: 0;"></a>
</h2>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Closes <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5487" title="rename() fails when source and target are the same - violates POSIX compliance" class="gfm gfm-issue" data-original="#5487" data-link="false" data-link-reference="false" data-issue="29510" data-project="26" data-iid="5487" data-namespace-path="rtems/rtos/rtems" data-project-path="rtems/rtos/rtems" data-issue-type="issue" data-container="body" data-placement="top" data-reference-type="issue" style="margin-top: 0;">#5487</a></p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">POSIX 1003.1-2024 requires that rename() returns success when old and new resolve to the same file:</p>
<blockquote dir="auto" style="font-size: inherit; color: #626168; padding-top: 0.5rem; padding-bottom: 0.5rem; padding-left: 1rem; border-left-style: solid; margin: 0.5rem 0; border-color: #bfbfc3; border-width: 0 0 0 4px;" align="initial">
<p style="color: inherit; line-height: 1.5; margin: 0;">"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."</p>
</blockquote>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">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.</p>
<h2 id="user-content-fix" dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">Fix<a href="#fix" aria-label="Link to heading 'Fix'" data-heading-content="Fix" class="anchor" style="margin-top: 0;"></a>
</h2>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">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.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">If they differ, clean up and re-evaluate the new path with the original flags so all existing rename behaviour is preserved.</p>
<h2 id="user-content-testing" dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">Testing<a href="#testing" aria-label="Link to heading 'Testing'" data-heading-content="Testing" class="anchor" style="margin-top: 0;"></a>
</h2>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Built for riscv/rv64imafdc - compiles cleanly with no warnings.</p>
<h2 id="user-content-known-limitation" dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">Known Limitation<a href="#known-limitation" aria-label="Link to heading 'Known Limitation'" data-heading-content="Known Limitation" class="anchor" style="margin-top: 0;"></a>
</h2>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Renaming over an existing destination (e.g. <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">mv a b</code> where <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">b</code> 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.</p>
<h2 id="user-content-generative-ai" dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">Generative AI<a href="#generative-ai" aria-label="Link to heading 'Generative AI'" data-heading-content="Generative AI" class="anchor" style="margin-top: 0;"></a>
</h2>
<p dir="auto" style="color: #3a383f; margin: 0;" align="initial">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.</p>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">
—
<br>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1190">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/sent_notifications/3-c9slo3w3wp09oki8k7ntyi5ss/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1190 at 1775649118
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1190"}}</script>
</p>
</div>
</body>
</html>