test_sparse_basic.c (313570) | test_sparse_basic.c (337351) |
---|---|
1/*- 2 * Copyright (c) 2010-2012 Michihiro NAKAJIMA 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 104 unchanged lines hidden (view full) --- 113 memset(buff, ' ', sizeof(buff)); 114 115 handle = CreateFileA(path, GENERIC_WRITE, 0, 116 NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 117 NULL); 118 assert(handle != INVALID_HANDLE_VALUE); 119 assert(DeviceIoControl(handle, FSCTL_SET_SPARSE, NULL, 0, 120 NULL, 0, &dmy, NULL) != 0); | 1/*- 2 * Copyright (c) 2010-2012 Michihiro NAKAJIMA 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 104 unchanged lines hidden (view full) --- 113 memset(buff, ' ', sizeof(buff)); 114 115 handle = CreateFileA(path, GENERIC_WRITE, 0, 116 NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 117 NULL); 118 assert(handle != INVALID_HANDLE_VALUE); 119 assert(DeviceIoControl(handle, FSCTL_SET_SPARSE, NULL, 0, 120 NULL, 0, &dmy, NULL) != 0); |
121 122 size_t offsetSoFar = 0; 123 |
|
121 while (s->type != END) { 122 if (s->type == HOLE) { | 124 while (s->type != END) { 125 if (s->type == HOLE) { |
123 LARGE_INTEGER distance; | 126 LARGE_INTEGER fileOffset, beyondOffset, distanceToMove; 127 fileOffset.QuadPart = offsetSoFar; 128 beyondOffset.QuadPart = offsetSoFar + s->size; 129 distanceToMove.QuadPart = s->size; |
124 | 130 |
125 distance.QuadPart = s->size; 126 assert(SetFilePointerEx(handle, distance, 127 NULL, FILE_CURRENT) != 0); | 131 FILE_ZERO_DATA_INFORMATION zeroInformation; 132 zeroInformation.FileOffset = fileOffset; 133 zeroInformation.BeyondFinalZero = beyondOffset; 134 135 DWORD bytesReturned; 136 assert(SetFilePointerEx(handle, distanceToMove, 137 NULL, FILE_CURRENT) != 0); 138 assert(SetEndOfFile(handle) != 0); 139 assert(DeviceIoControl(handle, FSCTL_SET_ZERO_DATA, &zeroInformation, 140 sizeof(FILE_ZERO_DATA_INFORMATION), NULL, 0, &bytesReturned, NULL) != 0); |
128 } else { 129 DWORD w, wr; 130 size_t size; 131 132 size = s->size; 133 while (size) { 134 if (size > sizeof(buff)) 135 w = sizeof(buff); 136 else 137 w = (DWORD)size; 138 assert(WriteFile(handle, buff, w, &wr, NULL) != 0); 139 size -= wr; 140 } 141 } | 141 } else { 142 DWORD w, wr; 143 size_t size; 144 145 size = s->size; 146 while (size) { 147 if (size > sizeof(buff)) 148 w = sizeof(buff); 149 else 150 w = (DWORD)size; 151 assert(WriteFile(handle, buff, w, &wr, NULL) != 0); 152 size -= wr; 153 } 154 } |
155 offsetSoFar += s->size; |
|
142 s++; 143 } 144 assertEqualInt(CloseHandle(handle), 1); 145} 146 147#else 148 149#if defined(HAVE_LINUX_FIEMAP_H) --- 329 unchanged lines hidden (view full) --- 479 * The alignment of the hole of sparse files deeply depends 480 * on filesystem. In my experience, sparse_file2 test with 481 * 204800 bytes hole size did not pass on ZFS and the result 482 * of that test seemed the size was too small, thus you should 483 * keep a hole size more than 409600 bytes to pass this test 484 * on all platform. 485 */ 486 const struct sparse sparse_file0[] = { | 156 s++; 157 } 158 assertEqualInt(CloseHandle(handle), 1); 159} 160 161#else 162 163#if defined(HAVE_LINUX_FIEMAP_H) --- 329 unchanged lines hidden (view full) --- 493 * The alignment of the hole of sparse files deeply depends 494 * on filesystem. In my experience, sparse_file2 test with 495 * 204800 bytes hole size did not pass on ZFS and the result 496 * of that test seemed the size was too small, thus you should 497 * keep a hole size more than 409600 bytes to pass this test 498 * on all platform. 499 */ 500 const struct sparse sparse_file0[] = { |
501 // 0 // 1024 |
|
487 { DATA, 1024 }, { HOLE, 2048000 }, | 502 { DATA, 1024 }, { HOLE, 2048000 }, |
503 // 2049024 // 2051072 |
|
488 { DATA, 2048 }, { HOLE, 2048000 }, | 504 { DATA, 2048 }, { HOLE, 2048000 }, |
505 // 4099072 // 4103168 |
|
489 { DATA, 4096 }, { HOLE, 20480000 }, | 506 { DATA, 4096 }, { HOLE, 20480000 }, |
507 // 24583168 // 24591360 |
|
490 { DATA, 8192 }, { HOLE, 204800000 }, | 508 { DATA, 8192 }, { HOLE, 204800000 }, |
509 // 229391360 // 229391361 |
|
491 { DATA, 1 }, { END, 0 } 492 }; 493 const struct sparse sparse_file1[] = { 494 { HOLE, 409600 }, { DATA, 1 }, 495 { HOLE, 409600 }, { DATA, 1 }, 496 { HOLE, 409600 }, { END, 0 } 497 }; 498 const struct sparse sparse_file2[] = { --- 111 unchanged lines hidden --- | 510 { DATA, 1 }, { END, 0 } 511 }; 512 const struct sparse sparse_file1[] = { 513 { HOLE, 409600 }, { DATA, 1 }, 514 { HOLE, 409600 }, { DATA, 1 }, 515 { HOLE, 409600 }, { END, 0 } 516 }; 517 const struct sparse sparse_file2[] = { --- 111 unchanged lines hidden --- |