1 /* 2 * Copyright (c) International Business Machines Corp., 2004 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 12 * the GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 /* 20 * TEST CASE : hole.c 21 * 22 * VARIATIONS : 77 23 * 24 * API'S TESTED : dm_get_allocinfo 25 * dm_probe_hole 26 * dm_punch_hole 27 */ 28 #include <string.h> 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <errno.h> 32 #include <unistd.h> 33 #include <sys/stat.h> 34 #include <sys/mman.h> 35 #include <fcntl.h> 36 #include "dm_test.h" 37 38 #define TMP_FILELEN 500000 39 #define NUM_EXTENTS 8 40 41 char command[4096]; 42 dm_sessid_t sid; 43 dm_extent_t Extents[NUM_EXTENTS]; 44 dm_extent_t bigExtents[20]; 45 46 void LogExtents(dm_extent_t * pext, u_int nelem) 47 { 48 49 int i; 50 51 DMLOG_PRINT(DMLVL_DEBUG, "Extents:\n"); 52 for (i = 0; i < nelem; i++, pext++) { 53 DMLOG_PRINT(DMLVL_DEBUG, 54 " extent %d: type %d, offset %lld, length %lld\n", 55 i + 1, pext->ex_type, pext->ex_offset, 56 pext->ex_length); 57 } 58 59 } 60 61 int main(int argc, char **argv) 62 { 63 64 char *szFuncName; 65 char *varstr; 66 int i; 67 int rc; 68 char *szSessionInfo = "dm_test session info"; 69 70 DMOPT_PARSE(argc, argv); 71 DMLOG_START(); 72 73 /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */ 74 if ((rc = dm_init_service(&varstr)) != 0) { 75 DMLOG_PRINT(DMLVL_ERR, 76 "dm_init_service failed! (rc = %d, errno = %d)\n", 77 rc, errno); 78 DM_EXIT(); 79 } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) 80 != 0) { 81 DMLOG_PRINT(DMLVL_ERR, 82 "dm_create_session failed! (rc = %d, errno = %d)\n", 83 rc, errno); 84 DM_EXIT(); 85 } else { 86 int fd; 87 88 fd = open(DUMMY_TMP, O_RDWR | O_CREAT | O_TRUNC, 89 DUMMY_FILE_RW_MODE); 90 if (fd != -1) { 91 for (i = 0; i < (TMP_FILELEN / DUMMY_STRLEN); i++) { 92 if (write(fd, DUMMY_STRING, DUMMY_STRLEN) != 93 DUMMY_STRLEN) { 94 rc = -1; 95 break; 96 } 97 } 98 } else { 99 rc = -1; 100 } 101 if (rc == 0) { 102 rc = close(fd); 103 } 104 if (rc == -1) { 105 DMLOG_PRINT(DMLVL_ERR, 106 "creating dummy file failed! (rc = %d, errno = %d)\n", 107 rc, errno); 108 dm_destroy_session(sid); 109 DM_EXIT(); 110 } 111 } 112 113 DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI file hole tests\n"); 114 115 szFuncName = "dm_get_allocinfo"; 116 117 /* 118 * TEST : dm_get_allocinfo - invalid sid 119 * EXPECTED: rc = -1, errno = EINVAL 120 */ 121 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 1)) { 122 int fd; 123 void *hanp; 124 size_t hlen; 125 dm_off_t off = 0; 126 u_int nelem; 127 128 /* Variation set up */ 129 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 130 if ((rc = system(command)) == -1) { 131 /* No clean up */ 132 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 133 remove(DUMMY_FILE); 134 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 135 close(fd); 136 remove(DUMMY_FILE); 137 } 138 if (fd == -1 || rc == -1) { 139 DMLOG_PRINT(DMLVL_DEBUG, 140 "Unable to set up variation! (errno = %d)\n", 141 errno); 142 DMVAR_SKIP(); 143 } else { 144 /* Variation */ 145 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", 146 szFuncName); 147 rc = dm_get_allocinfo(INVALID_ADDR, hanp, hlen, 148 DM_NO_TOKEN, &off, NUM_EXTENTS, 149 Extents, &nelem); 150 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 151 152 /* Variation clean up */ 153 rc = close(fd); 154 rc |= remove(DUMMY_FILE); 155 if (rc == -1) { 156 DMLOG_PRINT(DMLVL_DEBUG, 157 "Unable to clean up variation! (errno = %d)\n", 158 errno); 159 } 160 dm_handle_free(hanp, hlen); 161 } 162 } 163 164 /* 165 * TEST : dm_get_allocinfo - invalid hanp 166 * EXPECTED: rc = -1, errno = EFAULT 167 */ 168 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 2)) { 169 int fd; 170 void *hanp; 171 size_t hlen; 172 dm_off_t off = 0; 173 u_int nelem; 174 175 /* Variation set up */ 176 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 177 if ((rc = system(command)) == -1) { 178 /* No clean up */ 179 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 180 remove(DUMMY_FILE); 181 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 182 close(fd); 183 remove(DUMMY_FILE); 184 } 185 if (fd == -1 || rc == -1) { 186 DMLOG_PRINT(DMLVL_DEBUG, 187 "Unable to set up variation! (errno = %d)\n", 188 errno); 189 DMVAR_SKIP(); 190 } else { 191 /* Variation */ 192 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", 193 szFuncName); 194 rc = dm_get_allocinfo(sid, (void *)INVALID_ADDR, hlen, 195 DM_NO_TOKEN, &off, NUM_EXTENTS, 196 Extents, &nelem); 197 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 198 199 /* Variation clean up */ 200 rc = close(fd); 201 rc |= remove(DUMMY_FILE); 202 if (rc == -1) { 203 DMLOG_PRINT(DMLVL_DEBUG, 204 "Unable to clean up variation! (errno = %d)\n", 205 errno); 206 } 207 dm_handle_free(hanp, hlen); 208 } 209 } 210 211 /* 212 * TEST : dm_get_allocinfo - directory handle 213 * EXPECTED: rc = -1, errno = EINVAL 214 * 215 * This variation uncovered XFS BUG #7 (EOPNOTSUPP errno returned 216 * instead of EINVAL) 217 */ 218 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 3)) { 219 void *hanp; 220 size_t hlen; 221 dm_off_t off = 0; 222 u_int nelem; 223 224 /* Variation set up */ 225 if ((rc = mkdir(DUMMY_SUBDIR, DUMMY_DIR_RW_MODE)) == -1) { 226 /* No clean up */ 227 } else if ((rc = dm_path_to_handle(DUMMY_SUBDIR, &hanp, &hlen)) 228 == -1) { 229 rmdir(DUMMY_SUBDIR); 230 } 231 if (rc == -1) { 232 DMLOG_PRINT(DMLVL_DEBUG, 233 "Unable to set up variation! (errno = %d)\n", 234 errno); 235 DMVAR_SKIP(); 236 } else { 237 /* Variation */ 238 DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n", 239 szFuncName); 240 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 241 &off, NUM_EXTENTS, Extents, 242 &nelem); 243 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 244 245 /* Variation clean up */ 246 rc = rmdir(DUMMY_SUBDIR); 247 if (rc == -1) { 248 DMLOG_PRINT(DMLVL_DEBUG, 249 "Unable to clean up variation! (errno = %d)\n", 250 errno); 251 } 252 dm_handle_free(hanp, hlen); 253 } 254 } 255 256 /* 257 * TEST : dm_get_allocinfo - invalid hlen 258 * EXPECTED: rc = -1, errno = EBADF 259 */ 260 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 4)) { 261 int fd; 262 void *hanp; 263 size_t hlen; 264 dm_off_t off = 0; 265 u_int nelem; 266 267 /* Variation set up */ 268 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 269 if ((rc = system(command)) == -1) { 270 /* No clean up */ 271 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 272 remove(DUMMY_FILE); 273 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 274 close(fd); 275 remove(DUMMY_FILE); 276 } 277 if (fd == -1 || rc == -1) { 278 DMLOG_PRINT(DMLVL_DEBUG, 279 "Unable to set up variation! (errno = %d)\n", 280 errno); 281 DMVAR_SKIP(); 282 } else { 283 /* Variation */ 284 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", 285 szFuncName); 286 rc = dm_get_allocinfo(sid, hanp, INVALID_ADDR, 287 DM_NO_TOKEN, &off, NUM_EXTENTS, 288 Extents, &nelem); 289 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 290 291 /* Variation clean up */ 292 rc = close(fd); 293 rc |= remove(DUMMY_FILE); 294 if (rc == -1) { 295 DMLOG_PRINT(DMLVL_DEBUG, 296 "Unable to clean up variation! (errno = %d)\n", 297 errno); 298 } 299 dm_handle_free(hanp, hlen); 300 } 301 } 302 303 /* 304 * TEST : dm_get_allocinfo - invalid token 305 * EXPECTED: rc = -1, errno = EINVAL 306 */ 307 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 5)) { 308 int fd; 309 void *hanp; 310 size_t hlen; 311 dm_off_t off = 0; 312 u_int nelem; 313 314 /* Variation set up */ 315 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 316 if ((rc = system(command)) == -1) { 317 /* No clean up */ 318 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 319 remove(DUMMY_FILE); 320 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 321 close(fd); 322 remove(DUMMY_FILE); 323 } 324 if (fd == -1 || rc == -1) { 325 DMLOG_PRINT(DMLVL_DEBUG, 326 "Unable to set up variation! (errno = %d)\n", 327 errno); 328 DMVAR_SKIP(); 329 } else { 330 /* Variation */ 331 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", 332 szFuncName); 333 rc = dm_get_allocinfo(sid, hanp, hlen, INVALID_ADDR, 334 &off, NUM_EXTENTS, Extents, 335 &nelem); 336 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 337 338 /* Variation clean up */ 339 rc = close(fd); 340 rc |= remove(DUMMY_FILE); 341 if (rc == -1) { 342 DMLOG_PRINT(DMLVL_DEBUG, 343 "Unable to clean up variation! (errno = %d)\n", 344 errno); 345 } 346 dm_handle_free(hanp, hlen); 347 } 348 } 349 350 /* 351 * TEST : dm_get_allocinfo - invalid offp 352 * EXPECTED: rc = -1, errno = EFAULT 353 */ 354 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 6)) { 355 int fd; 356 void *hanp; 357 size_t hlen; 358 u_int nelem; 359 360 /* Variation set up */ 361 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 362 if ((rc = system(command)) == -1) { 363 /* No clean up */ 364 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 365 remove(DUMMY_FILE); 366 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 367 close(fd); 368 remove(DUMMY_FILE); 369 } 370 if (fd == -1 || rc == -1) { 371 DMLOG_PRINT(DMLVL_DEBUG, 372 "Unable to set up variation! (errno = %d)\n", 373 errno); 374 DMVAR_SKIP(); 375 } else { 376 /* Variation */ 377 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid offp)\n", 378 szFuncName); 379 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 380 (dm_off_t *) INVALID_ADDR, 381 NUM_EXTENTS, Extents, &nelem); 382 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 383 384 /* Variation clean up */ 385 rc = close(fd); 386 rc |= remove(DUMMY_FILE); 387 if (rc == -1) { 388 DMLOG_PRINT(DMLVL_DEBUG, 389 "Unable to clean up variation! (errno = %d)\n", 390 errno); 391 } 392 dm_handle_free(hanp, hlen); 393 } 394 } 395 396 /* 397 * TEST : dm_get_allocinfo - unaligned offp 398 * EXPECTED: rc = -1, errno = EINVAL 399 */ 400 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 7)) { 401 int fd; 402 void *hanp; 403 size_t hlen; 404 dm_off_t off = UNALIGNED_BLK_OFF; 405 u_int nelem; 406 407 /* Variation set up */ 408 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 409 if ((rc = system(command)) == -1) { 410 /* No clean up */ 411 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 412 remove(DUMMY_FILE); 413 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 414 close(fd); 415 remove(DUMMY_FILE); 416 } 417 if (fd == -1 || rc == -1) { 418 DMLOG_PRINT(DMLVL_DEBUG, 419 "Unable to set up variation! (errno = %d)\n", 420 errno); 421 DMVAR_SKIP(); 422 } else { 423 /* Variation */ 424 DMLOG_PRINT(DMLVL_DEBUG, "%s(unaligned offp)\n", 425 szFuncName); 426 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 427 &off, NUM_EXTENTS, Extents, 428 &nelem); 429 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 430 431 /* Variation clean up */ 432 rc = close(fd); 433 rc |= remove(DUMMY_FILE); 434 if (rc == -1) { 435 DMLOG_PRINT(DMLVL_DEBUG, 436 "Unable to clean up variation! (errno = %d)\n", 437 errno); 438 } 439 dm_handle_free(hanp, hlen); 440 } 441 } 442 443 /* 444 * TEST : dm_get_allocinfo - off past EOF 445 * EXPECTED: rc = -1, errno = EINVAL 446 */ 447 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 8)) { 448 int fd; 449 void *hanp; 450 size_t hlen; 451 dm_off_t off = TMP_FILELEN + 1; 452 u_int nelem; 453 454 /* Variation set up */ 455 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 456 if ((rc = system(command)) == -1) { 457 /* No clean up */ 458 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 459 remove(DUMMY_FILE); 460 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 461 close(fd); 462 remove(DUMMY_FILE); 463 } 464 if (fd == -1 || rc == -1) { 465 DMLOG_PRINT(DMLVL_DEBUG, 466 "Unable to set up variation! (errno = %d)\n", 467 errno); 468 DMVAR_SKIP(); 469 } else { 470 /* Variation */ 471 DMLOG_PRINT(DMLVL_DEBUG, "%s(off past EOF)\n", 472 szFuncName); 473 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 474 &off, NUM_EXTENTS, Extents, 475 &nelem); 476 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 477 478 /* Variation clean up */ 479 rc = close(fd); 480 rc |= remove(DUMMY_FILE); 481 if (rc == -1) { 482 DMLOG_PRINT(DMLVL_DEBUG, 483 "Unable to clean up variation! (errno = %d)\n", 484 errno); 485 } 486 dm_handle_free(hanp, hlen); 487 } 488 } 489 490 /* 491 * TEST : dm_get_allocinfo - zero nelem 492 * EXPECTED: rc = -1, errno = EINVAL 493 */ 494 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 9)) { 495 int fd; 496 void *hanp; 497 size_t hlen; 498 dm_off_t off = 0; 499 u_int nelem; 500 501 /* Variation set up */ 502 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 503 if ((rc = system(command)) == -1) { 504 /* No clean up */ 505 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 506 remove(DUMMY_FILE); 507 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 508 close(fd); 509 remove(DUMMY_FILE); 510 } 511 if (fd == -1 || rc == -1) { 512 DMLOG_PRINT(DMLVL_DEBUG, 513 "Unable to set up variation! (errno = %d)\n", 514 errno); 515 DMVAR_SKIP(); 516 } else { 517 /* Variation */ 518 DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem zero)\n", 519 szFuncName); 520 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 521 &off, 0, Extents, &nelem); 522 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 523 524 /* Variation clean up */ 525 rc = close(fd); 526 rc |= remove(DUMMY_FILE); 527 if (rc == -1) { 528 DMLOG_PRINT(DMLVL_DEBUG, 529 "Unable to clean up variation! (errno = %d)\n", 530 errno); 531 } 532 dm_handle_free(hanp, hlen); 533 } 534 } 535 536 /* 537 * TEST : dm_get_allocinfo - invalid extentp 538 * EXPECTED: rc = -1, errno = EFAULT 539 */ 540 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 10)) { 541 int fd; 542 void *hanp; 543 size_t hlen; 544 dm_off_t off = 0; 545 u_int nelem; 546 547 /* Variation set up */ 548 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 549 if ((rc = system(command)) == -1) { 550 /* No clean up */ 551 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 552 remove(DUMMY_FILE); 553 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 554 close(fd); 555 remove(DUMMY_FILE); 556 } 557 if (fd == -1 || rc == -1) { 558 DMLOG_PRINT(DMLVL_DEBUG, 559 "Unable to set up variation! (errno = %d)\n", 560 errno); 561 DMVAR_SKIP(); 562 } else { 563 /* Variation */ 564 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid extentp)\n", 565 szFuncName); 566 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 567 &off, NUM_EXTENTS, 568 (dm_extent_t *) INVALID_ADDR, 569 &nelem); 570 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 571 572 /* Variation clean up */ 573 rc = close(fd); 574 rc |= remove(DUMMY_FILE); 575 if (rc == -1) { 576 DMLOG_PRINT(DMLVL_DEBUG, 577 "Unable to clean up variation! (errno = %d)\n", 578 errno); 579 } 580 dm_handle_free(hanp, hlen); 581 } 582 } 583 584 /* 585 * TEST : dm_get_allocinfo - invalid nelemp 586 * EXPECTED: rc = -1, errno = EFAULT 587 */ 588 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 11)) { 589 int fd; 590 void *hanp; 591 size_t hlen; 592 dm_off_t off = 0; 593 594 /* Variation set up */ 595 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 596 if ((rc = system(command)) == -1) { 597 /* No clean up */ 598 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 599 remove(DUMMY_FILE); 600 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 601 close(fd); 602 remove(DUMMY_FILE); 603 } 604 if (fd == -1 || rc == -1) { 605 DMLOG_PRINT(DMLVL_DEBUG, 606 "Unable to set up variation! (errno = %d)\n", 607 errno); 608 DMVAR_SKIP(); 609 } else { 610 /* Variation */ 611 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid nelemp)\n", 612 szFuncName); 613 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 614 &off, NUM_EXTENTS, Extents, 615 (u_int *) INVALID_ADDR); 616 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 617 618 /* Variation clean up */ 619 rc = close(fd); 620 rc |= remove(DUMMY_FILE); 621 if (rc == -1) { 622 DMLOG_PRINT(DMLVL_DEBUG, 623 "Unable to clean up variation! (errno = %d)\n", 624 errno); 625 } 626 dm_handle_free(hanp, hlen); 627 } 628 } 629 630 /* 631 * TEST : dm_get_allocinfo - zero-length file 632 * EXPECTED: rc = 0, nelem = 0 633 */ 634 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 12)) { 635 int fd; 636 void *hanp; 637 size_t hlen; 638 dm_off_t off = 0; 639 u_int nelem; 640 641 /* Variation set up */ 642 if ((fd = 643 open(DUMMY_FILE, O_RDWR | O_CREAT, 644 DUMMY_FILE_RW_MODE)) == -1) { 645 /* No clean up */ 646 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 647 close(fd); 648 remove(DUMMY_FILE); 649 } 650 if (fd == -1 || rc == -1) { 651 DMLOG_PRINT(DMLVL_DEBUG, 652 "Unable to set up variation! (errno = %d)\n", 653 errno); 654 DMVAR_SKIP(); 655 } else { 656 /* Variation */ 657 DMLOG_PRINT(DMLVL_DEBUG, "%s(zero-length file)\n", 658 szFuncName); 659 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 660 &off, NUM_EXTENTS, Extents, 661 &nelem); 662 DMLOG_PRINT(DMLVL_DEBUG, 663 "dm_get_allocinfo returned %d\n", rc); 664 if (rc == 0) { 665 DMLOG_PRINT(DMLVL_DEBUG, " off = %lld\n", off); 666 if (nelem == 0) { 667 DMLOG_PRINT(DMLVL_DEBUG, 668 " nelem = %d\n", nelem); 669 DMVAR_PASS(); 670 } else { 671 DMLOG_PRINT(DMLVL_ERR, 672 "%s nelem NOT correct! (%d vs %d)\n", 673 szFuncName, nelem, 1); 674 DMVAR_FAIL(); 675 } 676 } else { 677 DMLOG_PRINT(DMLVL_ERR, 678 "%s failed with unexpected rc = %d (errno = %d)\n", 679 szFuncName, rc, errno); 680 DMVAR_FAIL(); 681 } 682 683 /* Variation clean up */ 684 rc = close(fd); 685 rc |= remove(DUMMY_FILE); 686 if (rc == -1) { 687 DMLOG_PRINT(DMLVL_DEBUG, 688 "Unable to clean up variation! (errno = %d)\n", 689 errno); 690 } 691 dm_handle_free(hanp, hlen); 692 } 693 } 694 695 /* 696 * TEST : dm_get_allocinfo - file all resident 697 * EXPECTED: rc = 0, nelem = 1 698 */ 699 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 13)) { 700 int fd; 701 void *hanp; 702 size_t hlen; 703 dm_off_t off = 0; 704 u_int nelem; 705 706 /* Variation set up */ 707 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 708 if ((rc = system(command)) == -1) { 709 /* No clean up */ 710 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 711 remove(DUMMY_FILE); 712 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 713 close(fd); 714 remove(DUMMY_FILE); 715 } 716 if (fd == -1 || rc == -1) { 717 DMLOG_PRINT(DMLVL_DEBUG, 718 "Unable to set up variation! (errno = %d)\n", 719 errno); 720 DMVAR_SKIP(); 721 } else { 722 /* Variation */ 723 DMLOG_PRINT(DMLVL_DEBUG, "%s(file all resident)\n", 724 szFuncName); 725 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 726 &off, NUM_EXTENTS, Extents, 727 &nelem); 728 DMLOG_PRINT(DMLVL_DEBUG, 729 "dm_get_allocinfo returned %d\n", rc); 730 if (rc == 0) { 731 DMLOG_PRINT(DMLVL_DEBUG, " off = %lld\n", off); 732 if (nelem == 1) { 733 DMLOG_PRINT(DMLVL_DEBUG, 734 " nelem = %d\n", nelem); 735 LogExtents(Extents, nelem); 736 if ((Extents[0].ex_length == 737 TMP_FILELEN) 738 && (Extents[0].ex_offset == 0) 739 && (Extents[0].ex_type == 740 DM_EXTENT_RES)) { 741 DMLOG_PRINT(DMLVL_DEBUG, 742 "%s extent information correct\n", 743 szFuncName); 744 DMVAR_PASS(); 745 } else { 746 DMLOG_PRINT(DMLVL_ERR, 747 "%s extent information NOT correct!\n", 748 szFuncName); 749 DMVAR_FAIL(); 750 } 751 } else { 752 DMLOG_PRINT(DMLVL_ERR, 753 "%s nelem NOT correct! (%d vs %d)\n", 754 szFuncName, nelem, 1); 755 DMVAR_FAIL(); 756 } 757 } else { 758 DMLOG_PRINT(DMLVL_ERR, 759 "%s failed with unexpected rc = %d (errno = %d)\n", 760 szFuncName, rc, errno); 761 DMVAR_FAIL(); 762 } 763 764 /* Variation clean up */ 765 rc = close(fd); 766 rc |= remove(DUMMY_FILE); 767 if (rc == -1) { 768 DMLOG_PRINT(DMLVL_DEBUG, 769 "Unable to clean up variation! (errno = %d)\n", 770 errno); 771 } 772 dm_handle_free(hanp, hlen); 773 } 774 } 775 776 /* 777 * TEST : dm_get_allocinfo - file all hole 778 * EXPECTED: rc = 0, nelem = 1 779 */ 780 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 14)) { 781 int fd; 782 void *hanp; 783 size_t hlen; 784 dm_off_t off = 0; 785 u_int nelem; 786 787 /* Variation set up */ 788 if ((fd = 789 open(DUMMY_FILE, O_RDWR | O_CREAT, 790 DUMMY_FILE_RW_MODE)) == -1) { 791 /* No clean up */ 792 } else 793 if (((off = 794 lseek(fd, TMP_FILELEN - DUMMY_STRLEN, 795 SEEK_SET)) != TMP_FILELEN - DUMMY_STRLEN) 796 || 797 ((rc = 798 (write(fd, DUMMY_STRING, DUMMY_STRLEN) != 799 DUMMY_STRLEN) ? -1 : 0) == -1) 800 || 801 ((rc = 802 ftruncate(fd, 803 ((TMP_FILELEN / 2) & (~(BLK_SIZE - 1))))) == 804 -1) 805 || ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1)) { 806 close(fd); 807 remove(DUMMY_FILE); 808 } 809 if (fd == -1 || off != (TMP_FILELEN - DUMMY_STRLEN) || rc == -1) { 810 DMLOG_PRINT(DMLVL_DEBUG, 811 "Unable to set up variation! (errno = %d)\n", 812 errno); 813 DMVAR_SKIP(); 814 } else { 815 /* Variation */ 816 off = 0; 817 DMLOG_PRINT(DMLVL_DEBUG, "%s(file all hole)\n", 818 szFuncName); 819 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 820 &off, NUM_EXTENTS, Extents, 821 &nelem); 822 DMLOG_PRINT(DMLVL_DEBUG, 823 "dm_get_allocinfo returned %d\n", rc); 824 if (rc == 0) { 825 DMLOG_PRINT(DMLVL_DEBUG, " off = %lld\n", off); 826 if (nelem == 1) { 827 DMLOG_PRINT(DMLVL_DEBUG, 828 " nelem = %d\n", nelem); 829 LogExtents(Extents, nelem); 830 if ((Extents[0].ex_length == 831 ((TMP_FILELEN / 832 2) & (~(BLK_SIZE - 1)))) 833 && (Extents[0].ex_offset == 0) 834 && (Extents[0].ex_type == 835 DM_EXTENT_HOLE)) { 836 DMLOG_PRINT(DMLVL_DEBUG, 837 "%s extent information correct\n", 838 szFuncName); 839 DMVAR_PASS(); 840 } else { 841 DMLOG_PRINT(DMLVL_ERR, 842 "%s extent information NOT correct!\n", 843 szFuncName); 844 DMVAR_FAIL(); 845 } 846 } else { 847 DMLOG_PRINT(DMLVL_ERR, 848 "%s nelem NOT correct! (%d vs %d)\n", 849 szFuncName, nelem, 1); 850 DMVAR_FAIL(); 851 } 852 } else { 853 DMLOG_PRINT(DMLVL_ERR, 854 "%s failed with unexpected rc = %d (errno = %d)\n", 855 szFuncName, rc, errno); 856 DMVAR_FAIL(); 857 } 858 859 /* Variation clean up */ 860 rc = close(fd); 861 rc |= remove(DUMMY_FILE); 862 if (rc == -1) { 863 DMLOG_PRINT(DMLVL_DEBUG, 864 "Unable to clean up variation! (errno = %d)\n", 865 errno); 866 } 867 dm_handle_free(hanp, hlen); 868 } 869 } 870 871 /* 872 * TEST : dm_get_allocinfo - hole, then resident 873 * EXPECTED: rc = 0, nelem = 2 874 */ 875 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 15)) { 876 int fd; 877 void *hanp; 878 size_t hlen; 879 dm_off_t off = 0; 880 u_int nelem; 881 882 /* Variation set up */ 883 if ((fd = 884 open(DUMMY_FILE, O_RDWR | O_CREAT, 885 DUMMY_FILE_RW_MODE)) == -1) { 886 /* No clean up */ 887 } else 888 if (((off = 889 lseek(fd, TMP_FILELEN - DUMMY_STRLEN, 890 SEEK_SET)) != TMP_FILELEN - DUMMY_STRLEN) 891 || 892 ((rc = 893 (write(fd, DUMMY_STRING, DUMMY_STRLEN) != 894 DUMMY_STRLEN) ? -1 : 0) == -1) 895 || ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1)) { 896 close(fd); 897 remove(DUMMY_FILE); 898 } 899 if (fd == -1 || off != (TMP_FILELEN - DUMMY_STRLEN) || rc == -1) { 900 DMLOG_PRINT(DMLVL_DEBUG, 901 "Unable to set up variation! (errno = %d)\n", 902 errno); 903 DMVAR_SKIP(); 904 } else { 905 /* Variation */ 906 off = 0; 907 DMLOG_PRINT(DMLVL_DEBUG, "%s(hole, resident)\n", 908 szFuncName); 909 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 910 &off, NUM_EXTENTS, Extents, 911 &nelem); 912 DMLOG_PRINT(DMLVL_DEBUG, "%s returned %d\n", szFuncName, 913 rc); 914 if (rc == 0) { 915 DMLOG_PRINT(DMLVL_DEBUG, " off = %lld\n", off); 916 if (nelem == 2) { 917 int i; 918 919 DMLOG_PRINT(DMLVL_DEBUG, 920 " nelem = %d\n", nelem); 921 LogExtents(Extents, nelem); 922 if ((i = 1) 923 && (Extents[0].ex_length + 924 Extents[1].ex_length == 925 TMP_FILELEN) && (i = 2) 926 && (Extents[0].ex_offset == 0) 927 && (i = 3) 928 && (Extents[0].ex_length == 929 Extents[1].ex_offset) && (i = 4) 930 && (Extents[0].ex_type == 931 DM_EXTENT_HOLE) && (i = 5) 932 && (Extents[1].ex_type == 933 DM_EXTENT_RES) 934 ) { 935 DMLOG_PRINT(DMLVL_DEBUG, 936 "%s extent information correct\n", 937 szFuncName); 938 DMVAR_PASS(); 939 } else { 940 DMLOG_PRINT(DMLVL_ERR, 941 "%s extent information NOT correct! (test %d failed)\n", 942 szFuncName, i); 943 DMVAR_FAIL(); 944 } 945 } else { 946 DMLOG_PRINT(DMLVL_ERR, 947 "%s nelem NOT correct! (%d vs %d)\n", 948 szFuncName, nelem, 2); 949 DMVAR_FAIL(); 950 } 951 } else { 952 DMLOG_PRINT(DMLVL_ERR, 953 "%s failed with unexpected rc = %d (errno = %d)\n", 954 szFuncName, rc, errno); 955 DMVAR_FAIL(); 956 } 957 958 /* Variation clean up */ 959 rc = close(fd); 960 rc |= remove(DUMMY_FILE); 961 if (rc == -1) { 962 DMLOG_PRINT(DMLVL_DEBUG, 963 "Unable to clean up variation! (errno = %d)\n", 964 errno); 965 } 966 dm_handle_free(hanp, hlen); 967 } 968 } 969 970 /* 971 * TEST : dm_get_allocinfo - resident, then hole 972 * EXPECTED: rc = 0, nelem = 2 973 */ 974 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 16)) { 975 int fd; 976 void *hanp; 977 size_t hlen; 978 dm_off_t off = 0; 979 u_int nelem; 980 981 /* Variation set up */ 982 if ((fd = 983 open(DUMMY_FILE, O_RDWR | O_CREAT, 984 DUMMY_FILE_RW_MODE)) == -1) { 985 /* No clean up */ 986 } else 987 if (((rc = 988 (write(fd, DUMMY_STRING, DUMMY_STRLEN) != 989 DUMMY_STRLEN) ? -1 : 0) == -1) 990 || 991 ((off = 992 lseek(fd, TMP_FILELEN - DUMMY_STRLEN, 993 SEEK_SET)) != TMP_FILELEN - DUMMY_STRLEN) 994 || 995 ((rc = 996 (write(fd, DUMMY_STRING, DUMMY_STRLEN) != 997 DUMMY_STRLEN) ? -1 : 0) == -1) 998 || 999 ((rc = 1000 ftruncate(fd, 1001 ((TMP_FILELEN / 2) & (~(BLK_SIZE - 1))))) == 1002 -1) 1003 || ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1)) { 1004 close(fd); 1005 remove(DUMMY_FILE); 1006 } 1007 if (fd == -1 || off != (TMP_FILELEN - DUMMY_STRLEN) || rc == -1) { 1008 DMLOG_PRINT(DMLVL_DEBUG, 1009 "Unable to set up variation! (errno = %d)\n", 1010 errno); 1011 DMVAR_SKIP(); 1012 } else { 1013 /* Variation */ 1014 off = 0; 1015 DMLOG_PRINT(DMLVL_DEBUG, "%s(resident, hole)\n", 1016 szFuncName); 1017 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 1018 &off, NUM_EXTENTS, Extents, 1019 &nelem); 1020 DMLOG_PRINT(DMLVL_DEBUG, "%s returned %d\n", szFuncName, 1021 rc); 1022 if (rc == 0) { 1023 DMLOG_PRINT(DMLVL_DEBUG, " off = %lld\n", off); 1024 if (nelem == 2) { 1025 int i; 1026 1027 DMLOG_PRINT(DMLVL_DEBUG, 1028 " nelem = %d\n", nelem); 1029 LogExtents(Extents, nelem); 1030 if ((i = 1) 1031 && (Extents[0].ex_length + 1032 Extents[1].ex_length == 1033 ((TMP_FILELEN / 1034 2) & (~(BLK_SIZE - 1)))) 1035 && (i = 2) 1036 && (Extents[0].ex_offset == 0) 1037 && (i = 3) 1038 && (Extents[0].ex_length == 1039 Extents[1].ex_offset) && (i = 4) 1040 && (Extents[0].ex_type == 1041 DM_EXTENT_RES) && (i = 5) 1042 && (Extents[1].ex_type == 1043 DM_EXTENT_HOLE) 1044 ) { 1045 DMLOG_PRINT(DMLVL_DEBUG, 1046 "%s extent information correct\n", 1047 szFuncName); 1048 DMVAR_PASS(); 1049 } else { 1050 DMLOG_PRINT(DMLVL_ERR, 1051 "%s extent information NOT correct! (test %d failed)\n", 1052 szFuncName, i); 1053 DMVAR_FAIL(); 1054 } 1055 } else { 1056 DMLOG_PRINT(DMLVL_ERR, 1057 "%s nelem NOT correct! (%d vs %d)\n", 1058 szFuncName, nelem, 2); 1059 DMVAR_FAIL(); 1060 } 1061 } else { 1062 DMLOG_PRINT(DMLVL_ERR, 1063 "%s failed with unexpected rc = %d (errno = %d)\n", 1064 szFuncName, rc, errno); 1065 DMVAR_FAIL(); 1066 } 1067 1068 /* Variation clean up */ 1069 rc = close(fd); 1070 rc |= remove(DUMMY_FILE); 1071 if (rc == -1) { 1072 DMLOG_PRINT(DMLVL_DEBUG, 1073 "Unable to clean up variation! (errno = %d)\n", 1074 errno); 1075 } 1076 dm_handle_free(hanp, hlen); 1077 } 1078 } 1079 1080 /* 1081 * TEST : dm_get_allocinfo - resident, then hole, then resident 1082 * EXPECTED: rc = 0, nelem = 3 1083 */ 1084 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 17)) { 1085 int fd; 1086 void *hanp; 1087 size_t hlen; 1088 dm_off_t off = 0; 1089 u_int nelem; 1090 1091 /* Variation set up */ 1092 if ((fd = 1093 open(DUMMY_FILE, O_RDWR | O_CREAT, 1094 DUMMY_FILE_RW_MODE)) == -1) { 1095 /* No clean up */ 1096 } else 1097 if (((rc = 1098 (write(fd, DUMMY_STRING, DUMMY_STRLEN) != 1099 DUMMY_STRLEN) ? -1 : 0) == -1) 1100 || 1101 ((off = 1102 lseek(fd, TMP_FILELEN - DUMMY_STRLEN, 1103 SEEK_SET)) != TMP_FILELEN - DUMMY_STRLEN) 1104 || 1105 ((rc = 1106 (write(fd, DUMMY_STRING, DUMMY_STRLEN) != 1107 DUMMY_STRLEN) ? -1 : 0) == -1) 1108 || ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1)) { 1109 close(fd); 1110 remove(DUMMY_FILE); 1111 } 1112 if (fd == -1 || off != (TMP_FILELEN - DUMMY_STRLEN) || rc == -1) { 1113 DMLOG_PRINT(DMLVL_DEBUG, 1114 "Unable to set up variation! (errno = %d)\n", 1115 errno); 1116 DMVAR_SKIP(); 1117 } else { 1118 /* Variation */ 1119 off = 0; 1120 DMLOG_PRINT(DMLVL_DEBUG, 1121 "%s(resident, hole, resident)\n", 1122 szFuncName); 1123 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 1124 &off, NUM_EXTENTS, Extents, 1125 &nelem); 1126 DMLOG_PRINT(DMLVL_DEBUG, "%s returned %d\n", szFuncName, 1127 rc); 1128 if (rc == 0) { 1129 int i; 1130 DMLOG_PRINT(DMLVL_DEBUG, " off = %lld\n", off); 1131 1132 if (nelem == 3) { 1133 DMLOG_PRINT(DMLVL_DEBUG, 1134 " nelem = %d\n", nelem); 1135 LogExtents(Extents, nelem); 1136 if ((i = 1) 1137 && (Extents[0].ex_length + 1138 Extents[1].ex_length + 1139 Extents[2].ex_length == 1140 TMP_FILELEN) && (i = 2) 1141 && (Extents[0].ex_offset == 0) 1142 && (i = 3) 1143 && (Extents[0].ex_length == 1144 Extents[1].ex_offset) && (i = 4) 1145 && (Extents[1].ex_length + 1146 Extents[1].ex_offset == 1147 Extents[2].ex_offset) && (i = 5) 1148 && (Extents[0].ex_type == 1149 DM_EXTENT_RES) && (i = 6) 1150 && (Extents[1].ex_type == 1151 DM_EXTENT_HOLE) && (i = 7) 1152 && (Extents[2].ex_type == 1153 DM_EXTENT_RES) 1154 ) { 1155 DMLOG_PRINT(DMLVL_DEBUG, 1156 "%s extent information correct\n", 1157 szFuncName); 1158 DMVAR_PASS(); 1159 } else { 1160 DMLOG_PRINT(DMLVL_ERR, 1161 "%s extent information NOT correct! (test %d failed)\n", 1162 szFuncName, i); 1163 DMVAR_FAIL(); 1164 } 1165 } else { 1166 DMLOG_PRINT(DMLVL_ERR, 1167 "%s nelem NOT correct! (%d vs %d)\n", 1168 szFuncName, nelem, 3); 1169 DMVAR_FAIL(); 1170 } 1171 } else { 1172 DMLOG_PRINT(DMLVL_ERR, 1173 "%s failed with unexpected rc = %d (errno = %d)\n", 1174 szFuncName, rc, errno); 1175 DMVAR_FAIL(); 1176 } 1177 1178 /* Variation clean up */ 1179 rc = close(fd); 1180 rc |= remove(DUMMY_FILE); 1181 if (rc == -1) { 1182 DMLOG_PRINT(DMLVL_DEBUG, 1183 "Unable to clean up variation! (errno = %d)\n", 1184 errno); 1185 } 1186 dm_handle_free(hanp, hlen); 1187 } 1188 } 1189 1190 /* 1191 * TEST : dm_get_allocinfo - resident, then hole, then resident, then hole, etc. 1192 * EXPECTED: rc = 1, nelem = 8 1193 */ 1194 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 18)) { 1195 int fd; 1196 void *hanp; 1197 size_t hlen; 1198 dm_off_t off = 0; 1199 u_int nelem; 1200 int i; 1201 1202 /* Variation set up */ 1203 fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE); 1204 for (i = 0, rc = 0; rc == 0 && i < TMP_FILELEN; 1205 i += TMP_FILELEN / (NUM_EXTENTS + 2)) { 1206 if ((rc = 1207 (write(fd, DUMMY_STRING, DUMMY_STRLEN) != 1208 DUMMY_STRLEN) ? -1 : 0) != -1) { 1209 if ((off = lseek(fd, i, SEEK_SET)) != off) { 1210 rc = -1; 1211 } 1212 } 1213 } 1214 if ((rc == -1) || 1215 ((off = 1216 lseek(fd, TMP_FILELEN - DUMMY_STRLEN, SEEK_SET)) != off) 1217 || 1218 ((rc = 1219 (write(fd, DUMMY_STRING, DUMMY_STRLEN) != 1220 DUMMY_STRLEN) ? -1 : 0) == -1) 1221 || ((rc = dm_fd_to_handle(fd, &hanp, &hlen)))) { 1222 close(fd); 1223 remove(DUMMY_FILE); 1224 } 1225 if (fd == -1 || off != TMP_FILELEN - DUMMY_STRLEN || rc == -1) { 1226 DMLOG_PRINT(DMLVL_DEBUG, 1227 "Unable to set up variation! (errno = %d)\n", 1228 errno); 1229 DMVAR_SKIP(); 1230 } else { 1231 /* Variation */ 1232 off = 0; 1233 DMLOG_PRINT(DMLVL_DEBUG, 1234 "%s(resident, hole, resident, hole, etc.)\n", 1235 szFuncName); 1236 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 1237 &off, NUM_EXTENTS, Extents, 1238 &nelem); 1239 DMLOG_PRINT(DMLVL_DEBUG, "%s returned %d\n", szFuncName, 1240 rc); 1241 if (rc == 1) { 1242 int i; 1243 DMLOG_PRINT(DMLVL_DEBUG, " off = %lld\n", off); 1244 1245 if (nelem == NUM_EXTENTS) { 1246 DMLOG_PRINT(DMLVL_DEBUG, 1247 " nelem = %d\n", nelem); 1248 LogExtents(Extents, nelem); 1249 if ((i = 1) 1250 && (Extents[0].ex_offset == 0) 1251 && (i = 2) 1252 && (Extents[0].ex_length == 1253 Extents[1].ex_offset) && (i = 3) 1254 && (Extents[1].ex_length + 1255 Extents[1].ex_offset == 1256 Extents[2].ex_offset) && (i = 4) 1257 && (Extents[2].ex_length + 1258 Extents[2].ex_offset == 1259 Extents[3].ex_offset) && (i = 5) 1260 && (Extents[3].ex_length + 1261 Extents[3].ex_offset == 1262 Extents[4].ex_offset) && (i = 6) 1263 && (Extents[4].ex_length + 1264 Extents[4].ex_offset == 1265 Extents[5].ex_offset) && (i = 7) 1266 && (Extents[5].ex_length + 1267 Extents[5].ex_offset == 1268 Extents[6].ex_offset) && (i = 8) 1269 && (Extents[6].ex_length + 1270 Extents[6].ex_offset == 1271 Extents[7].ex_offset) && (i = 9) 1272 && (Extents[7].ex_length + 1273 Extents[7].ex_offset == off) 1274 && (i = 10) 1275 && (Extents[0].ex_type == 1276 DM_EXTENT_RES) && (i = 11) 1277 && (Extents[1].ex_type == 1278 DM_EXTENT_HOLE) && (i = 12) 1279 && (Extents[2].ex_type == 1280 DM_EXTENT_RES) && (i = 13) 1281 && (Extents[3].ex_type == 1282 DM_EXTENT_HOLE) && (i = 14) 1283 && (Extents[4].ex_type == 1284 DM_EXTENT_RES) && (i = 15) 1285 && (Extents[5].ex_type == 1286 DM_EXTENT_HOLE) && (i = 16) 1287 && (Extents[6].ex_type == 1288 DM_EXTENT_RES) && (i = 17) 1289 && (Extents[7].ex_type == 1290 DM_EXTENT_HOLE) 1291 ) { 1292 DMLOG_PRINT(DMLVL_DEBUG, 1293 "%s extent information correct\n", 1294 szFuncName); 1295 1296 rc = dm_get_allocinfo(sid, hanp, 1297 hlen, 1298 DM_NO_TOKEN, 1299 &off, 1300 sizeof 1301 (bigExtents) 1302 / 1303 sizeof 1304 (dm_extent_t), 1305 bigExtents, 1306 &nelem); 1307 DMLOG_PRINT(DMLVL_DEBUG, 1308 "second %s returned %d\n", 1309 szFuncName, rc); 1310 if (rc == 0) { 1311 DMLOG_PRINT(DMLVL_DEBUG, 1312 " nelem = %d\n", 1313 nelem); 1314 LogExtents(bigExtents, 1315 nelem); 1316 if (bigExtents 1317 [nelem - 1318 1].ex_offset + 1319 bigExtents[nelem - 1320 1]. 1321 ex_length == 1322 TMP_FILELEN) { 1323 DMLOG_PRINT 1324 (DMLVL_DEBUG, 1325 "second %s extent information correct\n", 1326 szFuncName); 1327 DMVAR_PASS(); 1328 } else { 1329 DMLOG_PRINT 1330 (DMLVL_ERR, 1331 "second %s extent information NOT correct!\n", 1332 szFuncName); 1333 DMVAR_FAIL(); 1334 } 1335 } else { 1336 DMLOG_PRINT(DMLVL_ERR, 1337 "second %s failed with unexpected rc = %d (errno = %d)\n", 1338 szFuncName, 1339 rc, errno); 1340 DMVAR_FAIL(); 1341 } 1342 } else { 1343 DMLOG_PRINT(DMLVL_ERR, 1344 "%s extent information NOT correct! (test %d failed)\n", 1345 szFuncName, i); 1346 DMVAR_FAIL(); 1347 } 1348 } else { 1349 DMLOG_PRINT(DMLVL_ERR, 1350 "%s nelem NOT correct! (%d vs %d)\n", 1351 szFuncName, nelem, 3); 1352 DMVAR_FAIL(); 1353 } 1354 } else { 1355 DMLOG_PRINT(DMLVL_ERR, 1356 "%s failed with unexpected rc = %d (errno = %d)\n", 1357 szFuncName, rc, errno); 1358 DMVAR_FAIL(); 1359 } 1360 1361 /* Variation clean up */ 1362 rc = close(fd); 1363 rc |= remove(DUMMY_FILE); 1364 if (rc == -1) { 1365 DMLOG_PRINT(DMLVL_DEBUG, 1366 "Unable to clean up variation! (errno = %d)\n", 1367 errno); 1368 } 1369 dm_handle_free(hanp, hlen); 1370 } 1371 } 1372 1373 /* 1374 * TEST : dm_get_allocinfo - DM_NO_SESSION sid 1375 * EXPECTED: rc = -1, errno = EINVAL 1376 */ 1377 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 19)) { 1378 int fd; 1379 void *hanp; 1380 size_t hlen; 1381 dm_off_t off = 0; 1382 u_int nelem; 1383 1384 /* Variation set up */ 1385 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1386 if ((rc = system(command)) == -1) { 1387 /* No clean up */ 1388 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1389 remove(DUMMY_FILE); 1390 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1391 close(fd); 1392 remove(DUMMY_FILE); 1393 } 1394 if (fd == -1 || rc == -1) { 1395 DMLOG_PRINT(DMLVL_DEBUG, 1396 "Unable to set up variation! (errno = %d)\n", 1397 errno); 1398 DMVAR_SKIP(); 1399 } else { 1400 /* Variation */ 1401 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", 1402 szFuncName); 1403 rc = dm_get_allocinfo(DM_NO_SESSION, hanp, hlen, 1404 DM_NO_TOKEN, &off, NUM_EXTENTS, 1405 Extents, &nelem); 1406 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1407 1408 /* Variation clean up */ 1409 rc = close(fd); 1410 rc |= remove(DUMMY_FILE); 1411 if (rc == -1) { 1412 DMLOG_PRINT(DMLVL_DEBUG, 1413 "Unable to clean up variation! (errno = %d)\n", 1414 errno); 1415 } 1416 dm_handle_free(hanp, hlen); 1417 } 1418 } 1419 1420 /* 1421 * TEST : dm_get_allocinfo - fs handle 1422 * EXPECTED: rc = -1, errno = EINVAL 1423 */ 1424 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 20)) { 1425 void *hanp; 1426 size_t hlen; 1427 dm_off_t off = 0; 1428 u_int nelem; 1429 1430 /* Variation set up */ 1431 if ((rc = mkdir(DUMMY_SUBDIR, DUMMY_DIR_RW_MODE)) == -1) { 1432 /* No clean up */ 1433 } else 1434 if ((rc = 1435 dm_path_to_fshandle(DUMMY_SUBDIR, &hanp, 1436 &hlen)) == -1) { 1437 rmdir(DUMMY_SUBDIR); 1438 } 1439 if (rc == -1) { 1440 DMLOG_PRINT(DMLVL_DEBUG, 1441 "Unable to set up variation! (errno = %d)\n", 1442 errno); 1443 DMVAR_SKIP(); 1444 } else { 1445 /* Variation */ 1446 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); 1447 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 1448 &off, NUM_EXTENTS, Extents, 1449 &nelem); 1450 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1451 1452 /* Variation clean up */ 1453 rc = rmdir(DUMMY_SUBDIR); 1454 if (rc == -1) { 1455 DMLOG_PRINT(DMLVL_DEBUG, 1456 "Unable to clean up variation! (errno = %d)\n", 1457 errno); 1458 } 1459 dm_handle_free(hanp, hlen); 1460 } 1461 } 1462 1463 /* 1464 * TEST : dm_get_allocinfo - global handle 1465 * EXPECTED: rc = -1, errno = EBADF 1466 */ 1467 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 21)) { 1468 dm_off_t off = 0; 1469 u_int nelem; 1470 1471 /* Variation set up */ 1472 1473 /* Variation */ 1474 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); 1475 rc = dm_get_allocinfo(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, 1476 DM_NO_TOKEN, &off, NUM_EXTENTS, Extents, 1477 &nelem); 1478 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 1479 1480 /* Variation clean up */ 1481 } 1482 1483 /* 1484 * TEST : dm_get_allocinfo - invalidated hanp 1485 * EXPECTED: rc = -1, errno = EBADF 1486 */ 1487 if (DMVAR_EXEC(GET_ALLOCINFO_BASE + 22)) { 1488 int fd; 1489 void *hanp; 1490 size_t hlen; 1491 dm_off_t off = 0; 1492 u_int nelem; 1493 1494 /* Variation set up */ 1495 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1496 if ((rc = system(command)) == -1) { 1497 /* No clean up */ 1498 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1499 remove(DUMMY_FILE); 1500 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1501 close(fd); 1502 remove(DUMMY_FILE); 1503 } else if ((rc = close(fd)) == -1) { 1504 dm_handle_free(hanp, hlen); 1505 remove(DUMMY_FILE); 1506 } else if ((rc = remove(DUMMY_FILE)) == -1) { 1507 dm_handle_free(hanp, hlen); 1508 } 1509 if (fd == -1 || rc == -1) { 1510 DMLOG_PRINT(DMLVL_DEBUG, 1511 "Unable to set up variation! (errno = %d)\n", 1512 errno); 1513 DMVAR_SKIP(); 1514 } else { 1515 /* Variation */ 1516 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalidated hanp)\n", 1517 szFuncName); 1518 rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, 1519 &off, NUM_EXTENTS, Extents, 1520 &nelem); 1521 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 1522 1523 /* Variation clean up */ 1524 dm_handle_free(hanp, hlen); 1525 } 1526 } 1527 1528 szFuncName = "dm_probe_hole"; 1529 1530 /* 1531 * TEST : dm_probe_hole - invalid sid 1532 * EXPECTED: rc = -1, errno = EINVAL 1533 */ 1534 if (DMVAR_EXEC(PROBE_HOLE_BASE + 1)) { 1535 int fd; 1536 void *hanp; 1537 size_t hlen; 1538 dm_off_t inoff = 0, outoff; 1539 dm_size_t inlen = 0, outlen; 1540 1541 /* Variation set up */ 1542 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1543 if ((rc = system(command)) == -1) { 1544 /* No clean up */ 1545 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1546 remove(DUMMY_FILE); 1547 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1548 close(fd); 1549 remove(DUMMY_FILE); 1550 } 1551 if (fd == -1 || rc == -1) { 1552 DMLOG_PRINT(DMLVL_DEBUG, 1553 "Unable to set up variation! (errno = %d)\n", 1554 errno); 1555 DMVAR_SKIP(); 1556 } else { 1557 /* Variation */ 1558 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", 1559 szFuncName); 1560 rc = dm_probe_hole(INVALID_ADDR, hanp, hlen, 1561 DM_NO_TOKEN, inoff, inlen, &outoff, 1562 &outlen); 1563 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1564 1565 /* Variation clean up */ 1566 rc = close(fd); 1567 rc |= remove(DUMMY_FILE); 1568 if (rc == -1) { 1569 DMLOG_PRINT(DMLVL_DEBUG, 1570 "Unable to clean up variation! (errno = %d)\n", 1571 errno); 1572 } 1573 dm_handle_free(hanp, hlen); 1574 } 1575 } 1576 1577 /* 1578 * TEST : dm_probe_hole - invalid hanp 1579 * EXPECTED: rc = -1, errno = EFAULT 1580 */ 1581 if (DMVAR_EXEC(PROBE_HOLE_BASE + 2)) { 1582 int fd; 1583 void *hanp; 1584 size_t hlen; 1585 dm_off_t inoff = 0, outoff; 1586 dm_size_t inlen = 0, outlen; 1587 1588 /* Variation set up */ 1589 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1590 if ((rc = system(command)) == -1) { 1591 /* No clean up */ 1592 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1593 remove(DUMMY_FILE); 1594 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1595 close(fd); 1596 remove(DUMMY_FILE); 1597 } 1598 if (fd == -1 || rc == -1) { 1599 DMLOG_PRINT(DMLVL_DEBUG, 1600 "Unable to set up variation! (errno = %d)\n", 1601 errno); 1602 DMVAR_SKIP(); 1603 } else { 1604 /* Variation */ 1605 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", 1606 szFuncName); 1607 rc = dm_probe_hole(sid, (void *)INVALID_ADDR, hlen, 1608 DM_NO_TOKEN, inoff, inlen, &outoff, 1609 &outlen); 1610 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 1611 1612 /* Variation clean up */ 1613 rc = close(fd); 1614 rc |= remove(DUMMY_FILE); 1615 if (rc == -1) { 1616 DMLOG_PRINT(DMLVL_DEBUG, 1617 "Unable to clean up variation! (errno = %d)\n", 1618 errno); 1619 } 1620 dm_handle_free(hanp, hlen); 1621 } 1622 } 1623 1624 /* 1625 * TEST : dm_probe_hole - directory handle 1626 * EXPECTED: rc = -1, errno = EINVAL 1627 */ 1628 if (DMVAR_EXEC(PROBE_HOLE_BASE + 3)) { 1629 void *hanp; 1630 size_t hlen; 1631 dm_off_t inoff = 0, outoff; 1632 dm_size_t inlen = 0, outlen; 1633 1634 /* Variation set up */ 1635 if ((rc = mkdir(DUMMY_SUBDIR, DUMMY_DIR_RW_MODE)) == -1) { 1636 /* No clean up */ 1637 } else if ((rc = dm_path_to_handle(DUMMY_SUBDIR, &hanp, &hlen)) 1638 == -1) { 1639 rmdir(DUMMY_SUBDIR); 1640 } 1641 if (rc == -1) { 1642 DMLOG_PRINT(DMLVL_DEBUG, 1643 "Unable to set up variation! (errno = %d)\n", 1644 errno); 1645 DMVAR_SKIP(); 1646 } else { 1647 /* Variation */ 1648 DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n", 1649 szFuncName); 1650 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 1651 inlen, &outoff, &outlen); 1652 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1653 1654 /* Variation clean up */ 1655 rc = rmdir(DUMMY_SUBDIR); 1656 if (rc == -1) { 1657 DMLOG_PRINT(DMLVL_DEBUG, 1658 "Unable to clean up variation! (errno = %d)\n", 1659 errno); 1660 } 1661 dm_handle_free(hanp, hlen); 1662 } 1663 } 1664 1665 /* 1666 * TEST : dm_probe_hole - invalid hlen 1667 * EXPECTED: rc = -1, errno = EBADF 1668 */ 1669 if (DMVAR_EXEC(PROBE_HOLE_BASE + 4)) { 1670 int fd; 1671 void *hanp; 1672 size_t hlen; 1673 dm_off_t inoff = 0, outoff; 1674 dm_size_t inlen = 0, outlen; 1675 1676 /* Variation set up */ 1677 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1678 if ((rc = system(command)) == -1) { 1679 /* No clean up */ 1680 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1681 remove(DUMMY_FILE); 1682 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1683 close(fd); 1684 remove(DUMMY_FILE); 1685 } 1686 if (fd == -1 || rc == -1) { 1687 DMLOG_PRINT(DMLVL_DEBUG, 1688 "Unable to set up variation! (errno = %d)\n", 1689 errno); 1690 DMVAR_SKIP(); 1691 } else { 1692 /* Variation */ 1693 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", 1694 szFuncName); 1695 rc = dm_probe_hole(sid, hanp, INVALID_ADDR, DM_NO_TOKEN, 1696 inoff, inlen, &outoff, &outlen); 1697 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 1698 1699 /* Variation clean up */ 1700 rc = close(fd); 1701 rc |= remove(DUMMY_FILE); 1702 if (rc == -1) { 1703 DMLOG_PRINT(DMLVL_DEBUG, 1704 "Unable to clean up variation! (errno = %d)\n", 1705 errno); 1706 } 1707 dm_handle_free(hanp, hlen); 1708 } 1709 } 1710 1711 /* 1712 * TEST : dm_probe_hole - invalid token 1713 * EXPECTED: rc = -1, errno = EINVAL 1714 */ 1715 if (DMVAR_EXEC(PROBE_HOLE_BASE + 5)) { 1716 int fd; 1717 void *hanp; 1718 size_t hlen; 1719 dm_off_t inoff = 0, outoff; 1720 dm_size_t inlen = 0, outlen; 1721 1722 /* Variation set up */ 1723 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1724 if ((rc = system(command)) == -1) { 1725 /* No clean up */ 1726 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1727 remove(DUMMY_FILE); 1728 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1729 close(fd); 1730 remove(DUMMY_FILE); 1731 } 1732 if (fd == -1 || rc == -1) { 1733 DMLOG_PRINT(DMLVL_DEBUG, 1734 "Unable to set up variation! (errno = %d)\n", 1735 errno); 1736 DMVAR_SKIP(); 1737 } else { 1738 /* Variation */ 1739 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", 1740 szFuncName); 1741 rc = dm_probe_hole(sid, hanp, hlen, INVALID_ADDR, inoff, 1742 inlen, &outoff, &outlen); 1743 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1744 1745 /* Variation clean up */ 1746 rc = close(fd); 1747 rc |= remove(DUMMY_FILE); 1748 if (rc == -1) { 1749 DMLOG_PRINT(DMLVL_DEBUG, 1750 "Unable to clean up variation! (errno = %d)\n", 1751 errno); 1752 } 1753 dm_handle_free(hanp, hlen); 1754 } 1755 } 1756 1757 /* 1758 * TEST : dm_probe_hole - invalid off 1759 * EXPECTED: rc = -1, errno = E2BIG 1760 */ 1761 if (DMVAR_EXEC(PROBE_HOLE_BASE + 6)) { 1762 int fd; 1763 void *hanp; 1764 size_t hlen; 1765 dm_off_t inoff = TMP_FILELEN + 1, outoff; 1766 dm_size_t inlen = 0, outlen; 1767 1768 /* Variation set up */ 1769 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1770 if ((rc = system(command)) == -1) { 1771 /* No clean up */ 1772 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1773 remove(DUMMY_FILE); 1774 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1775 close(fd); 1776 remove(DUMMY_FILE); 1777 } 1778 if (fd == -1 || rc == -1) { 1779 DMLOG_PRINT(DMLVL_DEBUG, 1780 "Unable to set up variation! (errno = %d)\n", 1781 errno); 1782 DMVAR_SKIP(); 1783 } else { 1784 /* Variation */ 1785 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid off)\n", 1786 szFuncName); 1787 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 1788 inlen, &outoff, &outlen); 1789 DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG); 1790 1791 /* Variation clean up */ 1792 rc = close(fd); 1793 rc |= remove(DUMMY_FILE); 1794 if (rc == -1) { 1795 DMLOG_PRINT(DMLVL_DEBUG, 1796 "Unable to clean up variation! (errno = %d)\n", 1797 errno); 1798 } 1799 dm_handle_free(hanp, hlen); 1800 } 1801 } 1802 1803 /* 1804 * TEST : dm_probe_hole - invalid len 1805 * EXPECTED: rc = -1, errno = E2BIG 1806 * 1807 * This variation uncovered XFS BUG #8 (0 returned instead of -1 and 1808 * errno E2BIG) 1809 */ 1810 if (DMVAR_EXEC(PROBE_HOLE_BASE + 7)) { 1811 int fd; 1812 void *hanp; 1813 size_t hlen; 1814 dm_off_t inoff = 0, outoff; 1815 dm_size_t inlen = TMP_FILELEN + 1, outlen; 1816 1817 /* Variation set up */ 1818 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1819 if ((rc = system(command)) == -1) { 1820 /* No clean up */ 1821 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1822 remove(DUMMY_FILE); 1823 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1824 close(fd); 1825 remove(DUMMY_FILE); 1826 } 1827 if (fd == -1 || rc == -1) { 1828 DMLOG_PRINT(DMLVL_DEBUG, 1829 "Unable to set up variation! (errno = %d)\n", 1830 errno); 1831 DMVAR_SKIP(); 1832 } else { 1833 /* Variation */ 1834 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid len)\n", 1835 szFuncName); 1836 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 1837 inlen, &outoff, &outlen); 1838 DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG); 1839 1840 /* Variation clean up */ 1841 rc = close(fd); 1842 rc |= remove(DUMMY_FILE); 1843 if (rc == -1) { 1844 DMLOG_PRINT(DMLVL_DEBUG, 1845 "Unable to clean up variation! (errno = %d)\n", 1846 errno); 1847 } 1848 dm_handle_free(hanp, hlen); 1849 } 1850 } 1851 1852 /* 1853 * TEST : dm_probe_hole - invalid roffp 1854 * EXPECTED: rc = -1, errno = EFAULT 1855 */ 1856 if (DMVAR_EXEC(PROBE_HOLE_BASE + 8)) { 1857 int fd; 1858 void *hanp; 1859 size_t hlen; 1860 dm_off_t inoff = 0; 1861 dm_size_t inlen = 0, outlen; 1862 1863 /* Variation set up */ 1864 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1865 if ((rc = system(command)) == -1) { 1866 /* No clean up */ 1867 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1868 remove(DUMMY_FILE); 1869 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1870 close(fd); 1871 remove(DUMMY_FILE); 1872 } 1873 if (fd == -1 || rc == -1) { 1874 DMLOG_PRINT(DMLVL_DEBUG, 1875 "Unable to set up variation! (errno = %d)\n", 1876 errno); 1877 DMVAR_SKIP(); 1878 } else { 1879 /* Variation */ 1880 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid roffp)\n", 1881 szFuncName); 1882 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 1883 inlen, (dm_off_t *) INVALID_ADDR, 1884 &outlen); 1885 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 1886 1887 /* Variation clean up */ 1888 rc = close(fd); 1889 rc |= remove(DUMMY_FILE); 1890 if (rc == -1) { 1891 DMLOG_PRINT(DMLVL_DEBUG, 1892 "Unable to clean up variation! (errno = %d)\n", 1893 errno); 1894 } 1895 dm_handle_free(hanp, hlen); 1896 } 1897 } 1898 1899 /* 1900 * TEST : dm_probe_hole - invalid rlenp 1901 * EXPECTED: rc = -1, errno = EFAULT 1902 */ 1903 if (DMVAR_EXEC(PROBE_HOLE_BASE + 9)) { 1904 int fd; 1905 void *hanp; 1906 size_t hlen; 1907 dm_off_t inoff = 0, outoff; 1908 dm_size_t inlen = 0; 1909 1910 /* Variation set up */ 1911 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1912 if ((rc = system(command)) == -1) { 1913 /* No clean up */ 1914 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1915 remove(DUMMY_FILE); 1916 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1917 close(fd); 1918 remove(DUMMY_FILE); 1919 } 1920 if (fd == -1 || rc == -1) { 1921 DMLOG_PRINT(DMLVL_DEBUG, 1922 "Unable to set up variation! (errno = %d)\n", 1923 errno); 1924 DMVAR_SKIP(); 1925 } else { 1926 /* Variation */ 1927 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rlenp)\n", 1928 szFuncName); 1929 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 1930 inlen, &outoff, 1931 (dm_size_t *) INVALID_ADDR); 1932 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 1933 1934 /* Variation clean up */ 1935 rc = close(fd); 1936 rc |= remove(DUMMY_FILE); 1937 if (rc == -1) { 1938 DMLOG_PRINT(DMLVL_DEBUG, 1939 "Unable to clean up variation! (errno = %d)\n", 1940 errno); 1941 } 1942 dm_handle_free(hanp, hlen); 1943 } 1944 } 1945 1946 /* 1947 * TEST : dm_probe_hole - entire file 1948 * EXPECTED: rc = 0 1949 */ 1950 if (DMVAR_EXEC(PROBE_HOLE_BASE + 10)) { 1951 int fd; 1952 void *hanp; 1953 size_t hlen; 1954 dm_off_t inoff = 0, outoff; 1955 dm_size_t inlen = 0, outlen; 1956 1957 /* Variation set up */ 1958 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 1959 if ((rc = system(command)) == -1) { 1960 /* No clean up */ 1961 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 1962 remove(DUMMY_FILE); 1963 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 1964 close(fd); 1965 remove(DUMMY_FILE); 1966 } 1967 if (fd == -1 || rc == -1) { 1968 DMLOG_PRINT(DMLVL_DEBUG, 1969 "Unable to set up variation! (errno = %d)\n", 1970 errno); 1971 DMVAR_SKIP(); 1972 } else { 1973 /* Variation */ 1974 DMLOG_PRINT(DMLVL_DEBUG, "%s(entire file)\n", 1975 szFuncName); 1976 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 1977 inlen, &outoff, &outlen); 1978 if (rc == 0) { 1979 DMLOG_PRINT(DMLVL_DEBUG, 1980 "In -> offset %lld, length %lld\n", 1981 inoff, inlen); 1982 DMLOG_PRINT(DMLVL_DEBUG, 1983 "Out <- offset %lld, length %lld\n", 1984 outoff, outlen); 1985 if (outoff == inoff) { 1986 if (outlen == inlen) { 1987 DMLOG_PRINT(DMLVL_DEBUG, 1988 "%s passed with expected rc %d\n", 1989 szFuncName, rc); 1990 DMVAR_PASS(); 1991 } else { 1992 DMLOG_PRINT(DMLVL_ERR, 1993 "%s failed with expected rc %d but unexpected outlen (%d vs %d)\n", 1994 szFuncName, rc, 1995 outlen, inlen); 1996 DMVAR_FAIL(); 1997 } 1998 } else { 1999 DMLOG_PRINT(DMLVL_ERR, 2000 "%s failed with expected rc %d but unexpected outoff (%d vs %d)\n", 2001 szFuncName, rc, outoff, 2002 inoff); 2003 DMVAR_FAIL(); 2004 } 2005 } else { 2006 DMLOG_PRINT(DMLVL_ERR, 2007 "%s failed with unexpected rc = %d (errno = %d)\n", 2008 szFuncName, rc, errno); 2009 DMVAR_FAIL(); 2010 } 2011 2012 /* Variation clean up */ 2013 rc = close(fd); 2014 rc |= remove(DUMMY_FILE); 2015 if (rc == -1) { 2016 DMLOG_PRINT(DMLVL_DEBUG, 2017 "Unable to clean up variation! (errno = %d)\n", 2018 errno); 2019 } 2020 dm_handle_free(hanp, hlen); 2021 } 2022 } 2023 2024 /* 2025 * TEST : dm_probe_hole - end of file without rounding 2026 * EXPECTED: rc = 0 2027 */ 2028 if (DMVAR_EXEC(PROBE_HOLE_BASE + 11)) { 2029 int fd; 2030 void *hanp; 2031 size_t hlen; 2032 dm_off_t inoff = BLKALIGN(UNALIGNED_BLK_OFF), outoff; 2033 dm_size_t inlen = 0, outlen; 2034 2035 /* Variation set up */ 2036 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2037 if ((rc = system(command)) == -1) { 2038 /* No clean up */ 2039 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2040 remove(DUMMY_FILE); 2041 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2042 close(fd); 2043 remove(DUMMY_FILE); 2044 } 2045 if (fd == -1 || rc == -1) { 2046 DMLOG_PRINT(DMLVL_DEBUG, 2047 "Unable to set up variation! (errno = %d)\n", 2048 errno); 2049 DMVAR_SKIP(); 2050 } else { 2051 /* Variation */ 2052 DMLOG_PRINT(DMLVL_DEBUG, 2053 "%s(end of file without rounding)\n", 2054 szFuncName); 2055 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 2056 inlen, &outoff, &outlen); 2057 if (rc == 0) { 2058 DMLOG_PRINT(DMLVL_DEBUG, 2059 "In -> offset %lld, length %lld\n", 2060 inoff, inlen); 2061 DMLOG_PRINT(DMLVL_DEBUG, 2062 "Out <- offset %lld, length %lld\n", 2063 outoff, outlen); 2064 if (outoff == inoff) { 2065 if (outlen == inlen) { 2066 DMLOG_PRINT(DMLVL_DEBUG, 2067 "%s passed with expected rc %d\n", 2068 szFuncName, rc); 2069 DMVAR_PASS(); 2070 } else { 2071 DMLOG_PRINT(DMLVL_ERR, 2072 "%s failed with expected rc %d but unexpected outlen (%d vs %d)\n", 2073 szFuncName, rc, 2074 outlen, inlen); 2075 DMVAR_FAIL(); 2076 } 2077 } else { 2078 DMLOG_PRINT(DMLVL_ERR, 2079 "%s failed with expected rc %d but unexpected outoff (%d vs %d)\n", 2080 szFuncName, rc, outoff, 2081 inoff); 2082 DMVAR_FAIL(); 2083 } 2084 } else { 2085 DMLOG_PRINT(DMLVL_ERR, 2086 "%s failed with unexpected rc = %d (errno = %d)\n", 2087 szFuncName, rc, errno); 2088 DMVAR_FAIL(); 2089 } 2090 2091 /* Variation clean up */ 2092 rc = close(fd); 2093 rc |= remove(DUMMY_FILE); 2094 if (rc == -1) { 2095 DMLOG_PRINT(DMLVL_DEBUG, 2096 "Unable to clean up variation! (errno = %d)\n", 2097 errno); 2098 } 2099 dm_handle_free(hanp, hlen); 2100 } 2101 } 2102 2103 /* 2104 * TEST : dm_probe_hole - end of file with rounding 2105 * EXPECTED: rc = 0 2106 */ 2107 if (DMVAR_EXEC(PROBE_HOLE_BASE + 12)) { 2108 int fd; 2109 void *hanp; 2110 size_t hlen; 2111 dm_off_t inoff = UNALIGNED_BLK_OFF, outoff; 2112 dm_size_t inlen = TMP_FILELEN - UNALIGNED_BLK_OFF, outlen; 2113 2114 /* Variation set up */ 2115 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2116 if ((rc = system(command)) == -1) { 2117 /* No clean up */ 2118 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2119 remove(DUMMY_FILE); 2120 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2121 close(fd); 2122 remove(DUMMY_FILE); 2123 } 2124 if (fd == -1 || rc == -1) { 2125 DMLOG_PRINT(DMLVL_DEBUG, 2126 "Unable to set up variation! (errno = %d)\n", 2127 errno); 2128 DMVAR_SKIP(); 2129 } else { 2130 /* Variation */ 2131 DMLOG_PRINT(DMLVL_DEBUG, 2132 "%s(end of file with rounding)\n", 2133 szFuncName); 2134 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 2135 inlen, &outoff, &outlen); 2136 if (rc == 0) { 2137 DMLOG_PRINT(DMLVL_DEBUG, 2138 "In -> offset %lld, length %lld\n", 2139 inoff, inlen); 2140 DMLOG_PRINT(DMLVL_DEBUG, 2141 "Out <- offset %lld, length %lld\n", 2142 outoff, outlen); 2143 if ((outoff >= inoff) 2144 && (!(outoff & (BLK_SIZE - 1)))) { 2145 if (outlen == 0) { 2146 DMLOG_PRINT(DMLVL_DEBUG, 2147 "%s passed with expected rc %d\n", 2148 szFuncName, rc); 2149 DMVAR_PASS(); 2150 } else { 2151 DMLOG_PRINT(DMLVL_ERR, 2152 "%s failed with expected rc %d but unexpected outlen (%d vs %d)\n", 2153 szFuncName, rc, 2154 outlen, 0); 2155 DMVAR_FAIL(); 2156 } 2157 } else { 2158 DMLOG_PRINT(DMLVL_ERR, 2159 "%s failed with expected rc %d but unexpected outoff %d\n", 2160 szFuncName, rc, outoff); 2161 DMVAR_FAIL(); 2162 } 2163 } else { 2164 DMLOG_PRINT(DMLVL_ERR, 2165 "%s failed with unexpected rc = %d (errno = %d)\n", 2166 szFuncName, rc, errno); 2167 DMVAR_FAIL(); 2168 } 2169 2170 /* Variation clean up */ 2171 rc = close(fd); 2172 rc |= remove(DUMMY_FILE); 2173 if (rc == -1) { 2174 DMLOG_PRINT(DMLVL_DEBUG, 2175 "Unable to clean up variation! (errno = %d)\n", 2176 errno); 2177 } 2178 dm_handle_free(hanp, hlen); 2179 } 2180 } 2181 2182 /* 2183 * TEST : dm_probe_hole - middle of file without rounding 2184 * EXPECTED: rc = 0 2185 */ 2186 if (DMVAR_EXEC(PROBE_HOLE_BASE + 13)) { 2187 #ifdef INTERIOR_HOLES 2188 int fd; 2189 void *hanp; 2190 size_t hlen; 2191 dm_off_t inoff = BLKALIGN(UNALIGNED_BLK_OFF), outoff; 2192 dm_size_t inlen = 2193 BLKALIGN(TMP_FILELEN - BLK_SIZE - UNALIGNED_BLK_OFF), 2194 outlen; 2195 2196 /* Variation set up */ 2197 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2198 if ((rc = system(command)) == -1) { 2199 /* No clean up */ 2200 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2201 remove(DUMMY_FILE); 2202 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2203 close(fd); 2204 remove(DUMMY_FILE); 2205 } 2206 if (fd == -1 || rc == -1) { 2207 DMLOG_PRINT(DMLVL_DEBUG, 2208 "Unable to set up variation! (errno = %d)\n", 2209 errno); 2210 DMVAR_SKIP(); 2211 } else { 2212 /* Variation */ 2213 DMLOG_PRINT(DMLVL_DEBUG, 2214 "%s(middle of file without rounding)\n", 2215 szFuncName); 2216 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 2217 inlen, &outoff, &outlen); 2218 if (rc == 0) { 2219 DMLOG_PRINT(DMLVL_DEBUG, 2220 "In -> offset %lld, length %lld\n", 2221 inoff, inlen); 2222 DMLOG_PRINT(DMLVL_DEBUG, 2223 "Out <- offset %lld, length %lld\n", 2224 outoff, outlen); 2225 if (outoff == inoff) { 2226 if (outlen == inlen) { 2227 DMLOG_PRINT(DMLVL_DEBUG, 2228 "%s passed with expected rc %d\n", 2229 szFuncName, rc); 2230 DMVAR_PASS(); 2231 } else { 2232 DMLOG_PRINT(DMLVL_ERR, 2233 "%s failed with expected rc %d but unexpected outlen (%d vs %d)\n", 2234 szFuncName, rc, 2235 outlen, inlen); 2236 DMVAR_FAIL(); 2237 } 2238 } else { 2239 DMLOG_PRINT(DMLVL_ERR, 2240 "%s failed with expected rc %d but unexpected outoff (%d vs %d)\n", 2241 szFuncName, rc, outoff, 2242 inoff); 2243 DMVAR_FAIL(); 2244 } 2245 } else { 2246 DMLOG_PRINT(DMLVL_ERR, 2247 "%s failed with unexpected rc = %d (errno = %d)\n", 2248 szFuncName, rc, errno); 2249 DMVAR_FAIL(); 2250 } 2251 2252 /* Variation clean up */ 2253 rc = close(fd); 2254 rc |= remove(DUMMY_FILE); 2255 if (rc == -1) { 2256 DMLOG_PRINT(DMLVL_DEBUG, 2257 "Unable to clean up variation! (errno = %d)\n", 2258 errno); 2259 } 2260 dm_handle_free(hanp, hlen); 2261 } 2262 #else 2263 DMLOG_PRINT(DMLVL_WARN, 2264 "Test case not built with INTERIOR_HOLES defined\n"); 2265 DMVAR_SKIP(); 2266 #endif 2267 } 2268 2269 /* 2270 * TEST : dm_probe_hole - middle of file with rounding, large 2271 * EXPECTED: rc = 0 2272 */ 2273 if (DMVAR_EXEC(PROBE_HOLE_BASE + 14)) { 2274 #ifdef INTERIOR_HOLES 2275 int fd; 2276 void *hanp; 2277 size_t hlen; 2278 dm_off_t inoff = UNALIGNED_BLK_OFF, outoff; 2279 dm_size_t inlen = 2280 TMP_FILELEN - BLK_SIZE - UNALIGNED_BLK_OFF, outlen; 2281 2282 /* Variation set up */ 2283 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2284 if ((rc = system(command)) == -1) { 2285 /* No clean up */ 2286 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2287 remove(DUMMY_FILE); 2288 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2289 close(fd); 2290 remove(DUMMY_FILE); 2291 } 2292 if (fd == -1 || rc == -1) { 2293 DMLOG_PRINT(DMLVL_DEBUG, 2294 "Unable to set up variation! (errno = %d)\n", 2295 errno); 2296 DMVAR_SKIP(); 2297 } else { 2298 /* Variation */ 2299 DMLOG_PRINT(DMLVL_DEBUG, 2300 "%s(middle of file with rounding, large)\n", 2301 szFuncName); 2302 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 2303 inlen, &outoff, &outlen); 2304 if (rc == 0) { 2305 DMLOG_PRINT(DMLVL_DEBUG, 2306 "In -> offset %lld, length %lld\n", 2307 inoff, inlen); 2308 DMLOG_PRINT(DMLVL_DEBUG, 2309 "Out <- offset %lld, length %lld\n", 2310 outoff, outlen); 2311 if ((outoff >= inoff) 2312 && (!(outoff & (BLK_SIZE - 1)))) { 2313 if ((outlen <= inlen) 2314 && (!(outlen & (BLK_SIZE - 1)))) { 2315 DMLOG_PRINT(DMLVL_DEBUG, 2316 "%s passed with expected rc %d\n", 2317 szFuncName, rc); 2318 DMVAR_PASS(); 2319 } else { 2320 DMLOG_PRINT(DMLVL_ERR, 2321 "%s failed with expected rc %d but unexpected outlen %d\n", 2322 szFuncName, rc, 2323 outlen); 2324 DMVAR_FAIL(); 2325 } 2326 } else { 2327 DMLOG_PRINT(DMLVL_ERR, 2328 "%s failed with expected rc %d but unexpected outoff %d\n", 2329 szFuncName, rc, outoff); 2330 DMVAR_FAIL(); 2331 } 2332 } else { 2333 DMLOG_PRINT(DMLVL_ERR, 2334 "%s failed with unexpected rc = %d (errno = %d)\n", 2335 szFuncName, rc, errno); 2336 DMVAR_FAIL(); 2337 } 2338 2339 /* Variation clean up */ 2340 rc = close(fd); 2341 rc |= remove(DUMMY_FILE); 2342 if (rc == -1) { 2343 DMLOG_PRINT(DMLVL_DEBUG, 2344 "Unable to clean up variation! (errno = %d)\n", 2345 errno); 2346 } 2347 dm_handle_free(hanp, hlen); 2348 } 2349 #else 2350 DMLOG_PRINT(DMLVL_WARN, 2351 "Test case not built with INTERIOR_HOLES defined\n"); 2352 DMVAR_SKIP(); 2353 #endif 2354 } 2355 2356 /* 2357 * TEST : dm_probe_hole - middle of file with rounding, small 2358 * EXPECTED: rc = 0 2359 */ 2360 if (DMVAR_EXEC(PROBE_HOLE_BASE + 15)) { 2361 #ifdef INTERIOR_HOLES 2362 int fd; 2363 void *hanp; 2364 size_t hlen; 2365 dm_off_t inoff = TMP_FILELEN / 2 - BLK_SIZE, outoff; 2366 dm_size_t inlen = 5 * BLK_SIZE, outlen; 2367 2368 /* Variation set up */ 2369 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2370 if ((rc = system(command)) == -1) { 2371 /* No clean up */ 2372 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2373 remove(DUMMY_FILE); 2374 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2375 close(fd); 2376 remove(DUMMY_FILE); 2377 } 2378 if (fd == -1 || rc == -1) { 2379 DMLOG_PRINT(DMLVL_DEBUG, 2380 "Unable to set up variation! (errno = %d)\n", 2381 errno); 2382 DMVAR_SKIP(); 2383 } else { 2384 /* Variation */ 2385 DMLOG_PRINT(DMLVL_DEBUG, 2386 "%s(middle of file with rounding, small)\n", 2387 szFuncName); 2388 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 2389 inlen, &outoff, &outlen); 2390 if (rc == 0) { 2391 DMLOG_PRINT(DMLVL_DEBUG, 2392 "In -> offset %lld, length %lld\n", 2393 inoff, inlen); 2394 DMLOG_PRINT(DMLVL_DEBUG, 2395 "Out <- offset %lld, length %lld\n", 2396 outoff, outlen); 2397 if ((outoff >= inoff) 2398 && (!(outoff & (BLK_SIZE - 1)))) { 2399 if ((outlen <= inlen) 2400 && (!(outlen & (BLK_SIZE - 1)))) { 2401 DMLOG_PRINT(DMLVL_DEBUG, 2402 "%s passed with expected rc %d\n", 2403 szFuncName, rc); 2404 DMVAR_PASS(); 2405 } else { 2406 DMLOG_PRINT(DMLVL_ERR, 2407 "%s failed with expected rc %d but unexpected outlen %d\n", 2408 szFuncName, rc, 2409 outlen); 2410 DMVAR_FAIL(); 2411 } 2412 } else { 2413 DMLOG_PRINT(DMLVL_ERR, 2414 "%s failed with expected rc %d but unexpected outoff %d\n", 2415 szFuncName, rc, outoff); 2416 DMVAR_FAIL(); 2417 } 2418 } else { 2419 DMLOG_PRINT(DMLVL_ERR, 2420 "%s failed with unexpected rc = %d (errno = %d)\n", 2421 szFuncName, rc, errno); 2422 DMVAR_FAIL(); 2423 } 2424 2425 /* Variation clean up */ 2426 rc = close(fd); 2427 rc |= remove(DUMMY_FILE); 2428 if (rc == -1) { 2429 DMLOG_PRINT(DMLVL_DEBUG, 2430 "Unable to clean up variation! (errno = %d)\n", 2431 errno); 2432 } 2433 dm_handle_free(hanp, hlen); 2434 } 2435 #else 2436 DMLOG_PRINT(DMLVL_WARN, 2437 "Test case not built with INTERIOR_HOLES defined\n"); 2438 DMVAR_SKIP(); 2439 #endif 2440 } 2441 2442 /* 2443 * TEST : dm_probe_hole - middle of file with rounding, no hole 2444 * EXPECTED: rc = -1, errno = EINVAL 2445 */ 2446 if (DMVAR_EXEC(PROBE_HOLE_BASE + 16)) { 2447 #ifdef INTERIOR_HOLES 2448 int fd; 2449 void *hanp; 2450 size_t hlen; 2451 dm_off_t inoff = 2452 ((TMP_FILELEN / 2) & ~(BLK_SIZE - 1)) + 1, outoff; 2453 dm_size_t inlen = BLK_SIZE, outlen; 2454 2455 /* Variation set up */ 2456 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2457 if ((rc = system(command)) == -1) { 2458 /* No clean up */ 2459 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2460 remove(DUMMY_FILE); 2461 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2462 close(fd); 2463 remove(DUMMY_FILE); 2464 } 2465 if (fd == -1 || rc == -1) { 2466 DMLOG_PRINT(DMLVL_DEBUG, 2467 "Unable to set up variation! (errno = %d)\n", 2468 errno); 2469 DMVAR_SKIP(); 2470 } else { 2471 /* Variation */ 2472 DMLOG_PRINT(DMLVL_DEBUG, 2473 "%s(middle of file with rounding, no hole)\n", 2474 szFuncName); 2475 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 2476 inlen, &outoff, &outlen); 2477 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 2478 2479 /* Variation clean up */ 2480 rc = close(fd); 2481 rc |= remove(DUMMY_FILE); 2482 if (rc == -1) { 2483 DMLOG_PRINT(DMLVL_DEBUG, 2484 "Unable to clean up variation! (errno = %d)\n", 2485 errno); 2486 } 2487 dm_handle_free(hanp, hlen); 2488 } 2489 #else 2490 DMLOG_PRINT(DMLVL_WARN, 2491 "Test case not built with INTERIOR_HOLES defined\n"); 2492 DMVAR_SKIP(); 2493 #endif 2494 } 2495 2496 /* 2497 * TEST : dm_probe_hole - DM_NO_SESSION sid 2498 * EXPECTED: rc = -1, errno = EINVAL 2499 */ 2500 if (DMVAR_EXEC(PROBE_HOLE_BASE + 17)) { 2501 int fd; 2502 void *hanp; 2503 size_t hlen; 2504 dm_off_t inoff = 0, outoff; 2505 dm_size_t inlen = 0, outlen; 2506 2507 /* Variation set up */ 2508 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2509 if ((rc = system(command)) == -1) { 2510 /* No clean up */ 2511 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2512 remove(DUMMY_FILE); 2513 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2514 close(fd); 2515 remove(DUMMY_FILE); 2516 } 2517 if (fd == -1 || rc == -1) { 2518 DMLOG_PRINT(DMLVL_DEBUG, 2519 "Unable to set up variation! (errno = %d)\n", 2520 errno); 2521 DMVAR_SKIP(); 2522 } else { 2523 /* Variation */ 2524 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", 2525 szFuncName); 2526 rc = dm_probe_hole(DM_NO_SESSION, hanp, hlen, 2527 DM_NO_TOKEN, inoff, inlen, &outoff, 2528 &outlen); 2529 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 2530 2531 /* Variation clean up */ 2532 rc = close(fd); 2533 rc |= remove(DUMMY_FILE); 2534 if (rc == -1) { 2535 DMLOG_PRINT(DMLVL_DEBUG, 2536 "Unable to clean up variation! (errno = %d)\n", 2537 errno); 2538 } 2539 dm_handle_free(hanp, hlen); 2540 } 2541 } 2542 2543 /* 2544 * TEST : dm_probe_hole - fs handle 2545 * EXPECTED: rc = -1, errno = EINVAL 2546 */ 2547 if (DMVAR_EXEC(PROBE_HOLE_BASE + 18)) { 2548 void *hanp; 2549 size_t hlen; 2550 dm_off_t inoff = 0, outoff; 2551 dm_size_t inlen = 0, outlen; 2552 2553 /* Variation set up */ 2554 if ((rc = mkdir(DUMMY_SUBDIR, DUMMY_DIR_RW_MODE)) == -1) { 2555 /* No clean up */ 2556 } else 2557 if ((rc = 2558 dm_path_to_fshandle(DUMMY_SUBDIR, &hanp, 2559 &hlen)) == -1) { 2560 rmdir(DUMMY_SUBDIR); 2561 } 2562 if (rc == -1) { 2563 DMLOG_PRINT(DMLVL_DEBUG, 2564 "Unable to set up variation! (errno = %d)\n", 2565 errno); 2566 DMVAR_SKIP(); 2567 } else { 2568 /* Variation */ 2569 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); 2570 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 2571 inlen, &outoff, &outlen); 2572 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 2573 2574 /* Variation clean up */ 2575 rc = rmdir(DUMMY_SUBDIR); 2576 if (rc == -1) { 2577 DMLOG_PRINT(DMLVL_DEBUG, 2578 "Unable to clean up variation! (errno = %d)\n", 2579 errno); 2580 } 2581 dm_handle_free(hanp, hlen); 2582 } 2583 } 2584 2585 /* 2586 * TEST : dm_probe_hole - global handle 2587 * EXPECTED: rc = -1, errno = EBADF 2588 */ 2589 if (DMVAR_EXEC(PROBE_HOLE_BASE + 19)) { 2590 dm_off_t inoff = 0, outoff; 2591 dm_size_t inlen = 0, outlen; 2592 2593 /* Variation set up */ 2594 2595 /* Variation */ 2596 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); 2597 rc = dm_probe_hole(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, 2598 DM_NO_TOKEN, inoff, inlen, &outoff, &outlen); 2599 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 2600 2601 /* Variation clean up */ 2602 } 2603 2604 /* 2605 * TEST : dm_probe_hole - invalidated hanp 2606 * EXPECTED: rc = -1, errno = EBADF 2607 */ 2608 if (DMVAR_EXEC(PROBE_HOLE_BASE + 20)) { 2609 int fd; 2610 void *hanp; 2611 size_t hlen; 2612 dm_off_t inoff = 0, outoff; 2613 dm_size_t inlen = 0, outlen; 2614 2615 /* Variation set up */ 2616 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2617 if ((rc = system(command)) == -1) { 2618 /* No clean up */ 2619 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2620 remove(DUMMY_FILE); 2621 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2622 close(fd); 2623 remove(DUMMY_FILE); 2624 } else if ((rc = close(fd)) == -1) { 2625 dm_handle_free(hanp, hlen); 2626 remove(DUMMY_FILE); 2627 } else if ((rc = remove(DUMMY_FILE)) == -1) { 2628 dm_handle_free(hanp, hlen); 2629 } 2630 if (fd == -1 || rc == -1) { 2631 DMLOG_PRINT(DMLVL_DEBUG, 2632 "Unable to set up variation! (errno = %d)\n", 2633 errno); 2634 DMVAR_SKIP(); 2635 } else { 2636 /* Variation */ 2637 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalidated hanp)\n", 2638 szFuncName); 2639 rc = dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, inoff, 2640 inlen, &outoff, &outlen); 2641 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 2642 2643 /* Variation clean up */ 2644 dm_handle_free(hanp, hlen); 2645 } 2646 } 2647 2648 szFuncName = "dm_punch_hole"; 2649 2650 /* 2651 * TEST : dm_punch_hole - invalid sid 2652 * EXPECTED: rc = -1, errno = EINVAL 2653 */ 2654 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 1)) { 2655 int fd; 2656 void *hanp; 2657 size_t hlen; 2658 dm_off_t off = 0; 2659 dm_size_t len = 0; 2660 2661 /* Variation set up */ 2662 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2663 if ((rc = system(command)) == -1) { 2664 /* No clean up */ 2665 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2666 remove(DUMMY_FILE); 2667 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2668 close(fd); 2669 remove(DUMMY_FILE); 2670 } 2671 if (fd == -1 || rc == -1) { 2672 DMLOG_PRINT(DMLVL_DEBUG, 2673 "Unable to set up variation! (errno = %d)\n", 2674 errno); 2675 DMVAR_SKIP(); 2676 } else { 2677 /* Variation */ 2678 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", 2679 szFuncName); 2680 rc = dm_punch_hole(INVALID_ADDR, hanp, hlen, 2681 DM_NO_TOKEN, off, len); 2682 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 2683 2684 /* Variation clean up */ 2685 rc = close(fd); 2686 rc |= remove(DUMMY_FILE); 2687 if (rc == -1) { 2688 DMLOG_PRINT(DMLVL_DEBUG, 2689 "Unable to clean up variation! (errno = %d)\n", 2690 errno); 2691 } 2692 dm_handle_free(hanp, hlen); 2693 } 2694 } 2695 2696 /* 2697 * TEST : dm_punch_hole - invalid hanp 2698 * EXPECTED: rc = -1, errno = EFAULT 2699 */ 2700 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 2)) { 2701 int fd; 2702 void *hanp; 2703 size_t hlen; 2704 dm_off_t off = 0; 2705 dm_size_t len = 0; 2706 2707 /* Variation set up */ 2708 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2709 if ((rc = system(command)) == -1) { 2710 /* No clean up */ 2711 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2712 remove(DUMMY_FILE); 2713 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2714 close(fd); 2715 remove(DUMMY_FILE); 2716 } 2717 if (fd == -1 || rc == -1) { 2718 DMLOG_PRINT(DMLVL_DEBUG, 2719 "Unable to set up variation! (errno = %d)\n", 2720 errno); 2721 DMVAR_SKIP(); 2722 } else { 2723 /* Variation */ 2724 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", 2725 szFuncName); 2726 rc = dm_punch_hole(sid, (void *)INVALID_ADDR, hlen, 2727 DM_NO_TOKEN, off, len); 2728 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 2729 2730 /* Variation clean up */ 2731 rc = close(fd); 2732 rc |= remove(DUMMY_FILE); 2733 if (rc == -1) { 2734 DMLOG_PRINT(DMLVL_DEBUG, 2735 "Unable to clean up variation! (errno = %d)\n", 2736 errno); 2737 } 2738 dm_handle_free(hanp, hlen); 2739 } 2740 } 2741 2742 /* 2743 * TEST : dm_punch_hole - directory handle 2744 * EXPECTED: rc = -1, errno = EINVAL 2745 */ 2746 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 3)) { 2747 void *hanp; 2748 size_t hlen; 2749 dm_off_t off = 0; 2750 dm_size_t len = 0; 2751 2752 /* Variation set up */ 2753 if ((rc = mkdir(DUMMY_SUBDIR, DUMMY_DIR_RW_MODE)) == -1) { 2754 /* No clean up */ 2755 } else if ((rc = dm_path_to_handle(DUMMY_SUBDIR, &hanp, &hlen)) 2756 == -1) { 2757 rmdir(DUMMY_SUBDIR); 2758 } 2759 if (rc == -1) { 2760 DMLOG_PRINT(DMLVL_DEBUG, 2761 "Unable to set up variation! (errno = %d)\n", 2762 errno); 2763 DMVAR_SKIP(); 2764 } else { 2765 /* Variation */ 2766 DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n", 2767 szFuncName); 2768 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 2769 len); 2770 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 2771 2772 /* Variation clean up */ 2773 rc = rmdir(DUMMY_SUBDIR); 2774 if (rc == -1) { 2775 DMLOG_PRINT(DMLVL_DEBUG, 2776 "Unable to clean up variation! (errno = %d)\n", 2777 errno); 2778 } 2779 dm_handle_free(hanp, hlen); 2780 } 2781 } 2782 2783 /* 2784 * TEST : dm_punch_hole - invalid hlen 2785 * EXPECTED: rc = -1, errno = EBADF 2786 */ 2787 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 4)) { 2788 int fd; 2789 void *hanp; 2790 size_t hlen; 2791 dm_off_t off = 0; 2792 dm_size_t len = 0; 2793 2794 /* Variation set up */ 2795 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2796 if ((rc = system(command)) == -1) { 2797 /* No clean up */ 2798 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2799 remove(DUMMY_FILE); 2800 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2801 close(fd); 2802 remove(DUMMY_FILE); 2803 } 2804 if (fd == -1 || rc == -1) { 2805 DMLOG_PRINT(DMLVL_DEBUG, 2806 "Unable to set up variation! (errno = %d)\n", 2807 errno); 2808 DMVAR_SKIP(); 2809 } else { 2810 /* Variation */ 2811 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", 2812 szFuncName); 2813 rc = dm_punch_hole(sid, hanp, INVALID_ADDR, DM_NO_TOKEN, 2814 off, len); 2815 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 2816 2817 /* Variation clean up */ 2818 rc = close(fd); 2819 rc |= remove(DUMMY_FILE); 2820 if (rc == -1) { 2821 DMLOG_PRINT(DMLVL_DEBUG, 2822 "Unable to clean up variation! (errno = %d)\n", 2823 errno); 2824 } 2825 dm_handle_free(hanp, hlen); 2826 } 2827 } 2828 2829 /* 2830 * TEST : dm_punch_hole - invalid token 2831 * EXPECTED: rc = -1, errno = EINVAL 2832 */ 2833 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 5)) { 2834 int fd; 2835 void *hanp; 2836 size_t hlen; 2837 dm_off_t off = 0; 2838 dm_size_t len = 0; 2839 2840 /* Variation set up */ 2841 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2842 if ((rc = system(command)) == -1) { 2843 /* No clean up */ 2844 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2845 remove(DUMMY_FILE); 2846 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2847 close(fd); 2848 remove(DUMMY_FILE); 2849 } 2850 if (fd == -1 || rc == -1) { 2851 DMLOG_PRINT(DMLVL_DEBUG, 2852 "Unable to set up variation! (errno = %d)\n", 2853 errno); 2854 DMVAR_SKIP(); 2855 } else { 2856 /* Variation */ 2857 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", 2858 szFuncName); 2859 rc = dm_punch_hole(sid, hanp, hlen, INVALID_ADDR, off, 2860 len); 2861 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 2862 2863 /* Variation clean up */ 2864 rc = close(fd); 2865 rc |= remove(DUMMY_FILE); 2866 if (rc == -1) { 2867 DMLOG_PRINT(DMLVL_DEBUG, 2868 "Unable to clean up variation! (errno = %d)\n", 2869 errno); 2870 } 2871 dm_handle_free(hanp, hlen); 2872 } 2873 } 2874 2875 /* 2876 * TEST : dm_punch_hole - invalid off 2877 * EXPECTED: rc = -1, errno = E2BIG 2878 */ 2879 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 6)) { 2880 int fd; 2881 void *hanp; 2882 size_t hlen; 2883 dm_off_t off = TMP_FILELEN + 1; 2884 dm_size_t len = 0; 2885 2886 /* Variation set up */ 2887 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2888 if ((rc = system(command)) == -1) { 2889 /* No clean up */ 2890 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2891 remove(DUMMY_FILE); 2892 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2893 close(fd); 2894 remove(DUMMY_FILE); 2895 } 2896 if (fd == -1 || rc == -1) { 2897 DMLOG_PRINT(DMLVL_DEBUG, 2898 "Unable to set up variation! (errno = %d)\n", 2899 errno); 2900 DMVAR_SKIP(); 2901 } else { 2902 /* Variation */ 2903 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid off)\n", 2904 szFuncName); 2905 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 2906 len); 2907 DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG); 2908 2909 /* Variation clean up */ 2910 rc = close(fd); 2911 rc |= remove(DUMMY_FILE); 2912 if (rc == -1) { 2913 DMLOG_PRINT(DMLVL_DEBUG, 2914 "Unable to clean up variation! (errno = %d)\n", 2915 errno); 2916 } 2917 dm_handle_free(hanp, hlen); 2918 } 2919 } 2920 2921 /* 2922 * TEST : dm_punch_hole - invalid len 2923 * EXPECTED: rc = -1, errno = E2BIG 2924 */ 2925 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 7)) { 2926 int fd; 2927 void *hanp; 2928 size_t hlen; 2929 dm_off_t off = 0; 2930 dm_size_t len = TMP_FILELEN + 1; 2931 2932 /* Variation set up */ 2933 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2934 if ((rc = system(command)) == -1) { 2935 /* No clean up */ 2936 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2937 remove(DUMMY_FILE); 2938 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2939 close(fd); 2940 remove(DUMMY_FILE); 2941 } 2942 if (fd == -1 || rc == -1) { 2943 DMLOG_PRINT(DMLVL_DEBUG, 2944 "Unable to set up variation! (errno = %d)\n", 2945 errno); 2946 DMVAR_SKIP(); 2947 } else { 2948 /* Variation */ 2949 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid len)\n", 2950 szFuncName); 2951 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 2952 len); 2953 DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG); 2954 2955 /* Variation clean up */ 2956 rc = close(fd); 2957 rc |= remove(DUMMY_FILE); 2958 if (rc == -1) { 2959 DMLOG_PRINT(DMLVL_DEBUG, 2960 "Unable to clean up variation! (errno = %d)\n", 2961 errno); 2962 } 2963 dm_handle_free(hanp, hlen); 2964 } 2965 } 2966 2967 /* 2968 * TEST : dm_punch_hole - unaligned off 2969 * EXPECTED: rc = -1, errno = EAGAIN 2970 */ 2971 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 8)) { 2972 int fd; 2973 void *hanp; 2974 size_t hlen; 2975 dm_off_t off = 1; 2976 dm_size_t len = 0; 2977 2978 /* Variation set up */ 2979 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 2980 if ((rc = system(command)) == -1) { 2981 /* No clean up */ 2982 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 2983 remove(DUMMY_FILE); 2984 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 2985 close(fd); 2986 remove(DUMMY_FILE); 2987 } 2988 if (fd == -1 || rc == -1) { 2989 DMLOG_PRINT(DMLVL_DEBUG, 2990 "Unable to set up variation! (errno = %d)\n", 2991 errno); 2992 DMVAR_SKIP(); 2993 } else { 2994 /* Variation */ 2995 DMLOG_PRINT(DMLVL_DEBUG, "%s(unaligned off)\n", 2996 szFuncName); 2997 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 2998 len); 2999 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EAGAIN); 3000 3001 /* Variation clean up */ 3002 rc = close(fd); 3003 rc |= remove(DUMMY_FILE); 3004 if (rc == -1) { 3005 DMLOG_PRINT(DMLVL_DEBUG, 3006 "Unable to clean up variation! (errno = %d)\n", 3007 errno); 3008 } 3009 dm_handle_free(hanp, hlen); 3010 } 3011 } 3012 3013 /* 3014 * TEST : dm_punch_hole - unaligned len 3015 * EXPECTED: rc = -1, errno = EAGAIN 3016 */ 3017 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 9)) { 3018 int fd; 3019 void *hanp; 3020 size_t hlen; 3021 dm_off_t off = 0; 3022 dm_size_t len = 1; 3023 3024 /* Variation set up */ 3025 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3026 if ((rc = system(command)) == -1) { 3027 /* No clean up */ 3028 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3029 remove(DUMMY_FILE); 3030 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3031 close(fd); 3032 remove(DUMMY_FILE); 3033 } 3034 if (fd == -1 || rc == -1) { 3035 DMLOG_PRINT(DMLVL_DEBUG, 3036 "Unable to set up variation! (errno = %d)\n", 3037 errno); 3038 DMVAR_SKIP(); 3039 } else { 3040 /* Variation */ 3041 DMLOG_PRINT(DMLVL_DEBUG, "%s(unaligned len)\n", 3042 szFuncName); 3043 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3044 len); 3045 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EAGAIN); 3046 3047 /* Variation clean up */ 3048 rc = close(fd); 3049 rc |= remove(DUMMY_FILE); 3050 if (rc == -1) { 3051 DMLOG_PRINT(DMLVL_DEBUG, 3052 "Unable to clean up variation! (errno = %d)\n", 3053 errno); 3054 } 3055 dm_handle_free(hanp, hlen); 3056 } 3057 } 3058 3059 /* 3060 * TEST : dm_punch_hole - unaligned off and len 3061 * EXPECTED: rc = -1, errno = EAGAIN 3062 */ 3063 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 10)) { 3064 int fd; 3065 void *hanp; 3066 size_t hlen; 3067 dm_off_t off = UNALIGNED_BLK_OFF; 3068 dm_size_t len = TMP_FILELEN - UNALIGNED_BLK_OFF; 3069 3070 /* Variation set up */ 3071 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3072 if ((rc = system(command)) == -1) { 3073 /* No clean up */ 3074 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3075 remove(DUMMY_FILE); 3076 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3077 close(fd); 3078 remove(DUMMY_FILE); 3079 } 3080 if (fd == -1 || rc == -1) { 3081 DMLOG_PRINT(DMLVL_DEBUG, 3082 "Unable to set up variation! (errno = %d)\n", 3083 errno); 3084 DMVAR_SKIP(); 3085 } else { 3086 /* Variation */ 3087 DMLOG_PRINT(DMLVL_DEBUG, "%s(unaligned off and len)\n", 3088 szFuncName); 3089 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3090 len); 3091 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EAGAIN); 3092 3093 /* Variation clean up */ 3094 rc = close(fd); 3095 rc |= remove(DUMMY_FILE); 3096 if (rc == -1) { 3097 DMLOG_PRINT(DMLVL_DEBUG, 3098 "Unable to clean up variation! (errno = %d)\n", 3099 errno); 3100 } 3101 dm_handle_free(hanp, hlen); 3102 } 3103 } 3104 3105 /* 3106 * TEST : dm_punch_hole - truncate entire file 3107 * EXPECTED: rc = 0, nelem = 0 3108 */ 3109 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 11)) { 3110 int fd; 3111 void *hanp; 3112 size_t hlen; 3113 dm_off_t off = 0; 3114 dm_size_t len = 0; 3115 u_int nelem; 3116 3117 /* Variation set up */ 3118 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3119 if ((rc = system(command)) == -1) { 3120 /* No clean up */ 3121 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3122 remove(DUMMY_FILE); 3123 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3124 close(fd); 3125 remove(DUMMY_FILE); 3126 } 3127 if (fd == -1 || rc == -1) { 3128 DMLOG_PRINT(DMLVL_DEBUG, 3129 "Unable to set up variation! (errno = %d)\n", 3130 errno); 3131 DMVAR_SKIP(); 3132 } else { 3133 /* Variation */ 3134 DMLOG_PRINT(DMLVL_DEBUG, "%s(truncate entire file)\n", 3135 szFuncName); 3136 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3137 len); 3138 DMLOG_PRINT(DMLVL_DEBUG, "%s returned %d\n", szFuncName, 3139 rc); 3140 if (rc == 0) { 3141 off = 0; 3142 rc = dm_get_allocinfo(sid, hanp, hlen, 3143 DM_NO_TOKEN, &off, 3144 NUM_EXTENTS, Extents, 3145 &nelem); 3146 DMLOG_PRINT(DMLVL_DEBUG, 3147 "dm_get_allocinfo returned %d\n", 3148 rc); 3149 if (rc == 0) { 3150 if (nelem == 0) { 3151 DMLOG_PRINT(DMLVL_DEBUG, 3152 " nelem = %d\n", 3153 nelem); 3154 DMVAR_PASS(); 3155 } else { 3156 DMLOG_PRINT(DMLVL_ERR, 3157 "%s nelem NOT correct! (%d vs %d)\n", 3158 szFuncName, nelem, 3159 0); 3160 DMVAR_FAIL(); 3161 } 3162 } else { 3163 DMLOG_PRINT(DMLVL_ERR, 3164 "dm_get_allocinfo failed with unexpected rc = %d (errno = %d)\n", 3165 rc, errno); 3166 DMVAR_FAIL(); 3167 } 3168 } else { 3169 DMLOG_PRINT(DMLVL_ERR, 3170 "%s failed with unexpected rc = %d (errno = %d)\n", 3171 szFuncName, rc, errno); 3172 DMVAR_FAIL(); 3173 } 3174 3175 /* Variation clean up */ 3176 rc = close(fd); 3177 rc |= remove(DUMMY_FILE); 3178 if (rc == -1) { 3179 DMLOG_PRINT(DMLVL_DEBUG, 3180 "Unable to clean up variation! (errno = %d)\n", 3181 errno); 3182 } 3183 dm_handle_free(hanp, hlen); 3184 } 3185 } 3186 3187 /* 3188 * TEST : dm_punch_hole - truncate part of file, len 0 3189 * EXPECTED: rc = 0, nelem = 1 3190 */ 3191 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 12)) { 3192 int fd; 3193 void *hanp; 3194 size_t hlen; 3195 dm_off_t off = BLK_SIZE; 3196 dm_size_t len = 0; 3197 u_int nelem; 3198 3199 /* Variation set up */ 3200 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3201 if ((rc = system(command)) == -1) { 3202 /* No clean up */ 3203 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3204 remove(DUMMY_FILE); 3205 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3206 close(fd); 3207 remove(DUMMY_FILE); 3208 } 3209 if (fd == -1 || rc == -1) { 3210 DMLOG_PRINT(DMLVL_DEBUG, 3211 "Unable to set up variation! (errno = %d)\n", 3212 errno); 3213 DMVAR_SKIP(); 3214 } else { 3215 /* Variation */ 3216 DMLOG_PRINT(DMLVL_DEBUG, 3217 "%s(truncate part of file, len 0)\n", 3218 szFuncName); 3219 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3220 len); 3221 DMLOG_PRINT(DMLVL_DEBUG, "%s returned %d\n", szFuncName, 3222 rc); 3223 if (rc == 0) { 3224 off = 0; 3225 rc = dm_get_allocinfo(sid, hanp, hlen, 3226 DM_NO_TOKEN, &off, 3227 NUM_EXTENTS, Extents, 3228 &nelem); 3229 DMLOG_PRINT(DMLVL_DEBUG, 3230 "dm_get_allocinfo returned %d\n", 3231 rc); 3232 if (rc == 0) { 3233 if (nelem == 1) { 3234 DMLOG_PRINT(DMLVL_DEBUG, 3235 " nelem = %d\n", 3236 nelem); 3237 LogExtents(Extents, nelem); 3238 DMVAR_PASS(); 3239 } else { 3240 DMLOG_PRINT(DMLVL_ERR, 3241 "%s nelem NOT correct! (%d vs %d)\n", 3242 szFuncName, nelem, 3243 1); 3244 DMVAR_FAIL(); 3245 } 3246 } else { 3247 DMLOG_PRINT(DMLVL_ERR, 3248 "dm_get_allocinfo failed with unexpected rc = %d (errno = %d)\n", 3249 rc, errno); 3250 DMVAR_FAIL(); 3251 } 3252 } else { 3253 DMLOG_PRINT(DMLVL_ERR, 3254 "%s failed with unexpected rc = %d (errno = %d)\n", 3255 szFuncName, rc, errno); 3256 DMVAR_FAIL(); 3257 } 3258 3259 /* Variation clean up */ 3260 rc = close(fd); 3261 rc |= remove(DUMMY_FILE); 3262 if (rc == -1) { 3263 DMLOG_PRINT(DMLVL_DEBUG, 3264 "Unable to clean up variation! (errno = %d)\n", 3265 errno); 3266 } 3267 dm_handle_free(hanp, hlen); 3268 } 3269 } 3270 3271 /* 3272 * TEST : dm_punch_hole - truncate part of file, len non-zero 3273 * EXPECTED: rc = 0, nelem = 1 3274 */ 3275 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 13)) { 3276 int fd; 3277 void *hanp; 3278 size_t hlen; 3279 dm_off_t off = BLK_SIZE; 3280 dm_size_t len = TMP_FILELEN - BLK_SIZE; 3281 u_int nelem; 3282 3283 /* Variation set up */ 3284 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3285 if ((rc = system(command)) == -1) { 3286 /* No clean up */ 3287 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3288 remove(DUMMY_FILE); 3289 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3290 close(fd); 3291 remove(DUMMY_FILE); 3292 } 3293 if (fd == -1 || rc == -1) { 3294 DMLOG_PRINT(DMLVL_DEBUG, 3295 "Unable to set up variation! (errno = %d)\n", 3296 errno); 3297 DMVAR_SKIP(); 3298 } else { 3299 /* Variation */ 3300 DMLOG_PRINT(DMLVL_DEBUG, 3301 "%s(truncate part of file, len non-0)\n", 3302 szFuncName); 3303 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3304 len); 3305 DMLOG_PRINT(DMLVL_DEBUG, "%s returned %d\n", szFuncName, 3306 rc); 3307 if (rc == 0) { 3308 off = 0; 3309 rc = dm_get_allocinfo(sid, hanp, hlen, 3310 DM_NO_TOKEN, &off, 3311 NUM_EXTENTS, Extents, 3312 &nelem); 3313 DMLOG_PRINT(DMLVL_DEBUG, 3314 "dm_get_allocinfo returned %d\n", 3315 rc); 3316 if (rc == 0) { 3317 if (nelem == 1) { 3318 DMLOG_PRINT(DMLVL_DEBUG, 3319 " nelem = %d\n", 3320 nelem); 3321 LogExtents(Extents, nelem); 3322 DMVAR_PASS(); 3323 } else { 3324 DMLOG_PRINT(DMLVL_ERR, 3325 "%s nelem NOT correct! (%d vs %d)\n", 3326 szFuncName, nelem, 3327 1); 3328 DMVAR_FAIL(); 3329 } 3330 } else { 3331 DMLOG_PRINT(DMLVL_ERR, 3332 "dm_get_allocinfo failed with unexpected rc = %d (errno = %d)\n", 3333 rc, errno); 3334 DMVAR_FAIL(); 3335 } 3336 } else { 3337 DMLOG_PRINT(DMLVL_ERR, 3338 "%s failed with unexpected rc = %d (errno = %d)\n", 3339 szFuncName, rc, errno); 3340 DMVAR_FAIL(); 3341 } 3342 3343 /* Variation clean up */ 3344 rc = close(fd); 3345 rc |= remove(DUMMY_FILE); 3346 if (rc == -1) { 3347 DMLOG_PRINT(DMLVL_DEBUG, 3348 "Unable to clean up variation! (errno = %d)\n", 3349 errno); 3350 } 3351 dm_handle_free(hanp, hlen); 3352 } 3353 } 3354 3355 /* 3356 * TEST : dm_punch_hole - small hole 3357 * EXPECTED: rc = 0, nelem = 3 3358 */ 3359 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 14)) { 3360 #ifdef INTERIOR_HOLES 3361 int fd; 3362 void *hanp; 3363 size_t hlen; 3364 dm_off_t off = (TMP_FILELEN / 2) & (~(BLK_SIZE - 1)); 3365 dm_size_t len = 2 * BLK_SIZE; 3366 u_int nelem; 3367 char buf[DUMMY_STRLEN]; 3368 3369 /* Variation set up */ 3370 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3371 if ((rc = system(command)) == -1) { 3372 /* No clean up */ 3373 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3374 remove(DUMMY_FILE); 3375 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3376 close(fd); 3377 remove(DUMMY_FILE); 3378 } 3379 if (fd == -1 || rc == -1) { 3380 DMLOG_PRINT(DMLVL_DEBUG, 3381 "Unable to set up variation! (errno = %d)\n", 3382 errno); 3383 DMVAR_SKIP(); 3384 } else { 3385 /* Variation */ 3386 DMLOG_PRINT(DMLVL_DEBUG, "%s(small hole)\n", 3387 szFuncName); 3388 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3389 len); 3390 DMLOG_PRINT(DMLVL_DEBUG, "%s returned %d\n", szFuncName, 3391 rc); 3392 if (rc == 0) { 3393 off = 0; 3394 rc = dm_get_allocinfo(sid, hanp, hlen, 3395 DM_NO_TOKEN, &off, 3396 NUM_EXTENTS, Extents, 3397 &nelem); 3398 DMLOG_PRINT(DMLVL_DEBUG, 3399 "dm_get_allocinfo returned %d\n", 3400 rc); 3401 if (rc == 0) { 3402 if (nelem == 3) { 3403 DMLOG_PRINT(DMLVL_DEBUG, 3404 " nelem = %d\n", 3405 nelem); 3406 LogExtents(Extents, nelem); 3407 if ((lseek 3408 (fd, TMP_FILELEN / 2, 3409 SEEK_SET) == 3410 (TMP_FILELEN / 2)) 3411 && 3412 (read(fd, buf, DUMMY_STRLEN) 3413 == DUMMY_STRLEN)) { 3414 DMLOG_PRINT(DMLVL_DEBUG, 3415 "buffer from hole: [%s]\n", 3416 buf); 3417 } 3418 if ((lseek 3419 (fd, TMP_FILELEN - 10, 3420 SEEK_SET) == 3421 (TMP_FILELEN - 10)) 3422 && 3423 (read(fd, buf, DUMMY_STRLEN) 3424 == DUMMY_STRLEN)) { 3425 DMLOG_PRINT(DMLVL_DEBUG, 3426 "buffer from resident extent: [%s]\n", 3427 buf); 3428 } 3429 DMVAR_PASS(); 3430 } else { 3431 DMLOG_PRINT(DMLVL_ERR, 3432 "%s nelem NOT correct! (%d vs %d)\n", 3433 szFuncName, nelem, 3434 3); 3435 DMVAR_FAIL(); 3436 } 3437 } else { 3438 DMLOG_PRINT(DMLVL_ERR, 3439 "dm_get_allocinfo failed with unexpected rc = %d (errno = %d)\n", 3440 rc, errno); 3441 DMVAR_FAIL(); 3442 } 3443 } else { 3444 DMLOG_PRINT(DMLVL_ERR, 3445 "%s failed with unexpected rc = %d (errno = %d)\n", 3446 szFuncName, rc, errno); 3447 DMVAR_FAIL(); 3448 } 3449 3450 /* Variation clean up */ 3451 rc = close(fd); 3452 rc |= remove(DUMMY_FILE); 3453 if (rc == -1) { 3454 DMLOG_PRINT(DMLVL_DEBUG, 3455 "Unable to clean up variation! (errno = %d)\n", 3456 errno); 3457 } 3458 dm_handle_free(hanp, hlen); 3459 } 3460 #else 3461 DMLOG_PRINT(DMLVL_WARN, 3462 "Test case not built with INTERIOR_HOLES defined\n"); 3463 DMVAR_SKIP(); 3464 #endif 3465 } 3466 3467 /* 3468 * TEST : dm_punch_hole - large hole 3469 * EXPECTED: rc = 0, nelem = 3 3470 */ 3471 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 15)) { 3472 #ifdef INTERIOR_HOLES 3473 int fd; 3474 void *hanp; 3475 size_t hlen; 3476 dm_off_t off = BLK_SIZE; 3477 dm_size_t len = 3478 (TMP_FILELEN - (2 * BLK_SIZE)) & (~(BLK_SIZE - 1)); 3479 u_int nelem; 3480 3481 /* Variation set up */ 3482 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3483 if ((rc = system(command)) == -1) { 3484 /* No clean up */ 3485 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3486 remove(DUMMY_FILE); 3487 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3488 close(fd); 3489 remove(DUMMY_FILE); 3490 } 3491 if (fd == -1 || rc == -1) { 3492 DMLOG_PRINT(DMLVL_DEBUG, 3493 "Unable to set up variation! (errno = %d)\n", 3494 errno); 3495 DMVAR_SKIP(); 3496 } else { 3497 /* Variation */ 3498 DMLOG_PRINT(DMLVL_DEBUG, "%s(large hole)\n", 3499 szFuncName); 3500 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3501 len); 3502 DMLOG_PRINT(DMLVL_DEBUG, "%s returned %d\n", szFuncName, 3503 rc); 3504 if (rc == 0) { 3505 off = 0; 3506 rc = dm_get_allocinfo(sid, hanp, hlen, 3507 DM_NO_TOKEN, &off, 3508 NUM_EXTENTS, Extents, 3509 &nelem); 3510 DMLOG_PRINT(DMLVL_DEBUG, 3511 "dm_get_allocinfo returned %d\n", 3512 rc); 3513 if (rc == 0) { 3514 if (nelem == 3) { 3515 DMLOG_PRINT(DMLVL_DEBUG, 3516 " nelem = %d\n", 3517 nelem); 3518 LogExtents(Extents, nelem); 3519 DMVAR_PASS(); 3520 } else { 3521 DMLOG_PRINT(DMLVL_ERR, 3522 "%s nelem NOT correct! (%d vs %d)\n", 3523 szFuncName, nelem, 3524 3); 3525 DMVAR_FAIL(); 3526 } 3527 } else { 3528 DMLOG_PRINT(DMLVL_ERR, 3529 "dm_get_allocinfo failed with unexpected rc = %d (errno = %d)\n", 3530 rc, errno); 3531 DMVAR_FAIL(); 3532 } 3533 } else { 3534 DMLOG_PRINT(DMLVL_ERR, 3535 "%s failed with unexpected rc = %d (errno = %d)\n", 3536 szFuncName, rc, errno); 3537 DMVAR_FAIL(); 3538 } 3539 3540 /* Variation clean up */ 3541 rc = close(fd); 3542 rc |= remove(DUMMY_FILE); 3543 if (rc == -1) { 3544 DMLOG_PRINT(DMLVL_DEBUG, 3545 "Unable to clean up variation! (errno = %d)\n", 3546 errno); 3547 } 3548 dm_handle_free(hanp, hlen); 3549 } 3550 #else 3551 DMLOG_PRINT(DMLVL_WARN, 3552 "Test case not built with INTERIOR_HOLES defined\n"); 3553 DMVAR_SKIP(); 3554 #endif 3555 } 3556 3557 /* 3558 * TEST : dm_punch_hole - DM_NO_SESSION sid 3559 * EXPECTED: rc = -1, errno = EINVAL 3560 */ 3561 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 16)) { 3562 int fd; 3563 void *hanp; 3564 size_t hlen; 3565 dm_off_t off = 0; 3566 dm_size_t len = 0; 3567 3568 /* Variation set up */ 3569 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3570 if ((rc = system(command)) == -1) { 3571 /* No clean up */ 3572 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3573 remove(DUMMY_FILE); 3574 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3575 close(fd); 3576 remove(DUMMY_FILE); 3577 } 3578 if (fd == -1 || rc == -1) { 3579 DMLOG_PRINT(DMLVL_DEBUG, 3580 "Unable to set up variation! (errno = %d)\n", 3581 errno); 3582 DMVAR_SKIP(); 3583 } else { 3584 /* Variation */ 3585 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", 3586 szFuncName); 3587 rc = dm_punch_hole(DM_NO_SESSION, hanp, hlen, 3588 DM_NO_TOKEN, off, len); 3589 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 3590 3591 /* Variation clean up */ 3592 rc = close(fd); 3593 rc |= remove(DUMMY_FILE); 3594 if (rc == -1) { 3595 DMLOG_PRINT(DMLVL_DEBUG, 3596 "Unable to clean up variation! (errno = %d)\n", 3597 errno); 3598 } 3599 dm_handle_free(hanp, hlen); 3600 } 3601 } 3602 3603 /* 3604 * TEST : dm_punch_hole - fs handle 3605 * EXPECTED: rc = -1, errno = EINVAL 3606 */ 3607 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 17)) { 3608 void *hanp; 3609 size_t hlen; 3610 dm_off_t off = 0; 3611 dm_size_t len = 0; 3612 3613 /* Variation set up */ 3614 if ((rc = mkdir(DUMMY_SUBDIR, DUMMY_DIR_RW_MODE)) == -1) { 3615 /* No clean up */ 3616 } else 3617 if ((rc = 3618 dm_path_to_fshandle(DUMMY_SUBDIR, &hanp, 3619 &hlen)) == -1) { 3620 rmdir(DUMMY_SUBDIR); 3621 } 3622 if (rc == -1) { 3623 DMLOG_PRINT(DMLVL_DEBUG, 3624 "Unable to set up variation! (errno = %d)\n", 3625 errno); 3626 DMVAR_SKIP(); 3627 } else { 3628 /* Variation */ 3629 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); 3630 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3631 len); 3632 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 3633 3634 /* Variation clean up */ 3635 rc = rmdir(DUMMY_SUBDIR); 3636 if (rc == -1) { 3637 DMLOG_PRINT(DMLVL_DEBUG, 3638 "Unable to clean up variation! (errno = %d)\n", 3639 errno); 3640 } 3641 dm_handle_free(hanp, hlen); 3642 } 3643 } 3644 3645 /* 3646 * TEST : dm_punch_hole - global handle 3647 * EXPECTED: rc = -1, errno = EBADF 3648 */ 3649 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 18)) { 3650 dm_off_t off = 0; 3651 dm_size_t len = 0; 3652 3653 /* Variation set up */ 3654 3655 /* Variation */ 3656 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); 3657 rc = dm_punch_hole(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, 3658 DM_NO_TOKEN, off, len); 3659 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 3660 3661 /* Variation clean up */ 3662 } 3663 3664 /* 3665 * TEST : dm_punch_hole - invalidated hanp 3666 * EXPECTED: rc = -1, errno = EBADF 3667 */ 3668 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 19)) { 3669 int fd; 3670 void *hanp; 3671 size_t hlen; 3672 dm_off_t off = 0; 3673 dm_size_t len = 0; 3674 3675 /* Variation set up */ 3676 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3677 if ((rc = system(command)) == -1) { 3678 /* No clean up */ 3679 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3680 remove(DUMMY_FILE); 3681 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3682 close(fd); 3683 remove(DUMMY_FILE); 3684 } else if ((rc = close(fd)) == -1) { 3685 dm_handle_free(hanp, hlen); 3686 remove(DUMMY_FILE); 3687 } else if ((rc = remove(DUMMY_FILE)) == -1) { 3688 dm_handle_free(hanp, hlen); 3689 } 3690 if (fd == -1 || rc == -1) { 3691 DMLOG_PRINT(DMLVL_DEBUG, 3692 "Unable to set up variation! (errno = %d)\n", 3693 errno); 3694 DMVAR_SKIP(); 3695 } else { 3696 /* Variation */ 3697 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalidated hanp)\n", 3698 szFuncName); 3699 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3700 len); 3701 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 3702 3703 /* Variation clean up */ 3704 dm_handle_free(hanp, hlen); 3705 } 3706 } 3707 3708 /* 3709 * TEST : dm_punch_hole - private read mmap overlapping hole 3710 * EXPECTED: rc = -1, errno = EBUSY 3711 */ 3712 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 20)) { 3713 int fd; 3714 void *hanp; 3715 size_t hlen; 3716 dm_off_t off = 0; 3717 dm_size_t len = 0; 3718 void *memmap; 3719 3720 /* Variation set up */ 3721 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3722 if ((rc = system(command)) == -1) { 3723 /* No clean up */ 3724 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3725 remove(DUMMY_FILE); 3726 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3727 close(fd); 3728 remove(DUMMY_FILE); 3729 } else 3730 if ((memmap = 3731 mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, fd, 3732 0)) == MAP_FAILED) { 3733 dm_handle_free(hanp, hlen); 3734 close(fd); 3735 remove(DUMMY_FILE); 3736 } 3737 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 3738 DMLOG_PRINT(DMLVL_DEBUG, 3739 "Unable to set up variation! (errno = %d)\n", 3740 errno); 3741 DMVAR_SKIP(); 3742 } else { 3743 /* Variation */ 3744 DMLOG_PRINT(DMLVL_DEBUG, 3745 "%s(private read mmap overlap hole)\n", 3746 szFuncName); 3747 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3748 len); 3749 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 3750 3751 /* Variation clean up */ 3752 munmap(memmap, PAGE_SIZE); 3753 rc = close(fd); 3754 rc |= remove(DUMMY_FILE); 3755 if (rc == -1) { 3756 DMLOG_PRINT(DMLVL_DEBUG, 3757 "Unable to clean up variation! (errno = %d)\n", 3758 errno); 3759 } 3760 dm_handle_free(hanp, hlen); 3761 } 3762 } 3763 3764 /* 3765 * TEST : dm_punch_hole - private write mmap overlapping hole 3766 * EXPECTED: rc = -1, errno = EBUSY 3767 */ 3768 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 21)) { 3769 int fd; 3770 void *hanp; 3771 size_t hlen; 3772 dm_off_t off = 0; 3773 dm_size_t len = 0; 3774 void *memmap; 3775 3776 /* Variation set up */ 3777 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3778 if ((rc = system(command)) == -1) { 3779 /* No clean up */ 3780 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3781 remove(DUMMY_FILE); 3782 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3783 close(fd); 3784 remove(DUMMY_FILE); 3785 } else 3786 if ((memmap = 3787 mmap(NULL, PAGE_SIZE, PROT_WRITE, MAP_PRIVATE, fd, 3788 0)) == MAP_FAILED) { 3789 dm_handle_free(hanp, hlen); 3790 close(fd); 3791 remove(DUMMY_FILE); 3792 } 3793 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 3794 DMLOG_PRINT(DMLVL_DEBUG, 3795 "Unable to set up variation! (errno = %d)\n", 3796 errno); 3797 DMVAR_SKIP(); 3798 } else { 3799 /* Variation */ 3800 DMLOG_PRINT(DMLVL_DEBUG, 3801 "%s(private write mmap overlap hole)\n", 3802 szFuncName); 3803 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3804 len); 3805 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 3806 3807 /* Variation clean up */ 3808 munmap(memmap, PAGE_SIZE); 3809 rc = close(fd); 3810 rc |= remove(DUMMY_FILE); 3811 if (rc == -1) { 3812 DMLOG_PRINT(DMLVL_DEBUG, 3813 "Unable to clean up variation! (errno = %d)\n", 3814 errno); 3815 } 3816 dm_handle_free(hanp, hlen); 3817 } 3818 } 3819 3820 /* 3821 * TEST : dm_punch_hole - private exec mmap overlapping hole 3822 * EXPECTED: rc = -1, errno = EBUSY 3823 */ 3824 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 22)) { 3825 int fd; 3826 void *hanp; 3827 size_t hlen; 3828 dm_off_t off = 0; 3829 dm_size_t len = 0; 3830 void *memmap; 3831 3832 /* Variation set up */ 3833 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3834 if ((rc = system(command)) == -1) { 3835 /* No clean up */ 3836 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3837 remove(DUMMY_FILE); 3838 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3839 close(fd); 3840 remove(DUMMY_FILE); 3841 } else 3842 if ((memmap = 3843 mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_PRIVATE, fd, 3844 0)) == MAP_FAILED) { 3845 dm_handle_free(hanp, hlen); 3846 close(fd); 3847 remove(DUMMY_FILE); 3848 } 3849 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 3850 DMLOG_PRINT(DMLVL_DEBUG, 3851 "Unable to set up variation! (errno = %d)\n", 3852 errno); 3853 DMVAR_SKIP(); 3854 } else { 3855 /* Variation */ 3856 DMLOG_PRINT(DMLVL_DEBUG, 3857 "%s(private exec mmap overlap hole)\n", 3858 szFuncName); 3859 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3860 len); 3861 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 3862 3863 /* Variation clean up */ 3864 munmap(memmap, PAGE_SIZE); 3865 rc = close(fd); 3866 rc |= remove(DUMMY_FILE); 3867 if (rc == -1) { 3868 DMLOG_PRINT(DMLVL_DEBUG, 3869 "Unable to clean up variation! (errno = %d)\n", 3870 errno); 3871 } 3872 dm_handle_free(hanp, hlen); 3873 } 3874 } 3875 3876 /* 3877 * TEST : dm_punch_hole - private r/w mmap overlapping hole 3878 * EXPECTED: rc = -1, errno = EBUSY 3879 */ 3880 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 23)) { 3881 int fd; 3882 void *hanp; 3883 size_t hlen; 3884 dm_off_t off = 0; 3885 dm_size_t len = 0; 3886 void *memmap; 3887 3888 /* Variation set up */ 3889 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3890 if ((rc = system(command)) == -1) { 3891 /* No clean up */ 3892 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3893 remove(DUMMY_FILE); 3894 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3895 close(fd); 3896 remove(DUMMY_FILE); 3897 } else 3898 if ((memmap = 3899 mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, 3900 MAP_PRIVATE, fd, 0)) == MAP_FAILED) { 3901 dm_handle_free(hanp, hlen); 3902 close(fd); 3903 remove(DUMMY_FILE); 3904 } 3905 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 3906 DMLOG_PRINT(DMLVL_DEBUG, 3907 "Unable to set up variation! (errno = %d)\n", 3908 errno); 3909 DMVAR_SKIP(); 3910 } else { 3911 /* Variation */ 3912 DMLOG_PRINT(DMLVL_DEBUG, 3913 "%s(private r/w mmap overlap hole)\n", 3914 szFuncName); 3915 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3916 len); 3917 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 3918 3919 /* Variation clean up */ 3920 munmap(memmap, PAGE_SIZE); 3921 rc = close(fd); 3922 rc |= remove(DUMMY_FILE); 3923 if (rc == -1) { 3924 DMLOG_PRINT(DMLVL_DEBUG, 3925 "Unable to clean up variation! (errno = %d)\n", 3926 errno); 3927 } 3928 dm_handle_free(hanp, hlen); 3929 } 3930 } 3931 3932 /* 3933 * TEST : dm_punch_hole - shared read mmap overlapping hole 3934 * EXPECTED: rc = -1, errno = EBUSY 3935 */ 3936 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 24)) { 3937 int fd; 3938 void *hanp; 3939 size_t hlen; 3940 dm_off_t off = 0; 3941 dm_size_t len = 0; 3942 void *memmap; 3943 3944 /* Variation set up */ 3945 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 3946 if ((rc = system(command)) == -1) { 3947 /* No clean up */ 3948 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 3949 remove(DUMMY_FILE); 3950 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 3951 close(fd); 3952 remove(DUMMY_FILE); 3953 } else 3954 if ((memmap = 3955 mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 3956 0)) == MAP_FAILED) { 3957 dm_handle_free(hanp, hlen); 3958 close(fd); 3959 remove(DUMMY_FILE); 3960 } 3961 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 3962 DMLOG_PRINT(DMLVL_DEBUG, 3963 "Unable to set up variation! (errno = %d)\n", 3964 errno); 3965 DMVAR_SKIP(); 3966 } else { 3967 /* Variation */ 3968 DMLOG_PRINT(DMLVL_DEBUG, 3969 "%s(shared read mmap overlap hole)\n", 3970 szFuncName); 3971 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 3972 len); 3973 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 3974 3975 /* Variation clean up */ 3976 munmap(memmap, PAGE_SIZE); 3977 rc = close(fd); 3978 rc |= remove(DUMMY_FILE); 3979 if (rc == -1) { 3980 DMLOG_PRINT(DMLVL_DEBUG, 3981 "Unable to clean up variation! (errno = %d)\n", 3982 errno); 3983 } 3984 dm_handle_free(hanp, hlen); 3985 } 3986 } 3987 3988 /* 3989 * TEST : dm_punch_hole - shared write mmap overlapping hole 3990 * EXPECTED: rc = -1, errno = EBUSY 3991 */ 3992 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 25)) { 3993 int fd; 3994 void *hanp; 3995 size_t hlen; 3996 dm_off_t off = 0; 3997 dm_size_t len = 0; 3998 void *memmap; 3999 4000 /* Variation set up */ 4001 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4002 if ((rc = system(command)) == -1) { 4003 /* No clean up */ 4004 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4005 remove(DUMMY_FILE); 4006 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4007 close(fd); 4008 remove(DUMMY_FILE); 4009 } else 4010 if ((memmap = 4011 mmap(NULL, PAGE_SIZE, PROT_WRITE, MAP_SHARED, fd, 4012 0)) == MAP_FAILED) { 4013 dm_handle_free(hanp, hlen); 4014 close(fd); 4015 remove(DUMMY_FILE); 4016 } 4017 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4018 DMLOG_PRINT(DMLVL_DEBUG, 4019 "Unable to set up variation! (errno = %d)\n", 4020 errno); 4021 DMVAR_SKIP(); 4022 } else { 4023 /* Variation */ 4024 DMLOG_PRINT(DMLVL_DEBUG, 4025 "%s(shared write mmap overlap hole)\n", 4026 szFuncName); 4027 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4028 len); 4029 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 4030 4031 /* Variation clean up */ 4032 munmap(memmap, PAGE_SIZE); 4033 rc = close(fd); 4034 rc |= remove(DUMMY_FILE); 4035 if (rc == -1) { 4036 DMLOG_PRINT(DMLVL_DEBUG, 4037 "Unable to clean up variation! (errno = %d)\n", 4038 errno); 4039 } 4040 dm_handle_free(hanp, hlen); 4041 } 4042 } 4043 4044 /* 4045 * TEST : dm_punch_hole - shared exec mmap overlapping hole 4046 * EXPECTED: rc = -1, errno = EBUSY 4047 */ 4048 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 26)) { 4049 int fd; 4050 void *hanp; 4051 size_t hlen; 4052 dm_off_t off = 0; 4053 dm_size_t len = 0; 4054 void *memmap; 4055 4056 /* Variation set up */ 4057 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4058 if ((rc = system(command)) == -1) { 4059 /* No clean up */ 4060 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4061 remove(DUMMY_FILE); 4062 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4063 close(fd); 4064 remove(DUMMY_FILE); 4065 } else 4066 if ((memmap = 4067 mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_SHARED, fd, 4068 0)) == MAP_FAILED) { 4069 dm_handle_free(hanp, hlen); 4070 close(fd); 4071 remove(DUMMY_FILE); 4072 } 4073 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4074 DMLOG_PRINT(DMLVL_DEBUG, 4075 "Unable to set up variation! (errno = %d)\n", 4076 errno); 4077 DMVAR_SKIP(); 4078 } else { 4079 /* Variation */ 4080 DMLOG_PRINT(DMLVL_DEBUG, 4081 "%s(shared exec mmap overlap hole)\n", 4082 szFuncName); 4083 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4084 len); 4085 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 4086 4087 /* Variation clean up */ 4088 munmap(memmap, PAGE_SIZE); 4089 rc = close(fd); 4090 rc |= remove(DUMMY_FILE); 4091 if (rc == -1) { 4092 DMLOG_PRINT(DMLVL_DEBUG, 4093 "Unable to clean up variation! (errno = %d)\n", 4094 errno); 4095 } 4096 dm_handle_free(hanp, hlen); 4097 } 4098 } 4099 4100 /* 4101 * TEST : dm_punch_hole - shared r/w mmap overlapping hole 4102 * EXPECTED: rc = -1, errno = EBUSY 4103 */ 4104 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 27)) { 4105 int fd; 4106 void *hanp; 4107 size_t hlen; 4108 dm_off_t off = 0; 4109 dm_size_t len = 0; 4110 void *memmap; 4111 4112 /* Variation set up */ 4113 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4114 if ((rc = system(command)) == -1) { 4115 /* No clean up */ 4116 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4117 remove(DUMMY_FILE); 4118 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4119 close(fd); 4120 remove(DUMMY_FILE); 4121 } else 4122 if ((memmap = 4123 mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, 4124 MAP_SHARED, fd, 0)) == MAP_FAILED) { 4125 dm_handle_free(hanp, hlen); 4126 close(fd); 4127 remove(DUMMY_FILE); 4128 } 4129 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4130 DMLOG_PRINT(DMLVL_DEBUG, 4131 "Unable to set up variation! (errno = %d)\n", 4132 errno); 4133 DMVAR_SKIP(); 4134 } else { 4135 /* Variation */ 4136 DMLOG_PRINT(DMLVL_DEBUG, 4137 "%s(shared r/w mmap overlap hole)\n", 4138 szFuncName); 4139 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4140 len); 4141 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 4142 4143 /* Variation clean up */ 4144 munmap(memmap, PAGE_SIZE); 4145 rc = close(fd); 4146 rc |= remove(DUMMY_FILE); 4147 if (rc == -1) { 4148 DMLOG_PRINT(DMLVL_DEBUG, 4149 "Unable to clean up variation! (errno = %d)\n", 4150 errno); 4151 } 4152 dm_handle_free(hanp, hlen); 4153 } 4154 } 4155 4156 /* 4157 * TEST : dm_punch_hole - private read mmap not overlapping hole 4158 * EXPECTED: rc = 0 4159 */ 4160 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 28)) { 4161 int fd; 4162 void *hanp; 4163 size_t hlen; 4164 dm_off_t off = BLKALIGN(TMP_FILELEN / 2); 4165 dm_size_t len = 0; 4166 void *memmap; 4167 4168 /* Variation set up */ 4169 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4170 if ((rc = system(command)) == -1) { 4171 /* No clean up */ 4172 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4173 remove(DUMMY_FILE); 4174 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4175 close(fd); 4176 remove(DUMMY_FILE); 4177 } else 4178 if ((memmap = 4179 mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, fd, 4180 0)) == MAP_FAILED) { 4181 dm_handle_free(hanp, hlen); 4182 close(fd); 4183 remove(DUMMY_FILE); 4184 } 4185 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4186 DMLOG_PRINT(DMLVL_DEBUG, 4187 "Unable to set up variation! (errno = %d)\n", 4188 errno); 4189 DMVAR_SKIP(); 4190 } else { 4191 /* Variation */ 4192 DMLOG_PRINT(DMLVL_DEBUG, 4193 "%s(private read mmap not overlap hole)\n", 4194 szFuncName); 4195 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4196 len); 4197 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 4198 4199 /* Variation clean up */ 4200 munmap(memmap, PAGE_SIZE); 4201 rc = close(fd); 4202 rc |= remove(DUMMY_FILE); 4203 if (rc == -1) { 4204 DMLOG_PRINT(DMLVL_DEBUG, 4205 "Unable to clean up variation! (errno = %d)\n", 4206 errno); 4207 } 4208 dm_handle_free(hanp, hlen); 4209 } 4210 } 4211 4212 /* 4213 * TEST : dm_punch_hole - private write mmap not overlapping hole 4214 * EXPECTED: rc = 0 4215 */ 4216 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 29)) { 4217 int fd; 4218 void *hanp; 4219 size_t hlen; 4220 dm_off_t off = BLKALIGN(TMP_FILELEN / 2); 4221 dm_size_t len = 0; 4222 void *memmap; 4223 4224 /* Variation set up */ 4225 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4226 if ((rc = system(command)) == -1) { 4227 /* No clean up */ 4228 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4229 remove(DUMMY_FILE); 4230 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4231 close(fd); 4232 remove(DUMMY_FILE); 4233 } else 4234 if ((memmap = 4235 mmap(NULL, PAGE_SIZE, PROT_WRITE, MAP_PRIVATE, fd, 4236 0)) == MAP_FAILED) { 4237 dm_handle_free(hanp, hlen); 4238 close(fd); 4239 remove(DUMMY_FILE); 4240 } 4241 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4242 DMLOG_PRINT(DMLVL_DEBUG, 4243 "Unable to set up variation! (errno = %d)\n", 4244 errno); 4245 DMVAR_SKIP(); 4246 } else { 4247 /* Variation */ 4248 DMLOG_PRINT(DMLVL_DEBUG, 4249 "%s(private write mmap not overlap hole)\n", 4250 szFuncName); 4251 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4252 len); 4253 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 4254 4255 /* Variation clean up */ 4256 munmap(memmap, PAGE_SIZE); 4257 rc = close(fd); 4258 rc |= remove(DUMMY_FILE); 4259 if (rc == -1) { 4260 DMLOG_PRINT(DMLVL_DEBUG, 4261 "Unable to clean up variation! (errno = %d)\n", 4262 errno); 4263 } 4264 dm_handle_free(hanp, hlen); 4265 } 4266 } 4267 4268 /* 4269 * TEST : dm_punch_hole - private exec mmap not overlapping hole 4270 * EXPECTED: rc = -1, errno = EBUSY 4271 */ 4272 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 30)) { 4273 int fd; 4274 void *hanp; 4275 size_t hlen; 4276 dm_off_t off = BLKALIGN(TMP_FILELEN / 2); 4277 dm_size_t len = 0; 4278 void *memmap; 4279 4280 /* Variation set up */ 4281 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4282 if ((rc = system(command)) == -1) { 4283 /* No clean up */ 4284 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4285 remove(DUMMY_FILE); 4286 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4287 close(fd); 4288 remove(DUMMY_FILE); 4289 } else 4290 if ((memmap = 4291 mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_PRIVATE, fd, 4292 0)) == MAP_FAILED) { 4293 dm_handle_free(hanp, hlen); 4294 close(fd); 4295 remove(DUMMY_FILE); 4296 } 4297 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4298 DMLOG_PRINT(DMLVL_DEBUG, 4299 "Unable to set up variation! (errno = %d)\n", 4300 errno); 4301 DMVAR_SKIP(); 4302 } else { 4303 /* Variation */ 4304 DMLOG_PRINT(DMLVL_DEBUG, 4305 "%s(private exec mmap not overlap hole)\n", 4306 szFuncName); 4307 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4308 len); 4309 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 4310 4311 /* Variation clean up */ 4312 munmap(memmap, PAGE_SIZE); 4313 rc = close(fd); 4314 rc |= remove(DUMMY_FILE); 4315 if (rc == -1) { 4316 DMLOG_PRINT(DMLVL_DEBUG, 4317 "Unable to clean up variation! (errno = %d)\n", 4318 errno); 4319 } 4320 dm_handle_free(hanp, hlen); 4321 } 4322 } 4323 4324 /* 4325 * TEST : dm_punch_hole - private r/w mmap not overlapping hole 4326 * EXPECTED: rc = 0 4327 */ 4328 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 31)) { 4329 int fd; 4330 void *hanp; 4331 size_t hlen; 4332 dm_off_t off = BLKALIGN(TMP_FILELEN / 2); 4333 dm_size_t len = 0; 4334 void *memmap; 4335 4336 /* Variation set up */ 4337 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4338 if ((rc = system(command)) == -1) { 4339 /* No clean up */ 4340 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4341 remove(DUMMY_FILE); 4342 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4343 close(fd); 4344 remove(DUMMY_FILE); 4345 } else 4346 if ((memmap = 4347 mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, 4348 MAP_PRIVATE, fd, 0)) == MAP_FAILED) { 4349 dm_handle_free(hanp, hlen); 4350 close(fd); 4351 remove(DUMMY_FILE); 4352 } 4353 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4354 DMLOG_PRINT(DMLVL_DEBUG, 4355 "Unable to set up variation! (errno = %d)\n", 4356 errno); 4357 DMVAR_SKIP(); 4358 } else { 4359 /* Variation */ 4360 DMLOG_PRINT(DMLVL_DEBUG, 4361 "%s(private r/w mmap not overlap hole)\n", 4362 szFuncName); 4363 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4364 len); 4365 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 4366 4367 /* Variation clean up */ 4368 munmap(memmap, PAGE_SIZE); 4369 rc = close(fd); 4370 rc |= remove(DUMMY_FILE); 4371 if (rc == -1) { 4372 DMLOG_PRINT(DMLVL_DEBUG, 4373 "Unable to clean up variation! (errno = %d)\n", 4374 errno); 4375 } 4376 dm_handle_free(hanp, hlen); 4377 } 4378 } 4379 4380 /* 4381 * TEST : dm_punch_hole - shared read mmap not overlapping hole 4382 * EXPECTED: rc = 0 4383 */ 4384 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 32)) { 4385 int fd; 4386 void *hanp; 4387 size_t hlen; 4388 dm_off_t off = BLKALIGN(TMP_FILELEN / 2); 4389 dm_size_t len = 0; 4390 void *memmap; 4391 4392 /* Variation set up */ 4393 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4394 if ((rc = system(command)) == -1) { 4395 /* No clean up */ 4396 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4397 remove(DUMMY_FILE); 4398 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4399 close(fd); 4400 remove(DUMMY_FILE); 4401 } else 4402 if ((memmap = 4403 mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 4404 0)) == MAP_FAILED) { 4405 dm_handle_free(hanp, hlen); 4406 close(fd); 4407 remove(DUMMY_FILE); 4408 } 4409 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4410 DMLOG_PRINT(DMLVL_DEBUG, 4411 "Unable to set up variation! (errno = %d)\n", 4412 errno); 4413 DMVAR_SKIP(); 4414 } else { 4415 /* Variation */ 4416 DMLOG_PRINT(DMLVL_DEBUG, 4417 "%s(shared read mmap not overlap hole)\n", 4418 szFuncName); 4419 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4420 len); 4421 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 4422 4423 /* Variation clean up */ 4424 munmap(memmap, PAGE_SIZE); 4425 rc = close(fd); 4426 rc |= remove(DUMMY_FILE); 4427 if (rc == -1) { 4428 DMLOG_PRINT(DMLVL_DEBUG, 4429 "Unable to clean up variation! (errno = %d)\n", 4430 errno); 4431 } 4432 dm_handle_free(hanp, hlen); 4433 } 4434 } 4435 4436 /* 4437 * TEST : dm_punch_hole - shared write mmap not overlapping hole 4438 * EXPECTED: rc = 0 4439 */ 4440 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 33)) { 4441 int fd; 4442 void *hanp; 4443 size_t hlen; 4444 dm_off_t off = BLKALIGN(TMP_FILELEN / 2); 4445 dm_size_t len = 0; 4446 void *memmap; 4447 4448 /* Variation set up */ 4449 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4450 if ((rc = system(command)) == -1) { 4451 /* No clean up */ 4452 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4453 remove(DUMMY_FILE); 4454 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4455 close(fd); 4456 remove(DUMMY_FILE); 4457 } else 4458 if ((memmap = 4459 mmap(NULL, PAGE_SIZE, PROT_WRITE, MAP_SHARED, fd, 4460 0)) == MAP_FAILED) { 4461 dm_handle_free(hanp, hlen); 4462 close(fd); 4463 remove(DUMMY_FILE); 4464 } 4465 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4466 DMLOG_PRINT(DMLVL_DEBUG, 4467 "Unable to set up variation! (errno = %d)\n", 4468 errno); 4469 DMVAR_SKIP(); 4470 } else { 4471 /* Variation */ 4472 DMLOG_PRINT(DMLVL_DEBUG, 4473 "%s(shared write mmap not overlap hole)\n", 4474 szFuncName); 4475 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4476 len); 4477 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 4478 4479 /* Variation clean up */ 4480 munmap(memmap, PAGE_SIZE); 4481 rc = close(fd); 4482 rc |= remove(DUMMY_FILE); 4483 if (rc == -1) { 4484 DMLOG_PRINT(DMLVL_DEBUG, 4485 "Unable to clean up variation! (errno = %d)\n", 4486 errno); 4487 } 4488 dm_handle_free(hanp, hlen); 4489 } 4490 } 4491 4492 /* 4493 * TEST : dm_punch_hole - shared exec mmap not overlapping hole 4494 * EXPECTED: rc = -1, errno = EBUSY 4495 */ 4496 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 34)) { 4497 int fd; 4498 void *hanp; 4499 size_t hlen; 4500 dm_off_t off = BLKALIGN(TMP_FILELEN / 2); 4501 dm_size_t len = 0; 4502 void *memmap; 4503 4504 /* Variation set up */ 4505 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4506 if ((rc = system(command)) == -1) { 4507 /* No clean up */ 4508 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4509 remove(DUMMY_FILE); 4510 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4511 close(fd); 4512 remove(DUMMY_FILE); 4513 } else 4514 if ((memmap = 4515 mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_SHARED, fd, 4516 0)) == MAP_FAILED) { 4517 dm_handle_free(hanp, hlen); 4518 close(fd); 4519 remove(DUMMY_FILE); 4520 } 4521 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4522 DMLOG_PRINT(DMLVL_DEBUG, 4523 "Unable to set up variation! (errno = %d)\n", 4524 errno); 4525 DMVAR_SKIP(); 4526 } else { 4527 /* Variation */ 4528 DMLOG_PRINT(DMLVL_DEBUG, 4529 "%s(shared exec mmap not overlap hole)\n", 4530 szFuncName); 4531 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4532 len); 4533 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBUSY); 4534 4535 /* Variation clean up */ 4536 munmap(memmap, PAGE_SIZE); 4537 rc = close(fd); 4538 rc |= remove(DUMMY_FILE); 4539 if (rc == -1) { 4540 DMLOG_PRINT(DMLVL_DEBUG, 4541 "Unable to clean up variation! (errno = %d)\n", 4542 errno); 4543 } 4544 dm_handle_free(hanp, hlen); 4545 } 4546 } 4547 4548 /* 4549 * TEST : dm_punch_hole - shared r/w mmap not overlapping hole 4550 * EXPECTED: rc = 0 4551 */ 4552 if (DMVAR_EXEC(PUNCH_HOLE_BASE + 35)) { 4553 int fd; 4554 void *hanp; 4555 size_t hlen; 4556 dm_off_t off = BLKALIGN(TMP_FILELEN / 2); 4557 dm_size_t len = 0; 4558 void *memmap; 4559 4560 /* Variation set up */ 4561 sprintf(command, "cp %s %s", DUMMY_TMP, DUMMY_FILE); 4562 if ((rc = system(command)) == -1) { 4563 /* No clean up */ 4564 } else if ((fd = open(DUMMY_FILE, O_RDWR)) == -1) { 4565 remove(DUMMY_FILE); 4566 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { 4567 close(fd); 4568 remove(DUMMY_FILE); 4569 } else 4570 if ((memmap = 4571 mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, 4572 MAP_SHARED, fd, 0)) == MAP_FAILED) { 4573 dm_handle_free(hanp, hlen); 4574 close(fd); 4575 remove(DUMMY_FILE); 4576 } 4577 if (fd == -1 || rc == -1 || memmap == MAP_FAILED) { 4578 DMLOG_PRINT(DMLVL_DEBUG, 4579 "Unable to set up variation! (errno = %d)\n", 4580 errno); 4581 DMVAR_SKIP(); 4582 } else { 4583 /* Variation */ 4584 DMLOG_PRINT(DMLVL_DEBUG, 4585 "%s(shared r/w mmap not overlap hole)\n", 4586 szFuncName); 4587 rc = dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, off, 4588 len); 4589 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 4590 4591 /* Variation clean up */ 4592 munmap(memmap, PAGE_SIZE); 4593 rc = close(fd); 4594 rc |= remove(DUMMY_FILE); 4595 if (rc == -1) { 4596 DMLOG_PRINT(DMLVL_DEBUG, 4597 "Unable to clean up variation! (errno = %d)\n", 4598 errno); 4599 } 4600 dm_handle_free(hanp, hlen); 4601 } 4602 } 4603 4604 rc = dm_destroy_session(sid); 4605 if (rc == -1) { 4606 DMLOG_PRINT(DMLVL_ERR, 4607 "dm_destroy_session failed! (rc = %d, errno = %d)\n", 4608 rc, errno); 4609 } 4610 4611 remove(DUMMY_TMP); 4612 4613 DMLOG_STOP(); 4614 4615 tst_exit(); 4616 } 4617