Skip to content

[UDFS] Use LONG for reference/counter fields to eliminate Interlocked casts and fix mixed sign-type comparisons#114

Closed
Copilot wants to merge 3 commits into
writefrom
copilot/udfs-simplify-interlocked-functions
Closed

[UDFS] Use LONG for reference/counter fields to eliminate Interlocked casts and fix mixed sign-type comparisons#114
Copilot wants to merge 3 commits into
writefrom
copilot/udfs-simplify-interlocked-functions

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 12, 2026

Counter and reference fields in the UDFS driver were declared as ULONG/uint32 despite being used exclusively with signed Interlocked operations, requiring pervasive (PLONG)/(int32*) casts at every call site. More critically, companion fields (FcbCleanup, VcbResidualReference, etc.) remained ULONG while their siblings were already signed, producing mixed signed/unsigned comparisons.

Field type changes

struct.h — changed ULONG/uint32LONG:

  • FCB: FcbReference, FcbCleanup, CachedOpenHandleCount, FcbUserReference
  • VCB: VcbReference, VcbCleanup, VcbUserReference, VcbResidualReference, VcbResidualUserReference
  • Misc: Modified, numFiles, numDirs, CcbCount

udf_info/udf_rel.h — changed uint32LONG:

  • UDF_FILE_INFO::RefCount, OpenCount
  • UDF_DATALOC_INFO::LinkRefCount

Cast removal

With correct field types, all (PLONG) / (int32*) casts are removed from ~60 InterlockedIncrement/InterlockedDecrement/InterlockedExchangeAdd call sites across 9 files.

// Before
InterlockedIncrement((PLONG)&Vcb->VcbReference);
InterlockedDecrement((int32*)counter);

// After
InterlockedIncrement(&Vcb->VcbReference);
InterlockedDecrement(counter);

Bug fix: mixed signed/unsigned comparisons

Mismatched types between LONG reference fields and their ULONG companions caused implicit sign-to-unsigned conversions in comparisons. A negative value (indicating an over-release bug) would silently appear as a large positive number and pass assertions:

Expression Before After
FcbCleanup <= (FcbReference - 1) ULONG <= LONG ⚠️ LONG <= LONG
VcbReference -= VcbResidualReference LONG -= ULONG ⚠️ LONG -= LONG
VcbReference <= VcbResidualReference LONG <= ULONG ⚠️ LONG <= LONG
Original prompt

This section details on the original issue you should resolve

<issue_title>[UDFS] Is there any benefit to simplifying the usage of the Interlocked functions that it uses?</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Copilot AI changed the title [WIP] [UDFS] Simplify usage of Interlocked functions [UDFS] Simplify Interlocked function usage by using LONG field types Mar 12, 2026
Copilot AI requested a review from Zero3K20 March 12, 2026 17:23
…ter fields to LONG

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Copilot AI changed the title [UDFS] Simplify Interlocked function usage by using LONG field types [UDFS] Use LONG for reference/counter fields to eliminate Interlocked casts and fix mixed sign-type comparisons Mar 12, 2026
Copilot AI added a commit that referenced this pull request Mar 12, 2026
…move Interlocked casts

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
@Zero3K20 Zero3K20 closed this Mar 31, 2026
@Zero3K20 Zero3K20 deleted the copilot/udfs-simplify-interlocked-functions branch April 4, 2026 19:41
Copilot AI added a commit that referenced this pull request Apr 16, 2026
…terlocked casts

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants