Skip to content

Commit ae39345

Browse files
benhillisBen Hillis
andauthored
Minor follow-up initrd feedback items (#14186)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
1 parent 0e263df commit ae39345

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ tmp
1010
*.user
1111
*.csproj
1212
*.vcxproj
13-
*.targets
1413
*.filters
1514
*.pdb
1615
*.lib
@@ -42,7 +41,6 @@ linux/init
4241
initrd/init
4342
bin/
4443
*.nupkg
45-
build/
4644
generated/
4745
*.nuspec
4846
test/linux/unit_tests/wsl_unit_tests
@@ -65,4 +63,7 @@ package/x64
6563
/appx-logs.txt
6664
tools/clang-format.exe
6765
/linux-crashes
68-
doc/site/
66+
doc/site/
67+
directory.build.targets
68+
test-storage/
69+
*.vhdx

msipackage/package.wix.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@
540540
<!-- This needs to run after the registry is written because this action needs to read the install path -->
541541
<Custom Action="RegisterLspCategories" After="WriteRegistryValues" Condition='((not REMOVE~="ALL") or WIX_UPGRADE_DETECTED) and (not UPGRADINGPRODUCTCODE) and (not SKIPLSP = 1)' />
542542

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 -->
545544
<Custom Action="CreateInitrd" After="RegisterLspCategories" Condition='$tools=3' />
546545

547546
<!-- This needs to run before the registry is cleared because this action needs to read the install path.

src/windows/common/filesystem.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ void wsl::windows::common::filesystem::CreateCpioInitrd(_In_ const std::filesyst
11431143
constexpr size_t headerSize = 110;
11441144
const auto nameLen = strlen(name) + 1;
11451145
const auto headerPadding = (4 - ((headerSize + nameLen) % 4)) % 4;
1146+
const bool isTrailer = strcmp(name, "TRAILER!!!") == 0;
11461147

11471148
// Get current time for mtime. CPIO newc format only supports 32-bit fields.
11481149
const auto mtime = static_cast<DWORD>(time(nullptr));
@@ -1165,10 +1166,10 @@ void wsl::windows::common::filesystem::CreateCpioInitrd(_In_ const std::filesyst
11651166
"%08X" // namesize
11661167
"%08X", // check
11671168
0,
1168-
(fileSize > 0) ? 0100755 : 0,
1169+
isTrailer ? 0 : 0100755,
11691170
0,
11701171
0,
1171-
(fileSize > 0) ? 1 : 0,
1172+
isTrailer ? 0 : 1,
11721173
mtime,
11731174
fileSize,
11741175
0,
@@ -1214,7 +1215,8 @@ void wsl::windows::common::filesystem::CreateCpioInitrd(_In_ const std::filesyst
12141215
LARGE_INTEGER currentPos{};
12151216
THROW_IF_WIN32_BOOL_FALSE(SetFilePointerEx(destFile.get(), {}, &currentPos, FILE_CURRENT));
12161217

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);
12181220
if (archivePadding > 0)
12191221
{
12201222
char paddingBuffer[archiveBlockSize] = {0};

test/windows/SimpleTests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ class SimpleTests
325325
THROW_IF_WIN32_BOOL_FALSE(GetFileSizeEx(cpioHandle.get(), &cpioSize));
326326
VERIFY_ARE_EQUAL(cpioSize.QuadPart % 512, 0LL); // Archive padded to 512-byte boundary
327327

328-
char header[110] = {};
328+
char header[111] = {};
329329
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);
332332

333333
// Parse CPIO newc header: magic(6) ino mode uid gid nlink mtime filesize devmajor devminor rdevmajor rdevminor namesize check
334334
DWORD fileSize, nameSize;

0 commit comments

Comments
 (0)