test(drvfs): add O_APPEND ftruncate coverage, skip on virtiofs (#41032)
Adds an ftruncate-on-O_APPEND check to the drvfs Basic test. It runs on plan9 (passes) and is skipped on virtiofs, which currently fails with EACCES due to a wsldevicehost bug (microsoft/WSL#40987): the Windows lxutil file server strips FILE_WRITE_DATA for O_APPEND, so SetEndOfFile is denied. A TODO in packages.config tracks removing the skip once an updated Microsoft.WSL.DeviceHost package ships the fix. Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Ben Hillis committed
Jul 8, 2026 at 13:19 UTC
45b8f8e6e8efd62caf0518fdb1a6bf5886eb7b47
2 files changed
+27
packages.config
+1
@@ -19,6 +19,7 @@
19
<package id="Microsoft.WSL.bsdtar" version="0.0.2-2" />
20
<package id="Microsoft.WSL.Dependencies.amd64fre" version="10.0.27820.1000-250318-1700.rs-base2-hyp" targetFramework="native" />
21
<package id="Microsoft.WSL.Dependencies.arm64fre" version="10.0.27820.1000-250318-1700.rs-base2-hyp" targetFramework="native" />
22
+ <!-- TODO: Bump to an updated Microsoft.WSL.DeviceHost that includes the virtiofs O_APPEND ftruncate (EACCES) fix, then remove the virtiofs skip on the ftruncate check in test/linux/unit_tests/drvfs.c (DrvFsTestBasic). See microsoft/WSL#40987. -->
23
<package id="Microsoft.WSL.DeviceHost" version="1.2.39-0" />
24
<package id="Microsoft.WSL.Kernel" version="6.18.35.2-1" targetFramework="native" />
25
<package id="Microsoft.WSL.LinuxSdk" version="1.20.0" targetFramework="native" />
test/linux/unit_tests/drvfs.c
+26
@@ -1069,6 +1069,32 @@ Return Value:
1069
LxtCheckErrnoZeroSuccess(stat(DRVFS_BASIC_PREFIX "/test", &Stat));
1070
LxtCheckEqual(Stat.st_size, 11, "%lld");
1071
1072
+ //
1073
+ // Verify ftruncate succeeds on a descriptor opened with O_APPEND | O_WRONLY.
1074
+ // Regression test for a virtiofs bug where ftruncate returned EACCES on an
1075
+ // append-mode descriptor (GitHub issue #40987).
1076
+ //
1077
+ // TODO: Remove the virtiofs skip once the wsldevicehost fix ships (the
1078
+ // Windows lxutil file server strips FILE_WRITE_DATA for O_APPEND, causing
1079
+ // SetEndOfFile to fail with access denied).
1080
+ //
1081
+
1082
+ if (g_LxtFsInfo.FsType == LxtFsTypeVirtioFs)
1083
+ {
1084
+ LxtLogInfo("Skipping O_APPEND ftruncate test on virtiofs (see GitHub issue #40987).");
1085
+ }
1086
+ else
1087
+ {
1088
+ LxtCheckErrno(Fd = open(DRVFS_BASIC_PREFIX "/test", O_WRONLY | O_APPEND, 0666));
1089
+ LxtCheckErrno(Size = write(Fd, "hello", 5));
1090
+ LxtCheckEqual(Size, 5, "%ld");
1091
+ LxtCheckErrnoZeroSuccess(ftruncate(Fd, 0));
1092
+ LxtCheckErrnoZeroSuccess(ftruncate(Fd, 1));
1093
+ LxtCheckClose(Fd);
1094
+ LxtCheckErrnoZeroSuccess(stat(DRVFS_BASIC_PREFIX "/test", &Stat));
1095
+ LxtCheckEqual(Stat.st_size, 1, "%lld");
1096
+ }
1097
+
1098
//
1099
// Creating/removing items relative to the current working directory.
1100
//