Changeset 2007 in MondoRescue


Ignore:
Timestamp:
Aug 10, 2008, 7:48:51 PM (16 years ago)
Author:
Bruno Cornec
Message:

Patch and comment from Michael Shapiro:

I wrote a function called get_dsf_mount_list() that, given a whole disk device special file (dsf), it will return a list of all of the mounted file systems residing on that disk in the
variable included_dsf_list, and a list of all of the mounted file systems that are not residing on that disk in the variable excluded_dsf_list:

static int
get_dsf_mount_list (char *dsf,

char included_dsf_list,
char
excluded_dsf_list);

The function does the following:

  • Verifies that the dsf exists and has a partition table on it.
  • Creates a linked list of all of the locally mounted file systems (i.e. the mount points that start with "/dev/") using a new structure called mounted_fs_struct. Each structure contains the name of the

device, the device's mount point, and a variable called check that will be set to 1 if the mount point resides on the disk and a 0 if the mount point does not reside on the disk.

  • Loops through each partition on the disk and:

-- If the partition is swap, it ignores it.

-- If the partition is mounted (e.g. /dev/sda1 is mounted on /boot, /dev/sda2 is mounted on /usr, etc.), it finds its entry on the linked list and sets check == 1.

-- If the partition is part of a Volume Group that has Logical Volumes mounted, it finds its entry on the linked list for each mounted Logical Volume in that Volume Group and sets check == 1. Note that if
the Volume Group contains more than one disk, it will still add the entry even if the Logical Volume's extents are not on, or only partially on, the dsf that was passed in to the function. For example,
Volume Group VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01, which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is mounted as /usr
and has all of its extents on /dev/sdb1. If you pass /dev/sda into the function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.

-- If the partition is part of a Volume Group that has Logical Volumes used in a mounted software raid device, it finds its entry on the linked list and sets check == 1.

-- If the partition is part of a mounted software raid device, it finds its entry on the linked list and sets check == 1.

  • At the end of the function, it walks through the linked list and, for every entry where check == 1, catenates the mount point to included_dsf_list. For every entry where check == 0, it catenates the mount

point to excluded_dsf_list.

In process_switches():

  • I added code to the section that processes the -I option and, if a whole disk device special file is passed in, it calls get_dsf_mount_list(), sets bkpinfo->include_paths == "/", and catenates the

contents of excluded_dsf_list to bkpinfo->exclude_paths. If a whole disk device special file is not passed in, it processes the -I option normally.

  • I added code to the section that processes the -E option and, if a whole disk device special file is passed in, it calls get_dsf_mount_list() and catenates the contents of included_dsf_list to

bkpinfo->exclude_paths. If a whole disk device special file is not passed in, it processes the -E option normally.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.7/mondo/src/common/libmondo-cli.c

    r1991 r2007  
    191191extern pid_t g_main_pid;
    192192extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
     193
     194/* Stuff that handles the -I and -E option when a whole disk DSF is used */
     195typedef struct mounted_fs_struct {
     196    char device[MAX_STR_LEN];       /* The name of the device */
     197    char mount_point[MAX_STR_LEN];  /* The devices mount point */
     198    unsigned char check;            /* 1 == included on DSF */
     199    struct mounted_fs_struct *next;
     200} MOUNTED_FS_STRUCT;
     201static MOUNTED_FS_STRUCT *DSF_Head = NULL;      /* Points to the first entry of mounted_fs_struct list */
     202static MOUNTED_FS_STRUCT *DSF_Tail = NULL;      /* Points to the last entry of mounted_fs_struct list */
     203static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr);
     204static void free_mounted_fs_list (void);
     205static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list);
     206static int create_list_of_non_NFS_mounted_file_systems (void);
     207static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point);
     208static MOUNTED_FS_STRUCT *find_device_in_list (char *device);
    193209
    194210/* Do we use extended attributes and acl ?
     
    310326}
    311327
     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 */
     332static 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 */
     352static 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 */
     371static 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 */
     392static 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 */
     412static 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 */
     490static 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}
    312801
    313802
     
    337826    char *p;
    338827    char *q;
     828    char *mounted_on_dsf = NULL;
     829    char *not_mounted_on_dsf = NULL;
    339830
    340831    long itbs = 0L;
     
    426917            strcat(bkpinfo->include_paths, " ");
    427918        }
    428         asprintf(&tmp1, flag_val['I']);
    429         p = tmp1;
    430         q = tmp1;
    431 
    432         /* Cut the flag_val['I'] in parts containing all paths to test them */
    433         while (p != NULL) {
    434             q = strchr(p, ' ');
    435             if (q != NULL) {
    436                 *q = '\0';
    437                 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
    438                     log_msg(1, "ERROR ! %s doesn't exist", p);
    439                     fatal_error("ERROR ! You specified a directory to include which doesn't exist");
     919        switch (get_dsf_mount_list(flag_val['I'], &mounted_on_dsf, &not_mounted_on_dsf)) {
     920            /* It's a dsf but not a whole disk dsf */
     921            case -2:
     922                log_to_screen("Could %s be a partition instead of a whole disk device special file?\n", flag_val['I']);
     923                break;
     924            /* Fatal error; exit */
     925            case 1:
     926                fatal_error("Error processing -I option");
     927            /* Everything is OK; process to archive data */
     928            case 0:
     929                log_to_screen("Archiving only the following file systems on %s:\n", flag_val['I']);
     930                log_to_screen("  %s\n", mounted_on_dsf);
     931                strcpy(bkpinfo->include_paths, "/");
     932                if (strlen(not_mounted_on_dsf)) {
     933                    log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
     934                    log_to_screen("Not archiving the following file systems:\n");
     935                    log_to_screen("  %s\n", not_mounted_on_dsf);
     936                    strcat(bkpinfo->exclude_paths, not_mounted_on_dsf);
     937                    strcat(bkpinfo->exclude_paths, "");
    440938                }
    441                 p = q+1 ;
    442             } else {
    443                 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
    444                     log_msg(1, "ERROR ! %s doesn't exist", p);
    445                     fatal_error("ERROR ! You specified a directory to include which doesn't exist");
     939                break;
     940            /* A device special file was not passed in. Process it as a path. */
     941            case -1:
     942
     943                p = tmp1;
     944                q = tmp1;
     945
     946                /* Cut the flag_val['I'] in parts containing all paths to test them */
     947                while (p != NULL) {
     948                    q = strchr(p, ' ');
     949                    if (q != NULL) {
     950                        *q = '\0';
     951                        if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
     952                            log_msg(1, "ERROR ! %s doesn't exist", p);
     953                            fatal_error("ERROR ! You specified a directory to include which doesn't exist");
     954                        }
     955                        p = q+1 ;
     956                    } else {
     957                        if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
     958                            log_msg(1, "ERROR ! %s doesn't exist", p);
     959                            fatal_error("ERROR ! You specified a directory to include which doesn't exist");
     960                        }
     961                        p = NULL;
     962                    }
    446963                }
    447                 p = NULL;
    448             }
    449         }
    450         paranoid_free(tmp1);
    451 
    452         strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
    453                 flag_val['I'],
    454                 4*MAX_STR_LEN - strlen(bkpinfo->include_paths));
    455         log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
    456         if (bkpinfo->include_paths[0] == '-') {
    457             retval++;
    458             log_to_screen("Please supply a sensible value with '-I'\n");
    459         }
     964                paranoid_free(tmp1);
     965                strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
     966                    flag_val['I'],
     967                    4*MAX_STR_LEN - strlen(bkpinfo->include_paths));
     968                if (bkpinfo->include_paths[0] == '-') {
     969                    retval++;
     970                    log_to_screen("Please supply a sensible value with '-I'\n");
     971                }
     972                break;
     973            }
     974            log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
     975            log_msg(4, "Finished with the -I option");
    460976    }
    461977
     
    6971213        }
    6981214        asprintf(&tmp1, flag_val['E']);
    699         p = tmp1;
    700         q = tmp1;
    701 
    702         /* Cut the flag_val['E'] in parts containing all paths to test them */
    703         while (p != NULL) {
    704             q = strchr(p, ' ');
    705             if (q != NULL) {
    706                 *q = '\0';
    707                 /* Fix bug 14 where ending / cause a problem later
    708                  * so handled here for the moment */
    709                 q--;
    710                 if (*q == '/') {
    711                     *q = '\0';
     1215
     1216        switch (get_dsf_mount_list(flag_val['E'], &mounted_on_dsf, &not_mounted_on_dsf)) {
     1217            /* Fatal error; exit */
     1218            case 1:
     1219                fatal_error ("Error processing -I option");
     1220            /* Everything is OK; proceed to archive data */
     1221            case 0:
     1222                if (strlen(mounted_on_dsf)) {
     1223                    log_to_screen("Excluding the following file systems on %s:\n", flag_val['E']);
     1224                    `log_to_screen("  %s\n", mounted_on_dsf);
     1225                    log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
     1226                    strcat(bkpinfo->exclude_paths, mounted_on_dsf);
     1227                    strcat(bkpinfo->exclude_paths, "");
    7121228                }
    713                 q++;
    714                 /* End of bug fix */
    715                 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
    716                     log_msg(1, "WARNING ! %s doesn't exist", p);
     1229                break;
     1230            /* It's a dsf but not a whole disk dsf */
     1231            case -2:
     1232                break;
     1233            /* A device special file was not passed in. Process it as a path. */
     1234            case -1:
     1235                p = tmp1;
     1236                q = tmp1;
     1237
     1238                /* Cut the flag_val['E'] in parts containing all paths to test them */
     1239                while (p != NULL) {
     1240                    q = strchr(p, ' ');
     1241                    if (q != NULL) {
     1242                        *q = '\0';
     1243                        /* Fix bug 14 where ending / cause a problem later
     1244                        * so handled here for the moment */
     1245                        q--;
     1246                        if (*q == '/') {
     1247                            *q = '\0';
     1248                        }
     1249                        q++;
     1250                        /* End of bug fix */
     1251                        if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
     1252                            log_msg(1, "WARNING ! %s doesn't exist", p);
     1253                        }
     1254                        p = q+1 ;
     1255                    } else {
     1256                        if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
     1257                            log_msg(1, "WARNING ! %s doesn't exist", p);
     1258                        }
     1259                        p = NULL;
     1260                    }
    7171261                }
    718                 p = q+1 ;
    719             } else {
    720                 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
    721                     log_msg(1, "WARNING ! %s doesn't exist", p);
    722                 }
    723                 p = NULL;
    724             }
    725         }
    726         paranoid_free(tmp1);
    727 
    728         strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths),
    729                 flag_val['E'],
    730                 4*MAX_STR_LEN - strlen(bkpinfo->exclude_paths));
     1262                paranoid_free(tmp1);
     1263                strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths),
     1264                    flag_val['E'],
     1265                    4*MAX_STR_LEN - strlen(bkpinfo->exclude_paths));
     1266            }
     1267            log_msg(4, "Exclude path from -E: %s", bkpinfo->exclude_paths);
    7311268    }
    7321269
Note: See TracChangeset for help on using the changeset viewer.