@@ -243,10 +243,9 @@ int main(int argc, char **argv)
243
243
time_t lastt; /* last time */
244
244
ulint oldcsum, oldcsumfield, csum, csumfield, crc32, logseq, logseqfield;
245
245
/* ulints for checksum storage */
246
- struct stat st; /* for stat, if you couldn't guess */
247
246
unsigned long long int size; /* size of file (has to be 64 bits) */
248
247
ulint pages; /* number of pages in file */
249
- off_t offset= 0 ;
248
+ unsigned long long offset= 0 ;
250
249
int fd;
251
250
252
251
printf (" InnoDB offline file checksum utility.\n " );
@@ -269,6 +268,47 @@ int main(int argc, char **argv)
269
268
goto error;
270
269
}
271
270
271
+ #ifdef _WIN32
272
+ /* Switch off OS file buffering for the file. */
273
+
274
+ HANDLE h = CreateFile (filename, GENERIC_READ,
275
+ FILE_SHARE_READ|FILE_SHARE_WRITE, 0 ,
276
+ OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, 0 );
277
+
278
+ if (!h)
279
+ {
280
+ fprintf (stderr, " Error; cant open file\n " );
281
+ goto error;
282
+ }
283
+
284
+ if (!GetFileSizeEx (h, (LARGE_INTEGER *)&size))
285
+ {
286
+ fprintf (stderr, " Error; GetFileSize() failed\n " );
287
+ goto error;
288
+ }
289
+
290
+ fd = _open_osfhandle ((intptr_t ) h, _O_RDONLY);
291
+ if (fd < 0 )
292
+ {
293
+ fprintf (stderr, " Error; _open_osfhandle() failed\n " );
294
+ goto error;
295
+ }
296
+
297
+ f = _fdopen (fd, " rb" );
298
+ if (!f)
299
+ {
300
+ fprintf (stderr, " Error; fdopen() failed\n " );
301
+ goto error;
302
+ }
303
+
304
+ /*
305
+ Disable stdio buffering (FILE_FLAG_NO_BUFFERING requires properly IO buffers
306
+ which stdio does not guarantee.
307
+ */
308
+ setvbuf (f, NULL , _IONBF, 0 );
309
+
310
+ #else
311
+ struct stat st;
272
312
/* stat the file to get size and page count */
273
313
if (stat (filename, &st))
274
314
{
@@ -279,6 +319,8 @@ int main(int argc, char **argv)
279
319
280
320
/* Open the file for reading */
281
321
f= fopen (filename, " rb" );
322
+ #endif
323
+
282
324
if (f == NULL )
283
325
{
284
326
fprintf (stderr, " Error; %s cannot be opened" , filename);
@@ -323,7 +365,7 @@ int main(int argc, char **argv)
323
365
}
324
366
else if (verbose)
325
367
{
326
- printf (" file %s = %llu bytes (%lu pages)...\n " , filename, size, pages);
368
+ printf (" file %s = %llu bytes (%lu pages)...\n " , filename, size, (ulong) pages);
327
369
if (do_one_page)
328
370
printf (" InnoChecksum; checking page %lu\n " , do_page);
329
371
else
@@ -348,9 +390,12 @@ int main(int argc, char **argv)
348
390
goto error;
349
391
}
350
392
351
- offset= (off_t )start_page * (off_t )physical_page_size;
352
-
393
+ offset= (ulonglong)start_page * (ulonglong)physical_page_size;
394
+ #ifdef _WIN32
395
+ if (_lseeki64 (fd, offset, SEEK_SET) != offset)
396
+ #else
353
397
if (lseek (fd, offset, SEEK_SET) != offset)
398
+ #endif
354
399
{
355
400
perror (" Error; Unable to seek to necessary offset" );
356
401
goto error;
0 commit comments