7 char * teststr = "This is a test string.";
12 fprintf(stderr, "lftest <path>\n");
16 int test_write(HANDLE hf, LARGE_INTEGER offset) {
20 if (!LockFile(hf, offset.u.LowPart, offset.u.HighPart,
22 fprintf(stderr, "Unable to lock offset 0x%08x:%08x gle = 0x%08x\n",
23 offset.u.HighPart, offset.u.LowPart, GetLastError());
27 if (!SetFilePointerEx(hf, offset, NULL, FILE_BEGIN)) {
28 fprintf(stderr, "Unable to set file pointer to offset 0x%08x:%08x gle = 0x%08x\n",
29 offset.u.HighPart, offset.u.LowPart, GetLastError());
34 if (!WriteFile(hf, teststr, strlen(teststr)+1, &dwWritten, NULL)) {
35 fprintf(stderr, "Unable to write test string at offset 0x%08x:%08x gle = 0x%08x\n",
36 offset.u.HighPart, offset.u.LowPart, GetLastError());
40 printf("wrote '%s' at offset 0x%08x:%08x\n", teststr, offset.u.HighPart, offset.u.LowPart);
44 if (!UnlockFile(hf, offset.u.LowPart, offset.u.HighPart,
46 fprintf(stderr, "Unable to unlock offset 0x%08x:%08x gle = 0x%08x\n",
47 offset.u.HighPart, offset.u.LowPart, GetLastError());
52 if (!FlushFileBuffers(hf)) {
53 fprintf(stderr, "Flush buffers fails at offset 0x%08x:%08x gle = 0x%08x\n",
54 offset.u.HighPart, offset.u.LowPart, GetLastError());
60 int test_read(HANDLE hf, LARGE_INTEGER offset) {
65 if (!LockFile(hf, offset.u.LowPart, offset.u.HighPart,
67 fprintf(stderr, "Unable to lock offset 0x%08x:%08x gle = 0x%08x\n",
68 offset.u.HighPart, offset.u.LowPart, GetLastError());
72 if (!SetFilePointerEx(hf, offset, NULL, FILE_BEGIN)) {
73 fprintf(stderr, "Unable to set file pointer to offset 0x%08x:%08x gle = 0x%08x\n",
74 offset.u.HighPart, offset.u.LowPart, GetLastError());
79 if (!ReadFile(hf, buffer, strlen(teststr)+1, &dwRead, NULL)) {
80 fprintf(stderr, "Unable to read test string at offset 0x%08x:%08x gle = 0x%08x\n",
81 offset.u.HighPart, offset.u.LowPart, GetLastError());
85 printf("read '%s' (%d bytes) at offset 0x%08x:%08x\n", buffer, dwRead, offset.u.HighPart, offset.u.LowPart);
88 if (strcmp(buffer, teststr)) {
89 fprintf(stderr, "Test string comparison failure at offset 0x%08x:%08x\n",
90 offset.u.HighPart, offset.u.LowPart);
96 if (!UnlockFile(hf, offset.u.LowPart, offset.u.HighPart,
98 fprintf(stderr, "Unable to unlock offset 0x%08x:%08x gle = 0x%08x\n",
99 offset.u.HighPart, offset.u.LowPart, GetLastError());
107 main(int argc, char *argv[]) {
116 if (!SetCurrentDirectory(argv[1])) {
117 fprintf(stderr, "unable to set directory to %s\n", argv[1]);
121 fh = CreateFile("largefile.test",
122 GENERIC_READ | GENERIC_WRITE | STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE,
123 FILE_SHARE_READ | FILE_SHARE_WRITE,
124 NULL /* default security */,
126 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_WRITE_THROUGH,
129 if (fh == INVALID_HANDLE_VALUE) {
130 fprintf(stderr, "unable to create/open the test file\n");
134 for ( i=0; i<7; i++ ) {
136 large.QuadPart = i * (0x40000000-4);
137 test_write(fh, large);
143 sprintf(cmdline, "fs.exe flushvolume %s", argv[1]);
146 fh = CreateFile("largefile.test",
147 GENERIC_READ | GENERIC_WRITE | STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE,
148 FILE_SHARE_READ | FILE_SHARE_WRITE,
149 NULL /* default security */,
151 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_WRITE_THROUGH,
154 if (fh == INVALID_HANDLE_VALUE) {
155 fprintf(stderr, "unable to create/open the test file\n");
159 for ( i=0; i<7; i++ ) {
161 large.QuadPart = i * (0x40000000-4);
162 test_read(fh, large);