| | 328 | /** |
|---|
| | 329 | * Frees the memory for all of the structures on the linked list of |
|---|
| | 330 | * all of the non-NFS mounted file systems. |
|---|
| | 331 | */ |
|---|
| | 332 | static void free_mounted_fs_list (void) { |
|---|
| | 333 | MOUNTED_FS_STRUCT *DSFptr = NULL; |
|---|
| | 334 | MOUNTED_FS_STRUCT *DSFnext = NULL; |
|---|
| | 335 | |
|---|
| | 336 | DSFptr = DSF_Head; |
|---|
| | 337 | while (DSFptr != NULL) { |
|---|
| | 338 | DSFnext = DSFptr->next; |
|---|
| | 339 | paranoid_free(DSFptr); |
|---|
| | 340 | DSFptr = DSFnext; |
|---|
| | 341 | } |
|---|
| | 342 | DSF_Head = NULL; |
|---|
| | 343 | DSF_Tail = NULL; |
|---|
| | 344 | } |
|---|
| | 345 | |
|---|
| | 346 | /** |
|---|
| | 347 | * Creates a singly linked list of all of the non-NFS mounted file systems. |
|---|
| | 348 | * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold |
|---|
| | 349 | * the list of mounted file systems. |
|---|
| | 350 | * @return None. |
|---|
| | 351 | */ |
|---|
| | 352 | static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr) |
|---|
| | 353 | { |
|---|
| | 354 | assert (DSFptr); |
|---|
| | 355 | if (DSF_Head == NULL) { |
|---|
| | 356 | DSF_Head = DSFptr; |
|---|
| | 357 | } else { |
|---|
| | 358 | DSF_Tail->next = DSFptr; |
|---|
| | 359 | } |
|---|
| | 360 | DSFptr->next = NULL; |
|---|
| | 361 | DSF_Tail = DSFptr; |
|---|
| | 362 | } |
|---|
| | 363 | |
|---|
| | 364 | /** |
|---|
| | 365 | * Find the structure, in the singly linked list of all of the non-NFS |
|---|
| | 366 | * mounted file systems, that contains the specified device. |
|---|
| | 367 | * @param device The device to find |
|---|
| | 368 | * @return NULL if it didn't find the device, a pointer to the |
|---|
| | 369 | * structure if it did. |
|---|
| | 370 | */ |
|---|
| | 371 | static MOUNTED_FS_STRUCT *find_device_in_list (char *device) |
|---|
| | 372 | { |
|---|
| | 373 | MOUNTED_FS_STRUCT *DSFptr = NULL; |
|---|
| | 374 | |
|---|
| | 375 | DSFptr = DSF_Head; |
|---|
| | 376 | while (DSFptr != NULL) { |
|---|
| | 377 | if (!strcmp(DSFptr->device, device)) { |
|---|
| | 378 | break; |
|---|
| | 379 | } |
|---|
| | 380 | DSFptr = DSFptr->next; |
|---|
| | 381 | } |
|---|
| | 382 | return (DSFptr); |
|---|
| | 383 | } |
|---|
| | 384 | |
|---|
| | 385 | /** |
|---|
| | 386 | * Find the structure, in the singly linked list of all of the non-NFS |
|---|
| | 387 | * mounted file systems, that contains the specified mount point. |
|---|
| | 388 | * @param mount_point The mount point to find |
|---|
| | 389 | * @return NULL is it didn't find the mount point, a pointer to the |
|---|
| | 390 | * structure if it did. |
|---|
| | 391 | */ |
|---|
| | 392 | static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point) |
|---|
| | 393 | { |
|---|
| | 394 | MOUNTED_FS_STRUCT *DSFptr = NULL; |
|---|
| | 395 | |
|---|
| | 396 | DSFptr = DSF_Head; |
|---|
| | 397 | while (DSFptr != NULL) { |
|---|
| | 398 | if (!strcmp(DSFptr->mount_point, mount_point)) { |
|---|
| | 399 | break; |
|---|
| | 400 | } |
|---|
| | 401 | DSFptr = DSFptr->next; |
|---|
| | 402 | } |
|---|
| | 403 | return (DSFptr); |
|---|
| | 404 | } |
|---|
| | 405 | |
|---|
| | 406 | /** |
|---|
| | 407 | * Creates a linked list of all of the non-NFS mounted file systems. |
|---|
| | 408 | * We use a linked list because we don't know how many mounted file |
|---|
| | 409 | * there are (and there can be a lot). |
|---|
| | 410 | * @return 0 on success and greated than 0 on failure. |
|---|
| | 411 | */ |
|---|
| | 412 | static int create_list_of_non_NFS_mounted_file_systems (void) |
|---|
| | 413 | { |
|---|
| | 414 | int i = 0; |
|---|
| | 415 | int mount_cnt = 0; |
|---|
| | 416 | char *mounted_file_system = NULL; |
|---|
| | 417 | char *command = NULL; |
|---|
| | 418 | char *token = NULL; |
|---|
| | 419 | char token_chars[] =" :\t\r\f\a\0"; |
|---|
| | 420 | MOUNTED_FS_STRUCT *DSFptr = NULL; |
|---|
| | 421 | |
|---|
| | 422 | free_mounted_fs_list(); |
|---|
| | 423 | /******** |
|---|
| | 424 | * Find the number of mounted file system entries and their respective mount points. |
|---|
| | 425 | * I can't return all of the entries as one string because it's length can be longer |
|---|
| | 426 | * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output(). |
|---|
| | 427 | * So start looping and get the number of mounted file systems and query them one by one. |
|---|
| | 428 | ********/ |
|---|
| | 429 | /* Get the number of mounted file systems ((those that start with "/dev/" */ |
|---|
| | 430 | asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l"); |
|---|
| | 431 | log_msg(5, "Running: %s", command); |
|---|
| | 432 | asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); |
|---|
| | 433 | paranoid_free(command); |
|---|
| | 434 | |
|---|
| | 435 | mount_cnt = atoi(mounted_file_system); |
|---|
| | 436 | log_msg (5, "mount_cnt: %d", mount_cnt); |
|---|
| | 437 | paranoid_free(mounted_file_system); |
|---|
| | 438 | |
|---|
| | 439 | for (i=mount_cnt; i > 0; i--) { |
|---|
| | 440 | asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i); |
|---|
| | 441 | log_msg(5, "Running: %s", command); |
|---|
| | 442 | asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); |
|---|
| | 443 | paranoid_free(command); |
|---|
| | 444 | |
|---|
| | 445 | log_msg (5, "mounted_file_system: %s", mounted_file_system); |
|---|
| | 446 | if ((token = strtok(mounted_file_system, token_chars)) == NULL) { |
|---|
| | 447 | log_msg (4, "Could not get the list of mounted file systems"); |
|---|
| | 448 | paranoid_free(mounted_file_system); |
|---|
| | 449 | return (1); |
|---|
| | 450 | } |
|---|
| | 451 | paranoid_free(mounted_file_system); |
|---|
| | 452 | log_msg (5, "token: %s", token); |
|---|
| | 453 | while (token != NULL) { |
|---|
| | 454 | log_msg (5, "token: %s", token); |
|---|
| | 455 | if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) { |
|---|
| | 456 | fatal_error ("Cannot allocate memory"); |
|---|
| | 457 | } |
|---|
| | 458 | add_mounted_fs_struct(DSFptr); |
|---|
| | 459 | strcpy(DSFptr->device, token); |
|---|
| | 460 | if ((token = strtok(NULL, token_chars)) == NULL) { |
|---|
| | 461 | log_msg (5, "Ran out of entries on the mounted file systems list"); |
|---|
| | 462 | return (1); |
|---|
| | 463 | } |
|---|
| | 464 | log_msg (5, "token: %s", token); |
|---|
| | 465 | strcpy(DSFptr->mount_point, token); |
|---|
| | 466 | token = strtok(NULL, token_chars); |
|---|
| | 467 | } |
|---|
| | 468 | } |
|---|
| | 469 | /******** |
|---|
| | 470 | * DSFptr = DSF_Head; |
|---|
| | 471 | * while (DSFptr != NULL) { |
|---|
| | 472 | * printf ("Dev: %s MP: %s Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check); |
|---|
| | 473 | * DSFptr = DSFptr->next; |
|---|
| | 474 | * } |
|---|
| | 475 | ********/ |
|---|
| | 476 | return (0); |
|---|
| | 477 | } |
|---|
| | 478 | |
|---|
| | 479 | /** |
|---|
| | 480 | * Given a whole disk device special file, determine which mounted file systems |
|---|
| | 481 | * are on the dsf's partitions and which mounted file systems are not. |
|---|
| | 482 | * @param dsf The whole disk device special file. |
|---|
| | 483 | * @param included_dsf_list A char pointer used to hold the list of mount points |
|---|
| | 484 | * that are on the dsf. Memory for the array will be allocated within the function. |
|---|
| | 485 | * @param excluded_dsf_list A char pointer used to hold the list of mount points |
|---|
| | 486 | * that are not on the dsf. Memory for the array will be allocated within the function. |
|---|
| | 487 | * @return 0 on success, -1 if no device special file was passed in, -2 if a device |
|---|
| | 488 | * special file was passed in but it has no partitions on it, or 1 on failure |
|---|
| | 489 | */ |
|---|
| | 490 | static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) { |
|---|
| | 491 | int i = 0; |
|---|
| | 492 | int c = 0; |
|---|
| | 493 | int dsf_cnt = 0; |
|---|
| | 494 | int num_dsf = 0; |
|---|
| | 495 | char VG[MAX_STR_LEN]; |
|---|
| | 496 | char *tmp = NULL; |
|---|
| | 497 | char *command = NULL; |
|---|
| | 498 | char *partition_list = NULL; |
|---|
| | 499 | char partitions[64][MAX_STR_LEN]; |
|---|
| | 500 | char dsf_list[16][MAX_STR_LEN]; |
|---|
| | 501 | char *mount_list = NULL; |
|---|
| | 502 | char *token = NULL; |
|---|
| | 503 | char *DSF = NULL; |
|---|
| | 504 | char token_chars[] =" \t\r\f\a\0"; |
|---|
| | 505 | MOUNTED_FS_STRUCT *DSFptr = NULL; |
|---|
| | 506 | |
|---|
| | 507 | malloc_string(DSF); |
|---|
| | 508 | memset((char *)partitions, 0, sizeof(partitions)); |
|---|
| | 509 | memset((char *)dsf_list, 0, sizeof(dsf_list)); |
|---|
| | 510 | |
|---|
| | 511 | num_dsf = 0; |
|---|
| | 512 | log_msg(5, "DSF's: %s", dsf); |
|---|
| | 513 | strcpy(DSF, dsf); |
|---|
| | 514 | token = strtok(DSF, token_chars); |
|---|
| | 515 | while (token != NULL) { |
|---|
| | 516 | log_msg (5, " dsf: %s", token); |
|---|
| | 517 | strcpy(dsf_list[num_dsf], token); |
|---|
| | 518 | /******** |
|---|
| | 519 | * See if a device special file was passed in (i.e. it must start with /dev/ |
|---|
| | 520 | ********/ |
|---|
| | 521 | if (strncmp(dsf_list[num_dsf], "/dev/", 5)) { |
|---|
| | 522 | log_msg (5, "%s does not start with /dev/ and (probably) is not a device special file", dsf_list[num_dsf]); |
|---|
| | 523 | return (-1); |
|---|
| | 524 | } |
|---|
| | 525 | log_msg(5, " %s looks like a device special file", dsf_list[num_dsf]); |
|---|
| | 526 | /* Verify that the dsf exists */ |
|---|
| | 527 | asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf_list[num_dsf]); |
|---|
| | 528 | log_msg(5, " Executing: %s", command); |
|---|
| | 529 | asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); |
|---|
| | 530 | paranoid_free(command); |
|---|
| | 531 | log_msg(5, " Return value: %s", tmp); |
|---|
| | 532 | c = atoi(tmp); |
|---|
| | 533 | paranoid_free(tmp); |
|---|
| | 534 | if (!c) { |
|---|
| | 535 | log_to_screen("Cannot find device special file %s", dsf_list[num_dsf]); |
|---|
| | 536 | return (1); |
|---|
| | 537 | } |
|---|
| | 538 | log_msg(5, " %s device special file exists", dsf_list[dsf_cnt]); |
|---|
| | 539 | num_dsf++; |
|---|
| | 540 | token = strtok(NULL, token_chars); |
|---|
| | 541 | } |
|---|
| | 542 | paranoid_free(DSF); |
|---|
| | 543 | log_msg (5, " num_dsf: %d", num_dsf); |
|---|
| | 544 | |
|---|
| | 545 | /* Get a list of the mounted file systems */ |
|---|
| | 546 | if (create_list_of_non_NFS_mounted_file_systems()) { |
|---|
| | 547 | log_to_screen ("Could not get the list of mounted file systems"); |
|---|
| | 548 | return (1); |
|---|
| | 549 | } |
|---|
| | 550 | /* Loop throught each dsf */ |
|---|
| | 551 | for (dsf_cnt=0; dsf_cnt < num_dsf; dsf_cnt++) { |
|---|
| | 552 | log_msg (5, "Processing dsf: %s", dsf_list[dsf_cnt]); |
|---|
| | 553 | /******** |
|---|
| | 554 | * Get a list of the dsf's partitions. There could be no partitions on the disk |
|---|
| | 555 | * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda). |
|---|
| | 556 | * Either way, it's an error. |
|---|
| | 557 | ********/ |
|---|
| | 558 | asprintf(&command, |
|---|
| | 559 | "fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf_list[dsf_cnt]); |
|---|
| | 560 | log_msg(4, "Executing: %s", command); |
|---|
| | 561 | asprintf(&partition_list, call_program_and_get_last_line_of_output(command)); |
|---|
| | 562 | paranoid_free(command); |
|---|
| | 563 | log_msg(4, "Partition list for %s: %s", dsf_list[dsf_cnt], partition_list); |
|---|
| | 564 | if (!strlen(partition_list)) { |
|---|
| | 565 | /* There were no partitions on the disk */ |
|---|
| | 566 | log_msg(4, "Cannot find any partitions on device special file %s", dsf_list[dsf_cnt]); |
|---|
| | 567 | return (-2); |
|---|
| | 568 | } |
|---|
| | 569 | |
|---|
| | 570 | /* Fill the partition list */ |
|---|
| | 571 | i = 0; |
|---|
| | 572 | token = strtok(partition_list, token_chars); |
|---|
| | 573 | while (token != NULL) { |
|---|
| | 574 | log_msg (5, "Found partition: %s", token); |
|---|
| | 575 | strcpy(partitions[i++], token); |
|---|
| | 576 | token = strtok(NULL, token_chars); |
|---|
| | 577 | } |
|---|
| | 578 | paranoid_free(partition_list); |
|---|
| | 579 | |
|---|
| | 580 | /******** |
|---|
| | 581 | * At this point, we have a list of all of the partitions on the dsf. Now try to |
|---|
| | 582 | * see which partitions have a file system on them. |
|---|
| | 583 | * |
|---|
| | 584 | * Loop through each partition on the disk and: |
|---|
| | 585 | * |
|---|
| | 586 | * - If the partition is swap, it ignores it. |
|---|
| | 587 | * |
|---|
| | 588 | * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry |
|---|
| | 589 | * to the linked list, copies to it the device name and mount point, and sets check == 1. |
|---|
| | 590 | * |
|---|
| | 591 | * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds |
|---|
| | 592 | * an entry to the linked list for each mounted Logical Volume in that Volume Group, copying |
|---|
| | 593 | * to it the device name and mount point, and sets check == 1. Note that if the Volume Group |
|---|
| | 594 | * contains more than one disk, it will still add the entry even if the Logical Volume's |
|---|
| | 595 | * extents are not on the dsf that was passed in to the function. For example, Volume Group |
|---|
| | 596 | * VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01, |
|---|
| | 597 | * which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is |
|---|
| | 598 | * mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the |
|---|
| | 599 | * function, both /var and /usr will be archived even though /usr is actually on/dev/sdb. |
|---|
| | 600 | * |
|---|
| | 601 | * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted |
|---|
| | 602 | * software raid device, it adds an entry to the linked list, copies to it the software raid |
|---|
| | 603 | * device name and mount point, and sets check == 1. |
|---|
| | 604 | * |
|---|
| | 605 | * - If the partition is part of a mounted software raid device, it adds an entry to the linked |
|---|
| | 606 | * list, copies to it the software raid device name and mount point, and sets check == 1. |
|---|
| | 607 | * |
|---|
| | 608 | ********/ |
|---|
| | 609 | for (i=0; strlen(partitions[i]); i++) { |
|---|
| | 610 | log_msg(4, "Processing partition: %s", partitions[i]); |
|---|
| | 611 | /* See if it's swap. If it is, ignore it. */ |
|---|
| | 612 | asprintf(&command, |
|---|
| | 613 | "fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", |
|---|
| | 614 | dsf_list[dsf_cnt], partitions[i]); |
|---|
| | 615 | log_msg(4, " Running: %s", command); |
|---|
| | 616 | asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); |
|---|
| | 617 | paranoid_free(command); |
|---|
| | 618 | log_msg(4, " Return value: %s", tmp); |
|---|
| | 619 | c = strlen(tmp); |
|---|
| | 620 | paranoid_free(tmp); |
|---|
| | 621 | if (c) { |
|---|
| | 622 | log_msg(4, "It's swap. Ignoring partition %s", partitions[i]); |
|---|
| | 623 | continue; |
|---|
| | 624 | } |
|---|
| | 625 | /* It's not swap. See if we can find the mount point from the mount command. */ |
|---|
| | 626 | asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]); |
|---|
| | 627 | sprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); |
|---|
| | 628 | paranoid_free(command); |
|---|
| | 629 | if (strlen(tmp)) { |
|---|
| | 630 | log_msg(4, " %s is mounted: %s", partitions[i], tmp); |
|---|
| | 631 | if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) { |
|---|
| | 632 | log_msg (4, "Can't find mount point %s in mounted file systems list", tmp); |
|---|
| | 633 | paranoid_free(tmp); |
|---|
| | 634 | return (1); |
|---|
| | 635 | } |
|---|
| | 636 | DSFptr->check = 1; |
|---|
| | 637 | paranoid_free(tmp); |
|---|
| | 638 | continue; |
|---|
| | 639 | } |
|---|
| | 640 | paranoid_free(tmp); |
|---|
| | 641 | /* It's not swap and it's not mounted. See if it's LVM */ |
|---|
| | 642 | log_msg(4, " It's not mounted. Checking to see if it's LVM..."); |
|---|
| | 643 | /* Get the partition ID; 8e for LVM */ |
|---|
| | 644 | asprintf(&command, "fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf_list[dsf_cnt], partitions[i]); |
|---|
| | 645 | log_msg(4, " Running: %s", command); |
|---|
| | 646 | asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); |
|---|
| | 647 | paranoid_free(command); |
|---|
| | 648 | if (strlen(tmp)) { |
|---|
| | 649 | log_msg(4, " Partition ID: %s", tmp); |
|---|
| | 650 | if (!strcasecmp(tmp, "8e")) { |
|---|
| | 651 | /* It's LVM: Find the VG it's in */ |
|---|
| | 652 | log_msg(4, " It's LVM: Find the VG it's in..."); |
|---|
| | 653 | asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]); |
|---|
| | 654 | log_msg(4, " Running: %s", command); |
|---|
| | 655 | strcpy(VG, call_program_and_get_last_line_of_output(command)); |
|---|
| | 656 | paranoid_free(command); |
|---|
| | 657 | log_msg(4, " Volume Group: %s", VG); |
|---|
| | 658 | if (strlen(VG)) { |
|---|
| | 659 | /* Found the Volume Group. Now find all of the VG's mount points */ |
|---|
| | 660 | log_msg(4, " Found the Volume Group. Now find all of the VG's mount points"); |
|---|
| | 661 | asprintf(&command, |
|---|
| | 662 | "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", |
|---|
| | 663 | VG, VG); |
|---|
| | 664 | log_msg(4, " Running: %s", command); |
|---|
| | 665 | asprintf(&mount_list, call_program_and_get_last_line_of_output(command)); |
|---|
| | 666 | paranoid_free(command); |
|---|
| | 667 | log_msg(4, " VG %s mount_list: %s", VG, mount_list); |
|---|
| | 668 | token = strtok(mount_list, token_chars); |
|---|
| | 669 | while (token != NULL) { |
|---|
| | 670 | log_msg (5, "mount point token: %s", token); |
|---|
| | 671 | if ((DSFptr = find_mount_point_in_list(token)) == NULL) { |
|---|
| | 672 | log_msg (4, "Can't find mount point %s in mounted file systems list", token); |
|---|
| | 673 | paranoid_free(tmp); |
|---|
| | 674 | return (1); |
|---|
| | 675 | } |
|---|
| | 676 | DSFptr->check = 1; |
|---|
| | 677 | token = strtok(NULL, token_chars); |
|---|
| | 678 | } |
|---|
| | 679 | /******** |
|---|
| | 680 | * Now we want to see if there are any software raid devices using |
|---|
| | 681 | * any of the Logical Volumes on the Volume Group. |
|---|
| | 682 | *******/ |
|---|
| | 683 | paranoid_free(mount_list); |
|---|
| | 684 | asprintf(&command, |
|---|
| | 685 | "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); |
|---|
| | 686 | log_msg (5, "Running: %s", command); |
|---|
| | 687 | asprintf(&mount_list, call_program_and_get_last_line_of_output(command)); |
|---|
| | 688 | paranoid_free(command); |
|---|
| | 689 | log_msg(4, " Software raid device list: %s", mount_list); |
|---|
| | 690 | token = strtok(mount_list, token_chars); |
|---|
| | 691 | while (token != NULL) { |
|---|
| | 692 | asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG); |
|---|
| | 693 | log_msg (5, "Running: %s", command); |
|---|
| | 694 | paranoid_free(tmp); |
|---|
| | 695 | asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); |
|---|
| | 696 | paranoid_free(command); |
|---|
| | 697 | log_msg(4, "Number of Software raid device: %s", tmp); |
|---|
| | 698 | if (atoi(tmp)) { |
|---|
| | 699 | /* This device is on our disk */ |
|---|
| | 700 | if ((DSFptr = find_device_in_list(token)) == NULL) { |
|---|
| | 701 | log_msg (4, "Can't find device %s in mounted file systems list", token); |
|---|
| | 702 | paranoid_free(tmp); |
|---|
| | 703 | return (1); |
|---|
| | 704 | } |
|---|
| | 705 | DSFptr->check = 1; |
|---|
| | 706 | } |
|---|
| | 707 | token = strtok(NULL, token_chars); |
|---|
| | 708 | } |
|---|
| | 709 | paranoid_free(mount_list); |
|---|
| | 710 | } else { |
|---|
| | 711 | log_msg (4, "Error finding Volume Group for partition %s", partitions[i]); |
|---|
| | 712 | paranoid_free(tmp); |
|---|
| | 713 | return (1); |
|---|
| | 714 | } |
|---|
| | 715 | paranoid_free(tmp); |
|---|
| | 716 | continue; |
|---|
| | 717 | } |
|---|
| | 718 | } else { |
|---|
| | 719 | log_msg (4, "Error finding partition type for the partition %s", partitions[i]); |
|---|
| | 720 | } |
|---|
| | 721 | paranoid_free(tmp); |
|---|
| | 722 | /******** |
|---|
| | 723 | * It's not swap, mounted, or LVM. See if it's used in a software raid device. |
|---|
| | 724 | ********/ |
|---|
| | 725 | log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device."); |
|---|
| | 726 | asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]); |
|---|
| | 727 | log_msg(4, " Running: %s", command); |
|---|
| | 728 | asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); |
|---|
| | 729 | paranoid_free(command); |
|---|
| | 730 | if (!strlen(tmp)) { |
|---|
| | 731 | log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]); |
|---|
| | 732 | paranoid_free(tmp); |
|---|
| | 733 | continue; |
|---|
| | 734 | } |
|---|
| | 735 | log_msg (5, " UUID: %s", tmp); |
|---|
| | 736 | /* Get the Software raid device list */ |
|---|
| | 737 | asprintf(&command, |
|---|
| | 738 | "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); |
|---|
| | 739 | log_msg (5, " Running: %s", command); |
|---|
| | 740 | asprintf(&mount_list, call_program_and_get_last_line_of_output(command)); |
|---|
| | 741 | paranoid_free(command); |
|---|
| | 742 | log_msg(4, " Software raid device list: %s", mount_list); |
|---|
| | 743 | /* Loop through the software raid device list to see if we can find the partition */ |
|---|
| | 744 | token = strtok(mount_list, token_chars); |
|---|
| | 745 | while (token != NULL) { |
|---|
| | 746 | asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp); |
|---|
| | 747 | log_msg(4, " Running: %s", command); |
|---|
| | 748 | paranoid_free(tmp); |
|---|
| | 749 | asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); |
|---|
| | 750 | paranoid_free(command); |
|---|
| | 751 | if (!atoi(tmp)) { |
|---|
| | 752 | log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token); |
|---|
| | 753 | } else { |
|---|
| | 754 | if ((DSFptr = find_device_in_list(token)) == NULL) { |
|---|
| | 755 | log_msg (4, "Can't find device %s in mounted file systems list", token); |
|---|
| | 756 | paranoid_free(tmp); |
|---|
| | 757 | return (1); |
|---|
| | 758 | } |
|---|
| | 759 | DSFptr->check = 1; |
|---|
| | 760 | break; |
|---|
| | 761 | } |
|---|
| | 762 | token = strtok(NULL, token_chars); |
|---|
| | 763 | } |
|---|
| | 764 | paranoid_free(tmp); |
|---|
| | 765 | } |
|---|
| | 766 | } |
|---|
| | 767 | paranoid_free(partition_list); |
|---|
| | 768 | paranoid_free(mount_list); |
|---|
| | 769 | |
|---|
| | 770 | /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */ |
|---|
| | 771 | i = 0; |
|---|
| | 772 | DSFptr= DSF_Head; |
|---|
| | 773 | while (DSFptr != NULL) { |
|---|
| | 774 | i += strlen(DSFptr->mount_point) + 1; |
|---|
| | 775 | DSFptr = DSFptr->next; |
|---|
| | 776 | } |
|---|
| | 777 | log_msg (5, "i: %d", i); |
|---|
| | 778 | if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) { |
|---|
| | 779 | fatal_error ("Cannot allocate memory"); |
|---|
| | 780 | } |
|---|
| | 781 | if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) { |
|---|
| | 782 | fatal_error ("Cannot allocate memory"); |
|---|
| | 783 | } |
|---|
| | 784 | DSFptr= DSF_Head; |
|---|
| | 785 | while (DSFptr != NULL) { |
|---|
| | 786 | if (DSFptr->check) { |
|---|
| | 787 | log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf); |
|---|
| | 788 | strcat(*included_dsf_list, DSFptr->mount_point); |
|---|
| | 789 | strcat(*included_dsf_list, " "); |
|---|
| | 790 | } else { |
|---|
| | 791 | log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf); |
|---|
| | 792 | strcat(*excluded_dsf_list, DSFptr->mount_point); |
|---|
| | 793 | strcat(*excluded_dsf_list, " "); |
|---|
| | 794 | } |
|---|
| | 795 | DSFptr = DSFptr->next; |
|---|
| | 796 | } |
|---|
| | 797 | log_msg (5, "included_dsf_list: %s", *included_dsf_list); |
|---|
| | 798 | log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list); |
|---|
| | 799 | return (0); |
|---|
| | 800 | } |
|---|