Skip to content

[UDFS] Fix C bool literals, add typedef aliases, remove legacy x86 asm paths, thread PH_TMP_BUFFER through sector I/O, and add chunked bitmap infrastructure#275

Closed
Copilot wants to merge 43 commits into
writefrom
copilot/apply-assorted-pull-requests
Closed

[UDFS] Fix C bool literals, add typedef aliases, remove legacy x86 asm paths, thread PH_TMP_BUFFER through sector I/O, and add chunked bitmap infrastructure#275
Copilot wants to merge 43 commits into
writefrom
copilot/apply-assorted-pull-requests

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 16, 2026

Fixes several C compatibility issues in the UDFS driver after its conversion from C++ to C, and applies the cleanup changes from PR #277, PR #281, and PR #283.

Changes Made

  • write.c / read.c: Fixed C++ bool literals trueTRUE (C uses TRUE/FALSE from <windef.h>)
  • struct.h: Added missing typedef struct Foo Foo; aliases for all 13 struct types (UDFIdentifier, UDFObjectName, CCB, FCB_NONPAGED, FCB_DATA, FCB_INDEX, FCB, VCB, VOLUME_DEVICE_OBJECT, THREAD_CONTEXT, IRP_CONTEXT, IRP_CONTEXT_LITE, IO_CONTEXT) and replaced C++ using aliases with typedef for PCCB and PIRP_CONTEXT_LITE; changed Vat field type from uint32* to PCHAR to support chunked access
  • udf_dbg.h: Added #define UDFBreakPoint() __debugbreak() replacing the #ifdef _X86_ / __asm int 3 block; replaced the x86-specific UDFTouch asm implementation with a single portable version using volatile UCHAR + UNREFERENCED_PARAMETER
  • mem_tools.c: Removed #ifdef _X86_ DbgTouch asm branch; single C implementation kept using volatile UCHAR and (void)a
  • mem_tools.h: Replaced three __asm int 3 occurrences with __debugbreak() in MyFreePool__() and MyReallocPool__()
  • Sys_spec_lib.c / string_lib.c: Removed x86 MSVC inline asm string-length loops from MyAppendUnicodeToString_, MyInitUnicodeString, and RtlAppendUnicodeToString; changed loop counter from USHORT to ULONG, added i < (MAXUSHORT / sizeof(WCHAR)) overflow guard, and added (USHORT) casts on assignments to Str1->Length and Str1->MaximumLength
  • phys_lib.h / phys_lib.c: Added Flags parameter to UDFReadSectors and UDFWriteSectors; call sites that use a local temporary buffer now pass PH_TMP_BUFFER to skip the unnecessary NonPagedPool copy in UDFPhReadSynchronous/UDFPhWriteSynchronous
  • mount.c / udf_info.c: Updated all call sites of UDFReadSectors/UDFWriteSectors to pass the appropriate Flags value (PH_TMP_BUFFER where a local buffer is already provided, 0 otherwise)
  • udf_info/udf_info.h: Added chunked bitmap infrastructure (UDF_CHUNK_SHIFT=17, UDF_CHUNKED_BUF struct, and inline helpers UDFAllocChunked, UDFFreeChunked, UDFReadExtentIntoChunked, UDFWriteExtentFromChunked, UDFChunkedCopyMemory, UDFChunkedCompareMemory, UDFVatGetEntry, UDFVatSetEntry); updated UDFGetBit/SetBit/ClrBit/GetFreeBit/SetFreeBit macros to use chunked-aware access
  • udffs.h: Moved UDFPrint macro definition before the udf_info/udf_info.h include to resolve ordering dependency
  • fscntrl.c: Replaced DbgFreePool with UDFFreeChunked for Vat, FSBM_Bitmap, BSBM_Bitmap, and FSBM_OldBitmap fields on volume teardown
  • udf_info/alloc.c: Switched bitmap access in UDFGetBitmapLen, UDFMarkBadSpaceAsUsed, UDFMarkSpaceAsXXX, and UDFGetPartFreeSpace to use the chunked API
  • udf_info/mount.c: Replaced direct NonPagedPool bitmap allocations with UDFAllocChunked/UDFReadExtentIntoChunked/UDFWriteExtentFromChunked/UDFChunkedCopyMemory/UDFChunkedCompareMemory to reduce mount-time NonPagedPool pressure
  • udf_info/remap.c: Replaced direct VAT array indexing with UDFVatGetEntry to support chunked VAT storage
  • udf_info/udf_info.c: Updated VAT read/write paths to use PCHAR type and UDFVatGetEntry/UDFVatSetEntry/UDFChunkedCopyMemory

Copilot AI and others added 2 commits April 16, 2026 05:44
Copilot AI changed the title [WIP] Apply all pull requests from assorted/reactos [DDK/scsi] Move nested struct typedefs out of anonymous unions for UDFS C++ compatibility Apr 16, 2026
Copilot AI requested a review from Zero3K20 April 16, 2026 05:46
Copilot AI and others added 14 commits April 16, 2026 05:52
…onymous unions

Restore _PLAY_CD and _LOG_PARAMETER to have nested struct definitions
inside the anonymous union bodies (original ReactOS style), superseded
by the C++ to C conversion PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Directories need to be converted to external allocation on first write
to allow for preallocation and efficient growth. Only regular files
should stay in inline (IN_ICB) mode during writes.

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Removed directory exclusion from inline preservation logic. Small
directories (with few entries) can now stay in IN_ICB mode just like
small files. When directories grow beyond inline capacity, they are
converted to external allocation with optional preallocation.

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Added ExtPrint messages to clearly show:
- When data is in IN_ICB vs EXTERNAL mode
- When converting from IN_ICB to external allocation

This will help diagnose issues with inline data handling.

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
When files or directories with inline (IN_ICB) data are deleted, the
actual data content must be zeroed before freeing the FileEntry space.
This prevents sensitive data from remaining in freed sectors where it
could potentially be recovered.

Changes:
- Added inline data wiping in UDFUnlinkFile__ before flushing
- Zeros the data area at DataLoc.Offset for DataLoc.Length bytes
- Marks FE as modified to ensure zeroed data is written to disk
- Adds bounds checking to prevent buffer overflow

Security impact: Prevents data leakage from deleted inline files.

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Simplify APC check to KeGetCurrentIrql() >= APC_LEVEL

Co-Authored-By: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
…rites

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
…terlocked casts

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
@Zero3K20
Copy link
Copy Markdown
Owner

@copilot Please undo the spacing changes done to scsi.h.

Copy link
Copy Markdown
Author

Copilot AI commented Apr 16, 2026

@copilot Please undo the spacing changes done to scsi.h.

Done in 582a2ad — restored the three blank lines between SELF_TEST_RESULTS/SOLID_STATE_MEDIA, SOLID_STATE_MEDIA/BACKGROUND_SCAN_STATUS, and BACKGROUND_SCAN_STATUS/INFORMATIONAL_EXCEPTIONS that were inadvertently removed. scsi.h is now byte-for-byte identical to the original base.

Copilot AI and others added 20 commits April 22, 2026 01:38
Initialize all uninitialized local variables in the UDFS driver to
prevent MSVC debug builds from filling them with 0xCCCCCCCC:
- NTSTATUS/NTSTATUS variables initialized to STATUS_SUCCESS
- BOOLEAN variables initialized to FALSE
- ULONG/pointer variables initialized to 0/NULL

Also restore accidentally removed code:
- if (!FileInfo) check in UDFIndexDirectory (dirtree.cpp)
- PUDF_FILE_INFO curFileInfo declaration in UDFPackDirectory__ (dirtree.cpp)
- PAGED_CODE() calls in misc.cpp and volinfo.cpp
- Comment in misc.cpp AcquireResource function

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/901376db-4acd-42eb-8122-cce62735117e

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Initialize all uninitialized local variables in the Include/ support
files: Sys_spec_lib.cpp, phys_lib.cpp, regtools.cpp, mem_tools.cpp,
string_lib.cpp. Covers NTSTATUS, BOOLEAN, ULONG, and pointer variables.

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/a5f32228-fa19-4fba-bf7a-cdde18e904ec

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/d748e799-c061-440b-a45e-8e688426533a

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Applies changes from PR#25:
- Fix large I/O INSUFFICIENT_RESOURCES on XP/2003 by using MmCreateMdl
- Remove unnecessary scope block around IrpSp in write path
- Fix PFN_LIST_CORRUPT BSOD: use MmProbeAndLockPages
- Wrap MmProbeAndLockPages in SEH2 exception handler
- Add comments explaining IoWriteAccess/IoReadAccess
- Fall back to using Buffer directly when NonPagedPool copy allocation fails
- Remove unreachable null check after Buffer
- Fix UDFLockUserBuffer to use MmCreateMdl

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
- Rename all .cpp files to .c files
- Fix C++ constructs incompatible with C (casts, default parameters, etc.)
- Fix MSVC C compilation errors: empty structs, enum types, etc.
- Fix MinGW/GCC build errors: remove C++-only flags
- Fix static/inline conflicts in mem_tools.h
- Fix stale .cpp include references after renaming
- Fix mixed SEH macro nesting in UDFGetVolumeBitmap
- Fix multiple definition issues for MyAllocInit and other symbols
- Fix compiler warnings in filesystem driver
- Update CMakeLists.txt to use .c files and proper compile flags

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/ec18699c-68b2-4e23-bf16-4d8148a2f398

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
… C compilation errors

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/9e8e5bf2-5af6-451c-bde1-f711f94ce023

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
… __debugbreak()

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/c974a8bc-1af0-4576-a1db-2cba7bd89376

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
…WriteSectors

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/da7f3da2-2510-48c8-b4de-ee7c50126380
Co-Authored-By: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
@Zero3K20 Zero3K20 force-pushed the copilot/apply-assorted-pull-requests branch from b3d5d3a to d83aa55 Compare April 22, 2026 05:51
@Zero3K20
Copy link
Copy Markdown
Owner

@copilot Please add the changes done by PR #283.

Copilot AI and others added 3 commits April 23, 2026 13:35
…antics

Add UDF_CHUNKED_BUF: a lazily-allocated chunk array where each chunk is
allocated on first write (NULL chunk = all zeros = all FREE). A pointer
tagging scheme (UDF_CHUNKED_PTR_TAG = bit 0) lets PCHAR Vat/FSBM_Bitmap
fields distinguish flat vs. chunked allocations via UDFIsChunked().

New infrastructure in udf_info.h:
- UDFAllocChunked / UDFFreeChunked for lifecycle management
- UDFChunkedGetBytePtr / UDFChunkedGetOrAllocBytePtr for read/write access
- UDFChunkedFillMemory, UDFChunkedCopyMemory, UDFChunkedAndNotMemory,
  UDFChunkedOrMemory, UDFChunkedCompareMemory for bulk operations
- UDFVatGetEntry / UDFVatSetEntry for VAT element access
- UDFReadExtentIntoChunked / UDFWriteExtentFromChunked for disk I/O
- UDFSetBit/UDFClrBit/UDFGetBit dispatch to chunked or flat paths
- UDFSetBits/UDFClrBits use UDFChunkedFillMemory for the fast-path byte
  fill (replaces RtlFillMemory/RtlZeroMemory that would corrupt chunked ptrs)

Invert FSBM bit semantics: bit=1=USED, bit=0=FREE (was bit=1=FREE).
This matches the null-chunk default (all zeros = all FREE), so chunk
allocation is only triggered when marking blocks USED, keeping memory
usage minimal for mostly-free large disks.

Update all call sites:
- struct.h: uint32* Vat -> PCHAR Vat
- fscntrl.c: Vat/FSBM_Bitmap/BSBM_Bitmap/FSBM_OldBitmap freed via
  UDFFreeChunked
- alloc.c: UDFGetBitmapLen handles chunked; VAT accesses use
  UDFVatGetEntry/UDFVatSetEntry; UDFMarkBadSpaceAsUsed uses
  UDFChunkedOrMemory; UDFGetPartFreeSpace uses UDFChunkedGetByte
- mount.c: bitmap allocation/copy/compare/free updated throughout;
  UDFBuildFreeSpaceBitmap uses UDFAllocChunked
- remap.c: VAT access via UDFVatGetEntry
- udf_info.c: VAT fill/read/write via UDFVatSetEntry/UDFVatGetEntry
- udffs.h: UDFPrint/UDFPrintErr macros moved before udf_info.h include
  so inline functions in the header can reference them

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Match the PR diff exactly:
- Use RtlFillMemory(&(((uint32*)Vcb->Vat)[...]) for bulk fill
- Use ((uint32*)Vcb->Vat)[i] for direct array access in sync loop
- Use ((uint32*)Vcb->Vat)[CurLba] = NWA in UDFUpdateVAT

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Remove redundant re-assignment of i inside UDFAllocChunked call;
use the already-computed value from the preceding line.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Apr 23, 2026

@copilot Please add the changes done by PR #283.

Done in abace10. Applied all changes from PR #283:

  • udf_info/udf_info.h: Added full chunked bitmap infrastructure — UDF_CHUNKED_BUF struct with pointer tagging, UDFAllocChunked/UDFFreeChunked (lazy chunk allocation), byte/bit accessors (UDFChunkedGetByte, UDFChunkedSetBit, etc.), memory ops (UDFChunkedCopyMemory, UDFChunkedCompareMemory, UDFChunkedOrMemory), I/O helpers (UDFReadExtentIntoChunked, UDFWriteExtentFromChunked), VAT accessors (UDFVatGetEntry, UDFVatSetEntry); updated UDFGetBit/UDFSetBit/UDFClrBit to dispatch chunked vs flat; inverted FSBM semantics (bit=1=USED, bit=0=FREE so null chunks = all free)
  • udffs.h: Moved UDFPrint/UDFPrintErr macros before #include "udf_info/udf_info.h" so inline functions can reference them
  • struct.h: Changed uint32* VatPCHAR Vat
  • fscntrl.c: Replaced DbgFreePool with UDFFreeChunked for Vat/FSBM/BSBM bitmaps
  • udf_info/alloc.c: Chunked-aware UDFGetBitmapLen, UDFMarkBadSpaceAsUsed via UDFChunkedOrMemory, VAT ops via accessors, UDFGetPartFreeSpace via UDFChunkedGetByte
  • udf_info/mount.c: UDFAllocChunked for bitmaps, sector-by-sector loading in UDFAddXSpaceBitmap, UDFWriteExtentFromChunked, UDFChunkedCompareMemory/UDFChunkedCopyMemory
  • udf_info/remap.c: VAT access via UDFVatGetEntry
  • udf_info/udf_info.c: PCHAR Vat type, UDFVatSetEntry for init, direct casts for RtlFillMemory

Copilot AI changed the title [UDFS] Fix C bool literals, add typedef aliases, remove legacy x86 asm paths, and thread PH_TMP_BUFFER through sector I/O [UDFS] Fix C bool literals, add typedef aliases, remove legacy x86 asm paths, thread PH_TMP_BUFFER through sector I/O, and add chunked bitmap infrastructure Apr 23, 2026
@Zero3K20 Zero3K20 closed this Apr 27, 2026
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.

[UDFS] Please apply all of the pull requests from assorted/reactos

2 participants