From: Jeffrey Altman Date: Sun, 25 Jun 2006 20:50:02 +0000 (+0000) Subject: windows-largefile-test-20060625 X-Git-Tag: BP-openafs-windows-kdfs-ifs~1243 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=fa4b139d02fe4b1224a9ca367a081ca95ec18dd6;p=packages%2Fo%2Fopenafs.git windows-largefile-test-20060625 Large File test --- diff --git a/src/WINNT/tests/largefiles/lftest.c b/src/WINNT/tests/largefiles/lftest.c new file mode 100644 index 000000000..bf775e055 --- /dev/null +++ b/src/WINNT/tests/largefiles/lftest.c @@ -0,0 +1,169 @@ +#include +#include +#include +#include +#include + +char * teststr = "This is a test string."; + + + +void usage(void) { + fprintf(stderr, "lftest \n"); + exit(1); +} + +int test_write(HANDLE hf, LARGE_INTEGER offset) { + DWORD dwWritten; + int ret = 0; + + if (!LockFile(hf, offset.u.LowPart, offset.u.HighPart, + 4096, 0)) { + fprintf(stderr, "Unable to lock offset 0x%08x:%08x gle = 0x%08x\n", + offset.u.HighPart, offset.u.LowPart, GetLastError()); + return -1; + } + + if (!SetFilePointerEx(hf, offset, NULL, FILE_BEGIN)) { + fprintf(stderr, "Unable to set file pointer to offset 0x%08x:%08x gle = 0x%08x\n", + offset.u.HighPart, offset.u.LowPart, GetLastError()); + ret = -1; + goto unlock; + } + + if (!WriteFile(hf, teststr, strlen(teststr)+1, &dwWritten, NULL)) { + fprintf(stderr, "Unable to write test string at offset 0x%08x:%08x gle = 0x%08x\n", + offset.u.HighPart, offset.u.LowPart, GetLastError()); + ret = -1; + goto unlock; + } else { + printf("wrote '%s' at offset 0x%08x:%08x\n", teststr, offset.u.HighPart, offset.u.LowPart); + } + + unlock: + if (!UnlockFile(hf, offset.u.LowPart, offset.u.HighPart, + 4096, 0)) { + fprintf(stderr, "Unable to unlock offset 0x%08x:%08x gle = 0x%08x\n", + offset.u.HighPart, offset.u.LowPart, GetLastError()); + ret = -1; + } + +#if 0 + if (!FlushFileBuffers(hf)) { + fprintf(stderr, "Flush buffers fails at offset 0x%08x:%08x gle = 0x%08x\n", + offset.u.HighPart, offset.u.LowPart, GetLastError()); + } +#endif + return ret; +} + +int test_read(HANDLE hf, LARGE_INTEGER offset) { + char buffer[256]; + DWORD dwRead; + int ret = 0; + + if (!LockFile(hf, offset.u.LowPart, offset.u.HighPart, + 4096, 0)) { + fprintf(stderr, "Unable to lock offset 0x%08x:%08x gle = 0x%08x\n", + offset.u.HighPart, offset.u.LowPart, GetLastError()); + return -1; + } + + if (!SetFilePointerEx(hf, offset, NULL, FILE_BEGIN)) { + fprintf(stderr, "Unable to set file pointer to offset 0x%08x:%08x gle = 0x%08x\n", + offset.u.HighPart, offset.u.LowPart, GetLastError()); + ret = -1; + goto unlock; + } + + if (!ReadFile(hf, buffer, strlen(teststr)+1, &dwRead, NULL)) { + fprintf(stderr, "Unable to read test string at offset 0x%08x:%08x gle = 0x%08x\n", + offset.u.HighPart, offset.u.LowPart, GetLastError()); + ret = -1; + goto unlock; + } else { + printf("read '%s' (%d bytes) at offset 0x%08x:%08x\n", buffer, dwRead, offset.u.HighPart, offset.u.LowPart); + } + + if (strcmp(buffer, teststr)) { + fprintf(stderr, "Test string comparison failure at offset 0x%08x:%08x\n", + offset.u.HighPart, offset.u.LowPart); + ret = -1; + goto unlock; + } + + unlock: + if (!UnlockFile(hf, offset.u.LowPart, offset.u.HighPart, + 4096, 0)) { + fprintf(stderr, "Unable to unlock offset 0x%08x:%08x gle = 0x%08x\n", + offset.u.HighPart, offset.u.LowPart, GetLastError()); + ret = -1; + } + + return ret; +} + +int +main(int argc, char *argv[]) { + HANDLE fh; + __int64 i; + char cmdline[512]; + LARGE_INTEGER large; + + if (argc == 1) + usage(); + + if (!SetCurrentDirectory(argv[1])) { + fprintf(stderr, "unable to set directory to %s\n", argv[1]); + return 2; + } + + fh = CreateFile("largefile.test", + GENERIC_READ | GENERIC_WRITE | STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL /* default security */, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_WRITE_THROUGH, + NULL ); + + if (fh == INVALID_HANDLE_VALUE) { + fprintf(stderr, "unable to create/open the test file\n"); + return 3; + } + + for ( i=0; i<7; i++ ) { + + large.QuadPart = i * (0x40000000-4); + test_write(fh, large); + + } + + CloseHandle(fh); + + sprintf(cmdline, "fs.exe flushvolume %s", argv[1]); + system(cmdline); + + fh = CreateFile("largefile.test", + GENERIC_READ | GENERIC_WRITE | STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL /* default security */, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_WRITE_THROUGH, + NULL ); + + if (fh == INVALID_HANDLE_VALUE) { + fprintf(stderr, "unable to create/open the test file\n"); + return 3; + } + + for ( i=0; i<7; i++ ) { + + large.QuadPart = i * (0x40000000-4); + test_read(fh, large); + + } + + CloseHandle(fh); + + return 0; +}