<!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: hsla(0,0%,100%,.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: hsla(0,0%,100%,.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/TheSamPrice">Sam Price</a> created a merge request: <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1385">!1385</a>
</p>
<div class="branch">
Project:Branches: TheSamPrice/rtems:fix/fatfs-mkfs-parm to rtems/rtos/rtems:main
</div>
<div class="author">
Author: Sam Price
</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: 0px; margin-bottom: 10px;" align="initial">Summary<a href="#summary" aria-label="Link to heading 'Summary'" data-heading-content="Summary" class="anchor" style="margin-top: 0px;"></a>
</h2>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">testsuites/fstests: Include the FatFS headers in the FatFS tests</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">The three FatFS tests declared the disk I/O and f_mkfs() API by hand
instead of including <rtems/fatfs/rtems-fatfs.h>, which already declares
all of it.  A hand-copied declaration can drift from the implementation,
and these had drifted in four ways:</p>
<ul dir="auto" style="text-align: initial; list-style-type: disc; margin: 0px 0px 1rem; padding: 0;">
<li style="margin-top: 0px; line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<p style="color: #3a383f; margin: 0px 0px 1rem;">MKFS_PARM was redeclared with an unsigned long au_size.  The member
is a DWORD in contrib/cpukit/fatfs/ff.h, which is a uint32_t.  The
two layouts coincide on ILP32, so the tests work there by accident.
On LP64 the unsigned long is eight bytes with an eight byte
alignment, which pushes au_size from offset 12 to offset 16 and
grows the structure from 16 to 24 bytes.</p>
<p style="color: #3a383f; margin: 0px 0px 1rem;">fsfatfsformat01 fails outright as a result:  f_mkfs() reads the
cluster size from the four bytes of padding the test never writes,
formats the volume with a garbage cluster size, and the block size
and block count assertions of test_disk_params() fail.</p>
<p style="color: #3a383f; margin: 0px 0px 1rem;">fsfatfssync01 and fatfs_support escape this only because their
MKFS_PARM objects are static const with a zero cluster size, so
f_mkfs() reads the padding of the wrong layout as zero and happens
to pick the automatic cluster size.  An automatic object or a
non-zero cluster size would have failed the same way.</p>
</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<p style="color: #3a383f; margin: 0px 0px 1rem;">FRESULT was redeclared as unsigned char, where ff.h makes it an
enum.</p>
</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<p style="color: #3a383f; margin: 0px 0px 1rem;">f_mkfs() was declared as taking a const char * path, where ff.h uses
const TCHAR *.</p>
</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<p style="color: #3a383f; margin: 0px 0px 1rem;">rtems-fatfs.h declares pdrv as uint8_t, not unsigned char.  The two
agree on every RTEMS target today, so this one is only a latent
hazard.  The extern on the prototypes was redundant as well: a
declaration of a function has external linkage without it.</p>
</li>
</ul>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">Include <rtems/fatfs/rtems-fatfs.h> and delete the local FRESULT,
MKFS_PARM, FR_<em style="margin-top: 0px;">, FM_</em> and prototype declarations, so that the tests
cannot drift from the implementation again.  The header pulls in ff.h
and diskio.h itself.  The local MKFS_PARM members were named num_fat and
auto_cluster_size, so the designated initializers become n_fat and
au_size.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">contrib/cpukit/fatfs is added to the include path of fsfatfsformat01, of
fsfatfssync01, and of the testfatfs support library, which is how
spec/build/cpukit/objfatfs.yml reaches the same headers; the installed
layout puts ff.h, ffconf.h and diskio.h next to rtems-fatfs.h in
${BSP_INCLUDEDIR}/rtems/fatfs.  testfatfs is a library target with its
own include list, so the eleven test programs that link it need no
change.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">The lowercase mkfs_parm of fsfatfsformat01 is left alone: it is the
parameter descriptor of the test itself, which fatfs_format_disk()
converts into a MKFS_PARM member by member, not a copy of the FatFS
type.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">The struct mismatch is architecture independent, so fsfatfsformat01
fails on every LP64 BSP.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">Tested on riscv/mbv and riscv/mbv64 under QEMU amd-microblaze-v-generic:
the thirteen FatFS tests give 11 PASS and 2 XFAIL, and a sweep of all
110 fstests programs gives 86 PASS and 24 XFAIL with byte-identical
results on the two BSPs.  Every XFAIL is a pre-existing
TEST_STATE_EXPECTED_FAIL from the fsrename*/fssymlink family, which
fails on every filesystem.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">Co-Authored-By: Claude Opus 5 (1M context) <a href="mailto:noreply@anthropic.com" style="margin-top: 0px;">noreply@anthropic.com</a></p>
<h2 id="user-content-generative-ai" dir="auto" style="margin-top: 20px; margin-bottom: 0px;" 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: 0px;"></a>
</h2>

</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/1385">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/4-9grmz3v2rguypxkbinjqvfu4l-1d/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/1385 at 1785541171
</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/1385"}}</script>


</p>
</div>
</body>
</html>