Minor follow-up initrd feedback items (#14186)

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>

Ben Hillis committed Feb 9, 2026 at 13:39 UTC ae39345d90ea9331b5ff19ce9d0284487cb20b45
4 files changed +13 -11
.gitignore
+4 -3
@@ -10,7 +10,6 @@ tmp
10 *.user
11 *.csproj
12 *.vcxproj
13 -*.targets
13 *.filters
14 *.pdb
15 *.lib
@@ -42,7 +41,6 @@ linux/init
41 initrd/init
42 bin/
43 *.nupkg
45 -build/
44 generated/
45 *.nuspec
46 test/linux/unit_tests/wsl_unit_tests
@@ -65,4 +63,7 @@ package/x64
63 /appx-logs.txt
64 tools/clang-format.exe
65 /linux-crashes
68 -doc/site/
\ No newline at end of file
66 +doc/site/
67 +directory.build.targets
68 +test-storage/
69 +*.vhdx
\ No newline at end of file
msipackage/package.wix.in
+1 -2
@@ -540,8 +540,7 @@
540 <!-- This needs to run after the registry is written because this action needs to read the install path -->
541 <Custom Action="RegisterLspCategories" After="WriteRegistryValues" Condition='((not REMOVE~="ALL") or WIX_UPGRADE_DETECTED) and (not UPGRADINGPRODUCTCODE) and (not SKIPLSP = 1)' />
542
543 - <!-- Generate initrd.img from the init binary during installation.
544 - Only run when the tools component is being installed ($tools=3), not during same-version reinstalls -->
543 + <!-- Generate initrd.img from the init binary whenever the tools component is being installed -->
544 <Custom Action="CreateInitrd" After="RegisterLspCategories" Condition='$tools=3' />
545
546 <!-- This needs to run before the registry is cleared because this action needs to read the install path.
src/windows/common/filesystem.cpp
+5 -3
@@ -1143,6 +1143,7 @@ void wsl::windows::common::filesystem::CreateCpioInitrd(_In_ const std::filesyst
1143 constexpr size_t headerSize = 110;
1144 const auto nameLen = strlen(name) + 1;
1145 const auto headerPadding = (4 - ((headerSize + nameLen) % 4)) % 4;
1146 + const bool isTrailer = strcmp(name, "TRAILER!!!") == 0;
1147
1148 // Get current time for mtime. CPIO newc format only supports 32-bit fields.
1149 const auto mtime = static_cast<DWORD>(time(nullptr));
@@ -1165,10 +1166,10 @@ void wsl::windows::common::filesystem::CreateCpioInitrd(_In_ const std::filesyst
1166 "%08X" // namesize
1167 "%08X", // check
1168 0,
1168 - (fileSize > 0) ? 0100755 : 0,
1169 + isTrailer ? 0 : 0100755,
1170 0,
1171 0,
1171 - (fileSize > 0) ? 1 : 0,
1172 + isTrailer ? 0 : 1,
1173 mtime,
1174 fileSize,
1175 0,
@@ -1214,7 +1215,8 @@ void wsl::windows::common::filesystem::CreateCpioInitrd(_In_ const std::filesyst
1215 LARGE_INTEGER currentPos{};
1216 THROW_IF_WIN32_BOOL_FALSE(SetFilePointerEx(destFile.get(), {}, &currentPos, FILE_CURRENT));
1217
1217 - const auto archivePadding = (archiveBlockSize - (currentPos.LowPart % archiveBlockSize)) % archiveBlockSize;
1218 + const auto currentSize = static_cast<ULONGLONG>(currentPos.QuadPart);
1219 + const auto archivePadding = static_cast<DWORD>((archiveBlockSize - (currentSize % archiveBlockSize)) % archiveBlockSize);
1220 if (archivePadding > 0)
1221 {
1222 char paddingBuffer[archiveBlockSize] = {0};
test/windows/SimpleTests.cpp
+3 -3
@@ -325,10 +325,10 @@ class SimpleTests
325 THROW_IF_WIN32_BOOL_FALSE(GetFileSizeEx(cpioHandle.get(), &cpioSize));
326 VERIFY_ARE_EQUAL(cpioSize.QuadPart % 512, 0LL); // Archive padded to 512-byte boundary
327
328 - char header[110] = {};
328 + char header[111] = {};
329 DWORD bytesRead;
330 - THROW_IF_WIN32_BOOL_FALSE(ReadFile(cpioHandle.get(), header, sizeof(header), &bytesRead, nullptr));
331 - VERIFY_ARE_EQUAL(bytesRead, static_cast<DWORD>(sizeof(header)));
330 + THROW_IF_WIN32_BOOL_FALSE(ReadFile(cpioHandle.get(), header, 110, &bytesRead, nullptr));
331 + VERIFY_ARE_EQUAL(bytesRead, 110u);
332
333 // Parse CPIO newc header: magic(6) ino mode uid gid nlink mtime filesize devmajor devminor rdevmajor rdevminor namesize check
334 DWORD fileSize, nameSize;