- From d14f195057c89bacd22953cae76f6af2840bfbd6 Mon Sep 17 00:00:00 2001
- From: Cedric Blancher <cedric.blancher@gmail.com>
- Date: Tue, 30 Sep 2025 13:12:44 +0200
- Subject: [PATCH 1/4] tests: Fix Windows 10/32bit+Cygwin3.3 build failures
- Fix Windows 10/32bit+Cygwin3.3 build failures.
- Signed-off-by: Roland Mainz <roland.mainz@nrubsig.org>
- ---
- tests/ea/Makefile | 4 ++--
- tests/winfsinfo1/winfsinfo.c | 39 +++++++++++++++++++++++++++++++++++-
- 2 files changed, 40 insertions(+), 3 deletions(-)
- diff --git a/tests/ea/Makefile b/tests/ea/Makefile
- index e24e0dc..e647cb6 100644
- --- a/tests/ea/Makefile
- +++ b/tests/ea/Makefile
- @@ -8,11 +8,11 @@ SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/sign
- all: nfs_ea.i686.exe nfs_ea.x86_64.exe nfs_ea.exe
- nfs_ea.i686.exe: main.c
- - clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
- + clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DSTRSAFE_NO_DEPRECATE=1 -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
- bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
- nfs_ea.x86_64.exe: main.c
- - clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
- + clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DSTRSAFE_NO_DEPRECATE=1 -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
- bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
- nfs_ea.exe: nfs_ea.x86_64.exe
- diff --git a/tests/winfsinfo1/winfsinfo.c b/tests/winfsinfo1/winfsinfo.c
- index b36fc6f..ab9ced3 100644
- --- a/tests/winfsinfo1/winfsinfo.c
- +++ b/tests/winfsinfo1/winfsinfo.c
- @@ -504,14 +504,30 @@ int get_file_basic_info(const char *progname, const char *filename)
- TESTFBIA(FILE_ATTRIBUTE_OFFLINE);
- TESTFBIA(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
- TESTFBIA(FILE_ATTRIBUTE_ENCRYPTED);
- +#ifdef FILE_ATTRIBUTE_INTEGRITY_STREAM
- TESTFBIA(FILE_ATTRIBUTE_INTEGRITY_STREAM);
- +#endif /* FILE_ATTRIBUTE_INTEGRITY_STREAM */
- +#ifdef FILE_ATTRIBUTE_VIRTUAL
- TESTFBIA(FILE_ATTRIBUTE_VIRTUAL);
- +#endif /* FILE_ATTRIBUTE_VIRTUAL */
- +#ifdef FILE_ATTRIBUTE_NO_SCRUB_DATA
- TESTFBIA(FILE_ATTRIBUTE_NO_SCRUB_DATA);
- +#endif /* FILE_ATTRIBUTE_NO_SCRUB_DATA */
- +#ifdef FILE_ATTRIBUTE_EA
- TESTFBIA(FILE_ATTRIBUTE_EA);
- +#endif /* FILE_ATTRIBUTE_EA */
- +#ifdef FILE_ATTRIBUTE_PINNED
- TESTFBIA(FILE_ATTRIBUTE_PINNED);
- +#endif /* FILE_ATTRIBUTE_PINNED */
- +#ifdef FILE_ATTRIBUTE_UNPINNED
- TESTFBIA(FILE_ATTRIBUTE_UNPINNED);
- +#endif /* FILE_ATTRIBUTE_UNPINNED */
- +#ifdef FILE_ATTRIBUTE_RECALL_ON_OPEN
- TESTFBIA(FILE_ATTRIBUTE_RECALL_ON_OPEN);
- +#endif /* FILE_ATTRIBUTE_RECALL_ON_OPEN */
- +#ifdef FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS
- TESTFBIA(FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS);
- +#endif /* FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS */
- /*
- * print any leftover flags not covered by |TESTFBIA(FILE_*)|
- @@ -602,14 +618,30 @@ int get_fileexinfostandard(const char *progname, const char *filename)
- TESTFEIS(FILE_ATTRIBUTE_OFFLINE);
- TESTFEIS(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
- TESTFEIS(FILE_ATTRIBUTE_ENCRYPTED);
- +#ifdef FILE_ATTRIBUTE_INTEGRITY_STREAM
- TESTFEIS(FILE_ATTRIBUTE_INTEGRITY_STREAM);
- +#endif /* FILE_ATTRIBUTE_INTEGRITY_STREAM */
- +#ifdef FILE_ATTRIBUTE_VIRTUAL
- TESTFEIS(FILE_ATTRIBUTE_VIRTUAL);
- +#endif /* FILE_ATTRIBUTE_VIRTUAL */
- +#ifdef FILE_ATTRIBUTE_NO_SCRUB_DATA
- TESTFEIS(FILE_ATTRIBUTE_NO_SCRUB_DATA);
- +#endif /* FILE_ATTRIBUTE_NO_SCRUB_DATA */
- +#ifdef FILE_ATTRIBUTE_EA
- TESTFEIS(FILE_ATTRIBUTE_EA);
- +#endif /* FILE_ATTRIBUTE_EA */
- +#ifdef FILE_ATTRIBUTE_PINNED
- TESTFEIS(FILE_ATTRIBUTE_PINNED);
- +#endif /* FILE_ATTRIBUTE_PINNED */
- +#ifdef FILE_ATTRIBUTE_UNPINNED
- TESTFEIS(FILE_ATTRIBUTE_UNPINNED);
- +#endif /* FILE_ATTRIBUTE_UNPINNED */
- +#ifdef FILE_ATTRIBUTE_RECALL_ON_OPEN
- TESTFEIS(FILE_ATTRIBUTE_RECALL_ON_OPEN);
- +#endif /* FILE_ATTRIBUTE_RECALL_ON_OPEN */
- +#ifdef FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS
- TESTFEIS(FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS);
- +#endif /* FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS */
- /*
- * print any leftover flags not covered by |TESTFNOI(FILE_*)|
- @@ -798,7 +830,7 @@ done:
- return res;
- }
- -
- +#ifdef FILE_CS_FLAG_CASE_SENSITIVE_DIR
- static
- int get_filecasesensitiveinfo(const char *progname, const char *filename)
- {
- @@ -863,6 +895,7 @@ done:
- (void)CloseHandle(fileHandle);
- return res;
- }
- +#endif /* FILE_CS_FLAG_CASE_SENSITIVE_DIR */
- static
- int get_getfiletime(const char *progname, const char *filename)
- @@ -1461,7 +1494,9 @@ void usage(void)
- "filestandardinfo|"
- "filenameinfo|"
- "filenormalizednameinfo|"
- +#ifdef FILE_CS_FLAG_CASE_SENSITIVE_DIR
- "filecasesensitiveinfo|"
- +#endif /* FILE_CS_FLAG_CASE_SENSITIVE_DIR */
- "getfiletime|"
- "nfs3attr|"
- "fileremoteprotocolinfo|"
- @@ -1529,9 +1564,11 @@ int main(int ac, char *av[])
- else if (!strcmp(subcmd, "getfiletime")) {
- return get_getfiletime(av[0], av[2]);
- }
- +#ifdef FILE_CS_FLAG_CASE_SENSITIVE_DIR
- else if (!strcmp(subcmd, "filecasesensitiveinfo")) {
- return get_filecasesensitiveinfo(av[0], av[2]);
- }
- +#endif /* FILE_CS_FLAG_CASE_SENSITIVE_DIR */
- else if (!strcmp(subcmd, "nfs3attr")) {
- return get_nfs3attr(av[0], av[2]);
- }
- --
- 2.51.0
- From e99970a349215e8baa5eb4b9d038f382a70f1a50 Mon Sep 17 00:00:00 2001
- From: Cedric Blancher <cedric.blancher@gmail.com>
- Date: Tue, 30 Sep 2025 13:42:38 +0200
- Subject: [PATCH 2/4] tests: nfsbuildtest.ksh93: Fix VS2019 PATH on Windows
- 10/32bit
- Fix VS2019 PATH on Windows 10/32bit.
- Signed-off-by: Roland Mainz <roland.mainz@nrubsig.org>
- ---
- tests/nfsbuildtest/nfsbuildtest.ksh93 | 9 +++++++--
- 1 file changed, 7 insertions(+), 2 deletions(-)
- diff --git a/tests/nfsbuildtest/nfsbuildtest.ksh93 b/tests/nfsbuildtest/nfsbuildtest.ksh93
- index 234f09f..37024cb 100644
- --- a/tests/nfsbuildtest/nfsbuildtest.ksh93
- +++ b/tests/nfsbuildtest/nfsbuildtest.ksh93
- @@ -552,9 +552,14 @@ function msnfs41client_build
- time make -j1 -f cygwin/Makefile build64
- time make -j1 -f cygwin/Makefile installdest64
- time make -j1 -f cygwin/Makefile bintarball64
- - elif [[ -x '/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe' ]] ; then
- + elif [[ -x '/cygdrive/c/Program Files/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe' || \
- + -x '/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe' ]] ; then
- # Visual Studio 19 64bit+32bit kernel codepath
- - export PATH="/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/:$PATH"
- + if [[ -x '/cygdrive/c/Program Files/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe' ]] ; then
- + export PATH="/cygdrive/c/Program Files/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/:$PATH"
- + else
- + export PATH="/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/:$PATH"
- + fi
- set -o errexit
- time make -j1 -f cygwin/Makefile build
- time make -j1 -f cygwin/Makefile installdest
- --
- 2.51.0
- From d3f5ad7eab174c6dea6a578063f6ed90b5ba5e92 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Tue, 30 Sep 2025 17:23:38 +0200
- Subject: [PATCH 3/4] daemon: Fix "ASSERTION 'length == 0' in
- '...\ms-nfs41-client\daemon\lock.c'/316 failed."
- Fix "ASSERTION 'length == 0' in '...\ms-nfs41-client\daemon\lock.c'/316 failed.".
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/lock.c | 6 +++---
- 1 file changed, 3 insertions(+), 3 deletions(-)
- diff --git a/daemon/lock.c b/daemon/lock.c
- index 4066796..d41ef2c 100644
- --- a/daemon/lock.c
- +++ b/daemon/lock.c
- @@ -312,12 +312,12 @@ static int parse_unlock(unsigned char *buffer, uint32_t length, nfs41_upcall *up
- status = safe_read(&buffer, &length, &args->count, sizeof(ULONG));
- if (status) goto out;
- + args->buf_len = args->count*2L*sizeof(LONGLONG);
- + status = get_safe_read_bufferpos(&buffer, &length, args->buf_len, &args->buf);
- + if (status) goto out;
- EASSERT(length == 0);
- - args->buf = buffer;
- - args->buf_len = length;
- -
- DPRINTF(1, ("parsing NFS41_SYSOP_UNLOCK: count=%u\n", args->count));
- out:
- return status;
- --
- 2.51.0
- From 583cb2a64714fd0c50d70d5ec4f8bc1dc4aff67d Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Tue, 30 Sep 2025 20:23:04 +0200
- Subject: [PATCH 4/4] cygwin,tests: Add new Win32 (multi-client) locking API
- stress test "lockincfile1"
- Add new Win32 (multi-client) locking API stress test "lockincfile1",
- which locks a file, reads the last line which contains a
- "<tag> <value>" pair, and writes a new line with "<mytag> <value+1>",
- and then unlocks the file.
- This is intended to be a stress test running on one (contested)
- file from multiple clients.
- This patch also moves tests/filemmaptests/ into tests/misc/.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- cygwin/Makefile | 2 +
- cygwin/Makefile.install | 9 +-
- cygwin/devel/msnfs41client.bash | 3 +-
- tests/lockincfile1/Makefile | 29 +++++
- tests/lockincfile1/lockincfile1.c | 170 ++++++++++++++++++++++++++++++
- 5 files changed, 208 insertions(+), 5 deletions(-)
- create mode 100644 tests/lockincfile1/Makefile
- create mode 100644 tests/lockincfile1/lockincfile1.c
- diff --git a/cygwin/Makefile b/cygwin/Makefile
- index 5156b5b..3e55f1c 100644
- --- a/cygwin/Makefile
- +++ b/cygwin/Makefile
- @@ -26,6 +26,7 @@ $(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.exe \
- $(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.exe \
- $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
- $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.exe \
- + $(PROJECT_BASEDIR_DIR)/tests/lockincfile1/lockincfile1.exe \
- $(PROJECT_BASEDIR_DIR)/tests/winclonefile/winclonefile.exe \
- $(PROJECT_BASEDIR_DIR)/tests/winoffloadcopyfile/winoffloadcopyfile.exe \
- $(PROJECT_BASEDIR_DIR)/tests/winrunassystem/winrunassystem.exe \
- @@ -132,6 +133,7 @@ installdest_util: \
- $(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.exe \
- $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
- $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.exe \
- + $(PROJECT_BASEDIR_DIR)/tests/lockincfile1/lockincfile1.exe \
- $(PROJECT_BASEDIR_DIR)/tests/winclonefile/winclonefile.exe \
- $(PROJECT_BASEDIR_DIR)/tests/winoffloadcopyfile/winoffloadcopyfile.exe \
- $(PROJECT_BASEDIR_DIR)/tests/winrunassystem/winrunassystem.exe \
- diff --git a/cygwin/Makefile.install b/cygwin/Makefile.install
- index 137f6c8..a25aee8 100644
- --- a/cygwin/Makefile.install
- +++ b/cygwin/Makefile.install
- @@ -39,7 +39,6 @@ installdest:
- mkdir -p $(DESTDIR)/usr/share/msnfs41client/tests
- mkdir -p $(DESTDIR)/usr/share/msnfs41client/tests/misc
- mkdir -p $(DESTDIR)/usr/share/msnfs41client/tests/sparsefiles
- - mkdir -p $(DESTDIR)/usr/share/msnfs41client/tests/filemmaptests
- #
- # copy x86 binaries
- #
- @@ -152,9 +151,11 @@ installdest:
- cp "$(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.i686.exe" $(DESTDIR)/bin/winsg.i686.exe
- cp "$(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.x86_64.exe" $(DESTDIR)/bin/nfs_ea.x86_64.exe
- cp "$(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.i686.exe" $(DESTDIR)/bin/nfs_ea.i686.exe
- - cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.x86_64.exe" $(DESTDIR)/usr/share/msnfs41client/tests/filemmaptests/qsortonmmapedfile1.x86_64.exe
- - cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.i686.exe" $(DESTDIR)/usr/share/msnfs41client/tests/filemmaptests/qsortonmmapedfile1.i686.exe
- - cp $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/testqsortonmmapedfile1.ksh93 $(DESTDIR)/usr/share/msnfs41client/tests/filemmaptests/testqsortonmmapedfile1.ksh93
- + cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.x86_64.exe" $(DESTDIR)/usr/share/msnfs41client/tests/misc/qsortonmmapedfile1.x86_64.exe
- + cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.i686.exe" $(DESTDIR)/usr/share/msnfs41client/tests/misc/qsortonmmapedfile1.i686.exe
- + cp $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/testqsortonmmapedfile1.ksh93 $(DESTDIR)/usr/share/msnfs41client/tests/misc/testqsortonmmapedfile1.ksh93
- + cp "$(PROJECT_BASEDIR_DIR)/tests/lockincfile1/lockincfile1.x86_64.exe" $(DESTDIR)/usr/share/msnfs41client/tests/misc/lockincfile1.x86_64.exe
- + cp "$(PROJECT_BASEDIR_DIR)/tests/lockincfile1/lockincfile1.i686.exe" $(DESTDIR)/usr/share/msnfs41client/tests/misc/lockincfile1.i686.exe
- cp $(PROJECT_BASEDIR_DIR)/tests/nfsbuildtest/nfsbuildtest.ksh93 $(DESTDIR)/usr/share/msnfs41client/tests/misc/nfsbuildtest.ksh93
- cp $(PROJECT_BASEDIR_DIR)/tests/sparsefiles/testsparsefile1.ksh $(DESTDIR)/usr/share/msnfs41client/tests/sparsefiles/testsparsefile1.ksh
- cp $(PROJECT_BASEDIR_DIR)/tests/sparsefiles/testsparseexe1.ksh $(DESTDIR)/usr/share/msnfs41client/tests/sparsefiles/testsparseexe1.ksh
- diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
- index 2fbf2cd..4e44571 100755
- --- a/cygwin/devel/msnfs41client.bash
- +++ b/cygwin/devel/msnfs41client.bash
- @@ -251,7 +251,8 @@ function nfsclient_install
- 'bin/nfs_ea'
- 'sbin/winrunassystem'
- 'sbin/nfs_globalmount'
- - 'usr/share/msnfs41client/tests/filemmaptests/qsortonmmapedfile1'
- + 'usr/share/msnfs41client/tests/misc/qsortonmmapedfile1'
- + 'usr/share/msnfs41client/tests/misc/lockincfile1'
- )
- if [[ "${kernel_platform}" != 'i686' ]] ; then
- diff --git a/tests/lockincfile1/Makefile b/tests/lockincfile1/Makefile
- new file mode 100644
- index 0000000..ab539dc
- --- /dev/null
- +++ b/tests/lockincfile1/Makefile
- @@ -0,0 +1,29 @@
- +#
- +# Makefile for lockincfile1
- +#
- +
- +# POSIX Makefile
- +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
- +
- +all: \
- + lockincfile1.i686.exe \
- + lockincfile1.x86_64.exe \
- + lockincfile1.exe
- +
- +lockincfile1.i686.exe: lockincfile1.c
- + clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O lockincfile1.c -o $@
- + bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
- +
- +lockincfile1.x86_64.exe: lockincfile1.c
- + clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O lockincfile1.c -o $@
- + bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
- +
- +lockincfile1.exe: lockincfile1.x86_64.exe
- + ln -s lockincfile1.x86_64.exe lockincfile1.exe
- +
- +clean:
- + rm -fv \
- + lockincfile1.i686.exe \
- + lockincfile1.x86_64.exe \
- + lockincfile1.exe
- +# EOF.
- diff --git a/tests/lockincfile1/lockincfile1.c b/tests/lockincfile1/lockincfile1.c
- new file mode 100644
- index 0000000..cde5822
- --- /dev/null
- +++ b/tests/lockincfile1/lockincfile1.c
- @@ -0,0 +1,170 @@
- +/*
- + * MIT License
- + *
- + * Copyright (c) 2025 Roland Mainz <roland.mainz@nrubsig.org>
- + *
- + * Permission is hereby granted, free of charge, to any person obtaining a copy
- + * of this software and associated documentation files (the "Software"), to deal
- + * in the Software without restriction, including without limitation the rights
- + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- + * copies of the Software, and to permit persons to whom the Software is
- + * furnished to do so, subject to the following conditions:
- + *
- + * The above copyright notice and this permission notice shall be included in
- + * all copies or substantial portions of the Software.
- + *
- + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- + * SOFTWARE.
- + */
- +
- +/*
- + * lockincfile1.c - lock file, read last line with "<tag> <value>", and write a new line "<mytag> <value+1>", unlock file
- + *
- + * Usage:
- + * $ clang -Wall -Wextra -O -g lockincfile1.c -o lockincfile1.exe
- + * $ rm -f contestedfile1.txt ; touch contestedfile1.txt
- + *
- + * Test run
- + * # on machine 1:
- + * $ time bash -c 'set -o errexit ; (for ((i=0 ; i < 400 ; i++)) ; do ./lockincfile1 contestedfile1.txt "aaa"; done) ; echo $?'
- + * # on machine 2:
- + * $ time bash -c 'set -o errexit ; (for ((i=0 ; i < 400 ; i++)) ; do ./lockincfile1 contestedfile1.txt "bbb"; done) ; echo $?'
- + * When both machines are finished the last line should match eregex ".+800"
- + */
- +#include <windows.h>
- +#include <stdio.h>
- +#include <stdlib.h>
- +#include <stdint.h>
- +#include <string.h>
- +#include <ctype.h>
- +
- +#define EXIT_USAGE (2) /* Traditional UNIX exit code for usage */
- +
- +int main(int argc, char *av[])
- +{
- + if (argc != 3) {
- + (void)fprintf(stderr, "Usage:\n%s <filename> <tag>\n", av[0]);
- + return EXIT_USAGE;
- + }
- +
- + int retval = EXIT_FAILURE;
- + const char *fileName = av[1];
- + const char *tag = av[2];
- + long last_val = 0;
- + HANDLE h;
- + LARGE_INTEGER liFileSize;
- + char buffer[256];
- + char writeBuffer[256];
- + DWORD bytesRead, bytesWritten;
- +
- + h = CreateFileA(fileName,
- + GENERIC_READ | GENERIC_WRITE,
- + FILE_SHARE_READ | FILE_SHARE_WRITE,
- + NULL,
- + OPEN_EXISTING,
- + /*FILE_ATTRIBUTE_NORMAL*/FILE_FLAG_NO_BUFFERING,
- + NULL);
- + if (h == INVALID_HANDLE_VALUE) {
- + (void)fprintf(stderr, "%s: Cannot open file '%s', lasterr=%ld\n",
- + av[0],
- + av[1],
- + (long)GetLastError());
- + (void)CloseHandle(h);
- + return EXIT_FAILURE;
- + }
- +
- + OVERLAPPED ov = {
- + .hEvent = 0,
- + .Offset = 0,
- + .OffsetHigh = 0
- + };
- + if (!LockFileEx(h, LOCKFILE_EXCLUSIVE_LOCK, 0, MAXDWORD, MAXDWORD, &ov)) {
- + (void)fprintf(stderr,
- + "%s: Locking failed, lasterr=%ld\n",
- + av[0], (long)GetLastError());
- + (void)CloseHandle(h);
- + return EXIT_FAILURE;
- + }
- +
- + (void)GetFileSizeEx(h, &liFileSize);
- +
- + if (liFileSize.QuadPart > 0LL) {
- + LARGE_INTEGER liSeekPos;
- + if (liFileSize.QuadPart > (long long)(sizeof(buffer)-1))
- + liSeekPos.QuadPart = (liFileSize.QuadPart - (sizeof(buffer)-1));
- + else
- + liSeekPos.QuadPart = 0LL;
- +
- + (void)SetFilePointerEx(h, liSeekPos, NULL, FILE_BEGIN);
- +
- + if (!ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, NULL) || (bytesRead == 0)) {
- + (void)fprintf(stderr,
- + "%s: ReadFile() failed, lasterr=%ld\n",
- + av[0], (long)GetLastError());
- + goto cleanup;
- + }
- + buffer[bytesRead] = '\0';
- +
- + char *line_start = buffer;
- + char *p = buffer + bytesRead - 1;
- +
- + while ((p >= buffer) &&
- + isspace((unsigned char)*p)) {
- + p--;
- + }
- +
- + if (p >= buffer) {
- + line_start = p;
- + while (line_start > buffer && *(line_start - 1) != '\n') {
- + line_start--;
- + }
- +
- + char *separator = NULL;
- + char *temp_p = p;
- + while (temp_p >= line_start) {
- + if (*temp_p == ' ' || *temp_p == '\t') {
- + separator = temp_p;
- + break;
- + }
- + temp_p--;
- + }
- +
- + if (separator && isdigit((unsigned char)*(separator + 1))) {
- + last_val = strtol(separator + 1, NULL, 10);
- + }
- + }
- + }
- +
- + LARGE_INTEGER liEndPos = { .QuadPart = 0LL };
- + (void)SetFilePointerEx(h, liEndPos, NULL, FILE_END);
- +
- + if (liFileSize.QuadPart > 0LL) {
- + char lastChar;
- + LARGE_INTEGER liLastCharPos;
- + liLastCharPos.QuadPart = -1LL;
- + (void)SetFilePointerEx(h, liLastCharPos, NULL, FILE_END);
- + if (ReadFile(h, &lastChar, 1, &bytesRead, NULL) && (bytesRead == 1)) {
- + if (lastChar != '\n') {
- + (void)WriteFile(h, "\n", 1, &bytesWritten, NULL);
- + }
- + }
- + }
- +
- + int len = snprintf(writeBuffer, sizeof(writeBuffer),
- + "%s\t%ld\n", tag, (last_val + 1));
- + (void)WriteFile(h, writeBuffer, len, &bytesWritten, NULL);
- +
- + (void)FlushFileBuffers(h);
- + retval = EXIT_SUCCESS;
- +
- +cleanup:
- + (void)UnlockFileEx(h, 0, MAXDWORD, MAXDWORD, &ov);
- + (void)CloseHandle(h);
- +
- + return retval;
- +}
- --
- 2.51.0
msnfs41client: Patches for building on Win10/32bit+Win32 locking fixes+tests, 2025-09-30
Posted by Anonymous on Tue 30th Sep 2025 19:36
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.