Ignore:
Timestamp:
Nov 19, 2005, 2:27:41 AM (18 years ago)
Author:
bcornec
Message:

indent on all the C code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.05/mondo/mondo/common/libmondo-mountlist.c

    r30 r128  
    11/* libmondo-mountlist.c                            subroutines for handling mountlist
    2    $Id: libmondo-mountlist.c,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2   $Id$
    33
    44
     
    6161
    6262/*@unused@*/
    63 //static char cvsid[] = "$Id: libmondo-mountlist.c,v 1.2 2004/06/10 15:29:12 hugo Exp $";
     63//static char cvsid[] = "$Id$";
    6464
    6565/**
     
    8585 * @see evaluate_mountlist
    8686 */
    87 int evaluate_drive_within_mountlist (struct mountlist_itself *mountlist,
    88                  char *drive, char *flaws_str)
     87int evaluate_drive_within_mountlist(struct mountlist_itself *mountlist,
     88                                    char *drive, char *flaws_str)
    8989#ifdef __FreeBSD__
    9090{
    9191// FreeBSD-specific version of evaluate_drive_within_mountlist()
    92     /*@ int **************************************************************/
    93   int prev_part_no = 0;
     92    /*@ int ************************************************************* */
     93    int prev_part_no = 0;
    9494    int curr_part_no = 0;
    9595    int pos = 0, npos = 0;
     
    102102    int foundsome = FALSE;
    103103
    104     /*@ buffers *********************************************************/
    105   char tmp[MAX_STR_LEN];
     104    /*@ buffers ******************************************************** */
     105    char tmp[MAX_STR_LEN];
    106106    char device[MAX_STR_LEN];
    107107    char mountpoint[MAX_STR_LEN];
    108108
    109     /*@ long ************************************************************/
    110   long physical_drive_size = 0;
     109    /*@ long *********************************************************** */
     110    long physical_drive_size = 0;
    111111    long amount_allocated = 0;
    112112
    113     /*@ pointers ********************************************************/
     113    /*@ pointers ******************************************************* */
    114114    char *part_table_fmt;
    115115
    116     /*@ initialize ******************************************************/
    117   flaws_str[0] = '\0';
    118   prev_part_no = 0;
    119   tmp[0] = '\0';
    120 
    121 
    122   physical_drive_size = get_phys_size_of_drive (drive);
    123 
    124   if (physical_drive_size < 0)
    125     {
    126       sprintf (tmp, " %s does not exist.", drive);
    127       strcat (flaws_str, tmp);
    128     }
    129   else
    130     {
    131       sprintf (tmp, "%s is %ld MB", drive, physical_drive_size);
    132     }
    133   log_it (tmp);
    134  
    135 
    136   /* check DD */
    137   for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
    138       sprintf (device, "%s%c", drive, cur_sp_no);
    139       if (find_device_in_mountlist (mountlist, device) >= 0)
    140       foundsome = TRUE;
    141   }
    142   if (foundsome) {
    143       for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {   
    144       sprintf (device, "%s%c", drive, cur_sp_no);
    145       pos = find_device_in_mountlist (mountlist, device);
    146       if (pos < 0)
    147           {
    148           continue;
    149           }
    150       strcpy (mountpoint, mountlist->el[pos].mountpoint);
    151       /* is it too big? */
    152       if (curr_part_no > 'h')
    153           {
    154           sprintf (tmp, " Can only have up to 'h' in disklabel.");
    155           log_it (tmp);
    156           strcat (flaws_str, tmp);
    157           res++;
    158           }
    159       /* does partition /dev/adXsYZ exist more than once in the mountlist? */
    160       for (i = 0, mountpoint_copies = 0, device_copies = 0;
    161            i < mountlist->entries; i++)
    162           {
    163           if (!strcmp (device, mountlist->el[i].device))
    164               {
    165               device_copies++;
    166               }
    167           }
    168       if (device_copies > 1)
    169           {
    170           sprintf (tmp, " %s %s's.", number_to_text (device_copies), device);
    171           if (!strstr (flaws_str, tmp))
    172               {
    173               log_it (tmp);
    174               strcat (flaws_str, tmp);
    175               res++;
    176               }
    177           }
    178       /* silly partition size? */
    179       if (mountlist->el[pos].size < 8192
    180           && strcmp (mountlist->el[pos].mountpoint, "lvm"))
    181           {
    182           sprintf (tmp, " %s is tiny!", device);
    183           log_it (tmp);
    184           strcat (flaws_str, tmp);
    185           res++;
    186           }
    187       /* mountpoint should begin with / unless it is swap, lvm or raid */
    188       if (strcmp (mountlist->el[pos].mountpoint, "swap")
    189           && strcmp (mountlist->el[pos].mountpoint, "lvm")
    190           && strcmp (mountlist->el[pos].mountpoint, "raid")
    191           && strcmp (mountlist->el[pos].mountpoint, "image")
    192           && strcmp (mountlist->el[pos].mountpoint, "none")
    193           && mountlist->el[pos].mountpoint[0] != '/')
    194           {
    195           sprintf (tmp, " %s has a weird mountpoint.", device);
    196           log_it (tmp);
    197           strcat (flaws_str, tmp);
    198           res++;
    199           }
    200       /* is format sensible? */
    201       if (!is_this_a_valid_disk_format (mountlist->el[pos].format))
    202           {
    203           sprintf (tmp, " %s has unsupported format.", device);
    204           log_it (tmp);
    205           strcat (flaws_str, tmp);
    206           res++;
    207           }
    208       amount_allocated += mountlist->el[pos].size / 1024;
    209       prev_sp_no = cur_sp_no;
    210       }
    211   }
    212 
    213   npos = pos = 0;
    214   for (curr_part_no = 1; curr_part_no < 99; curr_part_no++)
    215     {
    216       sprintf (device, "%ss%d", drive, curr_part_no);
    217       pos = find_device_in_mountlist (mountlist, device);
    218       npos = 0;
    219       for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) {
    220       sprintf (device, "%ss%i%c", device, curr_part_no, cur_sp_no);
    221       if (find_device_in_mountlist (mountlist, device) >= 0) npos++;
    222       }
    223       if (((pos >= 0) || npos) && foundsome) {
    224       sprintf (flaws_str + strlen (flaws_str), " %s has both DD and PC-style partitions.", drive);
    225       return ++res; // fatal error
    226       }
    227      
    228       sprintf (device, "%ss%d", drive, curr_part_no);
    229       strcpy (mountpoint, mountlist->el[pos].mountpoint);
    230       if (pos > 0 && !npos) {
    231       /* gap in the partition list? */
    232       if (curr_part_no - prev_part_no > 1)
    233           {
    234           if (prev_part_no == 0)
    235               {
    236               sprintf (tmp, " Gap prior to %s.", device);
    237               log_it (tmp);
    238               strcat (flaws_str, tmp);
    239               res++;
    240               }
    241           else if (curr_part_no > 5
    242                || (curr_part_no <= 4 && prev_part_no > 0))
    243               {
    244               sprintf (tmp, " Gap between %ss%d and %d.", drive, prev_part_no,
    245                    curr_part_no);
    246               log_it (tmp);
    247               strcat (flaws_str, tmp);
    248               res++;
    249               }
    250           }
    251       /* GPT allows more than 4 primary partitions */
    252       part_table_fmt = which_partition_format(drive);
    253       /* no spare primary partitions to help accommodate the logical(s)? */
    254       if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt,"MBR") == 0))
    255           {
    256           sprintf (tmp, " Partition %ss4 is occupied.", drive);
    257           log_it (tmp);
    258           strcat (flaws_str, tmp);
    259           res++;
    260           }
    261       /* does partition /dev/adXsY exist more than once in the mountlist? */
    262       for (i = 0, mountpoint_copies = 0, device_copies = 0;
    263            i < mountlist->entries; i++)
    264           {
    265           if (!strcmp (device, mountlist->el[i].device))
    266               {
    267               device_copies++;
    268               }
    269           }
    270       if (device_copies > 1)
    271           {
    272           sprintf (tmp, " %s %s's.", number_to_text (device_copies), device);
    273           if (!strstr (flaws_str, tmp))
    274               {
    275               log_it (tmp);
    276               strcat (flaws_str, tmp);
    277               res++;
    278               }
    279           }
    280       /* silly partition size? */
    281       if (mountlist->el[pos].size < 8192
    282           && strcmp (mountlist->el[pos].mountpoint, "lvm"))
    283           {
    284           sprintf (tmp, " %s is tiny!", device);
    285           log_it (tmp);
    286           strcat (flaws_str, tmp);
    287           res++;
    288           }
    289       /* mountpoint should begin with / unless it is swap, lvm or raid */
    290       if (strcmp (mountlist->el[pos].mountpoint, "swap")
    291           && strcmp (mountlist->el[pos].mountpoint, "lvm")
    292           && strcmp (mountlist->el[pos].mountpoint, "raid")
    293           && strcmp (mountlist->el[pos].mountpoint, "image")
    294           && strcmp (mountlist->el[pos].mountpoint, "none")
    295           && mountlist->el[pos].mountpoint[0] != '/')
    296           {
    297           sprintf (tmp, " %s has a weird mountpoint.", device);
    298           log_it (tmp);
    299           strcat (flaws_str, tmp);
    300           res++;
    301           }
    302       /* is format sensible? */
    303       if (!is_this_a_valid_disk_format (mountlist->el[pos].format))
    304           {
    305           sprintf (tmp, " %s has unsupported format.", device);
    306           log_it (tmp);
    307           strcat (flaws_str, tmp);
    308           res++;
    309           }
    310       } else {
    311       /* Check subpartitions */
    312       for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {   
    313           sprintf (device, "%ss%d%c", drive, curr_part_no, cur_sp_no);
    314           pos = find_device_in_mountlist (mountlist, device);
    315           if (pos < 0)
    316           {
    317           continue;
    318           }
    319           strcpy (mountpoint, mountlist->el[pos].mountpoint);
    320           /* is it too big? */
    321           if (curr_part_no > 'h')
    322           {
    323               sprintf (tmp, " Can only have up to 'h' in disklabel.");
    324               log_it (tmp);
    325               strcat (flaws_str, tmp);
    326               res++;
    327           }
    328           /* does partition /dev/adXsYZ exist more than once in the mountlist? */
    329           for (i = 0, mountpoint_copies = 0, device_copies = 0;
    330            i < mountlist->entries; i++)
    331           {
    332               if (!strcmp (device, mountlist->el[i].device))
    333               {
    334                   device_copies++;
    335               }
    336           }
    337           if (device_copies > 1)
    338           {
    339               sprintf (tmp, " %s %s's.", number_to_text (device_copies), device);
    340               if (!strstr (flaws_str, tmp))
    341               {
    342                   log_it (tmp);
    343                   strcat (flaws_str, tmp);
    344                   res++;
    345               }
    346           }
    347           /* silly partition size? */
    348           if (mountlist->el[pos].size < 8192
    349           && strcmp (mountlist->el[pos].mountpoint, "lvm"))
    350           {
    351               sprintf (tmp, " %s is tiny!", device);
    352               log_it (tmp);
    353               strcat (flaws_str, tmp);
    354               res++;
    355           }
    356           /* mountpoint should begin with / unless it is swap, lvm or raid */
    357           if (strcmp (mountlist->el[pos].mountpoint, "swap")
    358           && strcmp (mountlist->el[pos].mountpoint, "lvm")
    359           && strcmp (mountlist->el[pos].mountpoint, "raid")
    360           && strcmp (mountlist->el[pos].mountpoint, "image")
    361           && strcmp (mountlist->el[pos].mountpoint, "none")
    362           && mountlist->el[pos].mountpoint[0] != '/')
    363           {
    364               sprintf (tmp, " %s has a weird mountpoint.", device);
    365               log_it (tmp);
    366               strcat (flaws_str, tmp);
    367               res++;
    368           }
    369           /* is format sensible? */
    370           if (!is_this_a_valid_disk_format (mountlist->el[pos].format))
    371           {
    372               sprintf (tmp, " %s has unsupported format.", device);
    373               log_it (tmp);
    374               strcat (flaws_str, tmp);
    375               res++;
    376           }
    377           amount_allocated += mountlist->el[pos].size / 1024;
    378           prev_sp_no = cur_sp_no;
    379       }
    380       }
    381      
    382       /* OK, continue with main loop */
    383       amount_allocated += mountlist->el[pos].size / 1024;
    384       prev_part_no = curr_part_no;
    385     }
    386 
    387   /* Over-allocated the disk? Unallocated space on disk? */
    388   if (amount_allocated > physical_drive_size)  // Used to be +1, but what if you're 1 MB too high?
    389     {
    390       sprintf (tmp, " %ld MB over-allocated on %s.",
    391            amount_allocated - physical_drive_size, drive);
    392       log_it (tmp);
    393       strcat (flaws_str, tmp);
    394       res++;
    395     }
    396   else if (amount_allocated < physical_drive_size - 1)
    397     {               /* NOT AN ERROR, JUST A WARNING :-) */
    398       sprintf (tmp, " %ld MB unallocated on %s.",
    399            physical_drive_size - amount_allocated, drive);
    400       log_it (tmp), strcat (flaws_str, tmp);
    401     }
    402   if (res)
    403     {
    404       return (FALSE);
    405     }
    406   else
    407     {
    408       return (TRUE);
    409     }
     116    /*@ initialize ***************************************************** */
     117    flaws_str[0] = '\0';
     118    prev_part_no = 0;
     119    tmp[0] = '\0';
     120
     121
     122    physical_drive_size = get_phys_size_of_drive(drive);
     123
     124    if (physical_drive_size < 0) {
     125        sprintf(tmp, " %s does not exist.", drive);
     126        strcat(flaws_str, tmp);
     127    } else {
     128        sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
     129    }
     130    log_it(tmp);
     131
     132
     133    /* check DD */
     134    for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
     135        sprintf(device, "%s%c", drive, cur_sp_no);
     136        if (find_device_in_mountlist(mountlist, device) >= 0)
     137            foundsome = TRUE;
     138    }
     139    if (foundsome) {
     140        for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
     141            sprintf(device, "%s%c", drive, cur_sp_no);
     142            pos = find_device_in_mountlist(mountlist, device);
     143            if (pos < 0) {
     144                continue;
     145            }
     146            strcpy(mountpoint, mountlist->el[pos].mountpoint);
     147            /* is it too big? */
     148            if (curr_part_no > 'h') {
     149                sprintf(tmp, " Can only have up to 'h' in disklabel.");
     150                log_it(tmp);
     151                strcat(flaws_str, tmp);
     152                res++;
     153            }
     154            /* does partition /dev/adXsYZ exist more than once in the mountlist? */
     155            for (i = 0, mountpoint_copies = 0, device_copies = 0;
     156                 i < mountlist->entries; i++) {
     157                if (!strcmp(device, mountlist->el[i].device)) {
     158                    device_copies++;
     159                }
     160            }
     161            if (device_copies > 1) {
     162                sprintf(tmp, " %s %s's.", number_to_text(device_copies),
     163                        device);
     164                if (!strstr(flaws_str, tmp)) {
     165                    log_it(tmp);
     166                    strcat(flaws_str, tmp);
     167                    res++;
     168                }
     169            }
     170            /* silly partition size? */
     171            if (mountlist->el[pos].size < 8192
     172                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
     173                sprintf(tmp, " %s is tiny!", device);
     174                log_it(tmp);
     175                strcat(flaws_str, tmp);
     176                res++;
     177            }
     178            /* mountpoint should begin with / unless it is swap, lvm or raid */
     179            if (strcmp(mountlist->el[pos].mountpoint, "swap")
     180                && strcmp(mountlist->el[pos].mountpoint, "lvm")
     181                && strcmp(mountlist->el[pos].mountpoint, "raid")
     182                && strcmp(mountlist->el[pos].mountpoint, "image")
     183                && strcmp(mountlist->el[pos].mountpoint, "none")
     184                && mountlist->el[pos].mountpoint[0] != '/') {
     185                sprintf(tmp, " %s has a weird mountpoint.", device);
     186                log_it(tmp);
     187                strcat(flaws_str, tmp);
     188                res++;
     189            }
     190            /* is format sensible? */
     191            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
     192                sprintf(tmp, " %s has unsupported format.", device);
     193                log_it(tmp);
     194                strcat(flaws_str, tmp);
     195                res++;
     196            }
     197            amount_allocated += mountlist->el[pos].size / 1024;
     198            prev_sp_no = cur_sp_no;
     199        }
     200    }
     201
     202    npos = pos = 0;
     203    for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
     204        sprintf(device, "%ss%d", drive, curr_part_no);
     205        pos = find_device_in_mountlist(mountlist, device);
     206        npos = 0;
     207        for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) {
     208            sprintf(device, "%ss%i%c", device, curr_part_no, cur_sp_no);
     209            if (find_device_in_mountlist(mountlist, device) >= 0)
     210                npos++;
     211        }
     212        if (((pos >= 0) || npos) && foundsome) {
     213            sprintf(flaws_str + strlen(flaws_str),
     214                    " %s has both DD and PC-style partitions.", drive);
     215            return ++res;       // fatal error
     216        }
     217
     218        sprintf(device, "%ss%d", drive, curr_part_no);
     219        strcpy(mountpoint, mountlist->el[pos].mountpoint);
     220        if (pos > 0 && !npos) {
     221            /* gap in the partition list? */
     222            if (curr_part_no - prev_part_no > 1) {
     223                if (prev_part_no == 0) {
     224                    sprintf(tmp, " Gap prior to %s.", device);
     225                    log_it(tmp);
     226                    strcat(flaws_str, tmp);
     227                    res++;
     228                } else if (curr_part_no > 5
     229                           || (curr_part_no <= 4 && prev_part_no > 0)) {
     230                    sprintf(tmp, " Gap between %ss%d and %d.", drive,
     231                            prev_part_no, curr_part_no);
     232                    log_it(tmp);
     233                    strcat(flaws_str, tmp);
     234                    res++;
     235                }
     236            }
     237            /* GPT allows more than 4 primary partitions */
     238            part_table_fmt = which_partition_format(drive);
     239            /* no spare primary partitions to help accommodate the logical(s)? */
     240            if ((curr_part_no >= 5 && prev_part_no == 4)
     241                && (strcmp(part_table_fmt, "MBR") == 0)) {
     242                sprintf(tmp, " Partition %ss4 is occupied.", drive);
     243                log_it(tmp);
     244                strcat(flaws_str, tmp);
     245                res++;
     246            }
     247            /* does partition /dev/adXsY exist more than once in the mountlist? */
     248            for (i = 0, mountpoint_copies = 0, device_copies = 0;
     249                 i < mountlist->entries; i++) {
     250                if (!strcmp(device, mountlist->el[i].device)) {
     251                    device_copies++;
     252                }
     253            }
     254            if (device_copies > 1) {
     255                sprintf(tmp, " %s %s's.", number_to_text(device_copies),
     256                        device);
     257                if (!strstr(flaws_str, tmp)) {
     258                    log_it(tmp);
     259                    strcat(flaws_str, tmp);
     260                    res++;
     261                }
     262            }
     263            /* silly partition size? */
     264            if (mountlist->el[pos].size < 8192
     265                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
     266                sprintf(tmp, " %s is tiny!", device);
     267                log_it(tmp);
     268                strcat(flaws_str, tmp);
     269                res++;
     270            }
     271            /* mountpoint should begin with / unless it is swap, lvm or raid */
     272            if (strcmp(mountlist->el[pos].mountpoint, "swap")
     273                && strcmp(mountlist->el[pos].mountpoint, "lvm")
     274                && strcmp(mountlist->el[pos].mountpoint, "raid")
     275                && strcmp(mountlist->el[pos].mountpoint, "image")
     276                && strcmp(mountlist->el[pos].mountpoint, "none")
     277                && mountlist->el[pos].mountpoint[0] != '/') {
     278                sprintf(tmp, " %s has a weird mountpoint.", device);
     279                log_it(tmp);
     280                strcat(flaws_str, tmp);
     281                res++;
     282            }
     283            /* is format sensible? */
     284            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
     285                sprintf(tmp, " %s has unsupported format.", device);
     286                log_it(tmp);
     287                strcat(flaws_str, tmp);
     288                res++;
     289            }
     290        } else {
     291            /* Check subpartitions */
     292            for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
     293                sprintf(device, "%ss%d%c", drive, curr_part_no, cur_sp_no);
     294                pos = find_device_in_mountlist(mountlist, device);
     295                if (pos < 0) {
     296                    continue;
     297                }
     298                strcpy(mountpoint, mountlist->el[pos].mountpoint);
     299                /* is it too big? */
     300                if (curr_part_no > 'h') {
     301                    sprintf(tmp, " Can only have up to 'h' in disklabel.");
     302                    log_it(tmp);
     303                    strcat(flaws_str, tmp);
     304                    res++;
     305                }
     306                /* does partition /dev/adXsYZ exist more than once in the mountlist? */
     307                for (i = 0, mountpoint_copies = 0, device_copies = 0;
     308                     i < mountlist->entries; i++) {
     309                    if (!strcmp(device, mountlist->el[i].device)) {
     310                        device_copies++;
     311                    }
     312                }
     313                if (device_copies > 1) {
     314                    sprintf(tmp, " %s %s's.",
     315                            number_to_text(device_copies), device);
     316                    if (!strstr(flaws_str, tmp)) {
     317                        log_it(tmp);
     318                        strcat(flaws_str, tmp);
     319                        res++;
     320                    }
     321                }
     322                /* silly partition size? */
     323                if (mountlist->el[pos].size < 8192
     324                    && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
     325                    sprintf(tmp, " %s is tiny!", device);
     326                    log_it(tmp);
     327                    strcat(flaws_str, tmp);
     328                    res++;
     329                }
     330                /* mountpoint should begin with / unless it is swap, lvm or raid */
     331                if (strcmp(mountlist->el[pos].mountpoint, "swap")
     332                    && strcmp(mountlist->el[pos].mountpoint, "lvm")
     333                    && strcmp(mountlist->el[pos].mountpoint, "raid")
     334                    && strcmp(mountlist->el[pos].mountpoint, "image")
     335                    && strcmp(mountlist->el[pos].mountpoint, "none")
     336                    && mountlist->el[pos].mountpoint[0] != '/') {
     337                    sprintf(tmp, " %s has a weird mountpoint.", device);
     338                    log_it(tmp);
     339                    strcat(flaws_str, tmp);
     340                    res++;
     341                }
     342                /* is format sensible? */
     343                if (!is_this_a_valid_disk_format
     344                    (mountlist->el[pos].format)) {
     345                    sprintf(tmp, " %s has unsupported format.", device);
     346                    log_it(tmp);
     347                    strcat(flaws_str, tmp);
     348                    res++;
     349                }
     350                amount_allocated += mountlist->el[pos].size / 1024;
     351                prev_sp_no = cur_sp_no;
     352            }
     353        }
     354
     355        /* OK, continue with main loop */
     356        amount_allocated += mountlist->el[pos].size / 1024;
     357        prev_part_no = curr_part_no;
     358    }
     359
     360    /* Over-allocated the disk? Unallocated space on disk? */
     361    if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high?
     362    {
     363        sprintf(tmp, " %ld MB over-allocated on %s.",
     364                amount_allocated - physical_drive_size, drive);
     365        log_it(tmp);
     366        strcat(flaws_str, tmp);
     367        res++;
     368    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
     369        sprintf(tmp, " %ld MB unallocated on %s.",
     370                physical_drive_size - amount_allocated, drive);
     371        log_it(tmp), strcat(flaws_str, tmp);
     372    }
     373    if (res) {
     374        return (FALSE);
     375    } else {
     376        return (TRUE);
     377    }
    410378}
    411379
     
    414382{
    415383
    416     /*@ int **************************************************************/
    417   int prev_part_no = 0;
     384    /*@ int ************************************************************* */
     385    int prev_part_no = 0;
    418386    int curr_part_no = 0;
    419387    int pos = 0;
     
    423391    int i = 0;
    424392
    425     /*@ buffers *********************************************************/
    426   char *tmp;
     393    /*@ buffers ******************************************************** */
     394    char *tmp;
    427395    char *device;
    428396    char *mountpoint;
    429397
    430     /*@ long ************************************************************/
    431   long physical_drive_size = 0;
     398    /*@ long *********************************************************** */
     399    long physical_drive_size = 0;
    432400    long amount_allocated = 0;
    433401
    434     /*@ pointers ********************************************************/
     402    /*@ pointers ******************************************************* */
    435403    char *part_table_fmt;
    436404
    437     /*@ initialize ******************************************************/
    438   assert_string_is_neither_NULL_nor_zerolength(drive);
    439   assert(mountlist!=NULL);
    440   assert(flaws_str!=NULL);
    441 
    442   malloc_string(tmp);
    443   malloc_string(device);
    444   malloc_string(mountpoint);
    445   flaws_str[0] = '\0';
    446   prev_part_no = 0;
    447   tmp[0] = '\0';
    448 
    449 
    450   physical_drive_size = get_phys_size_of_drive (drive);
    451 
    452   if (physical_drive_size < 0)
    453     {
    454       sprintf (tmp, " %s does not exist.", drive);
    455       strcat (flaws_str, tmp);
    456       res++;
    457       log_msg(1, tmp);
    458       goto endoffunc;
    459     }
    460   else
    461     {
    462       sprintf (tmp, "%s is %ld MB", drive, physical_drive_size);
    463       log_it (tmp);
    464     }
    465 
    466   for (curr_part_no = 1; curr_part_no < 99; curr_part_no++)
    467     {
    468       sprintf (device, "%s%d", drive, curr_part_no);
    469       pos = find_device_in_mountlist (mountlist, device);
    470       if (pos < 0)
    471     {
    472       continue;
    473     }
    474       if (physical_drive_size < 0)
    475         {
    476           sprintf(tmp, " %s refers to non-existent hardware.", device);
    477           strcat (flaws_str, tmp);
    478           res++;
    479           continue;
    480         }
    481       strcpy (mountpoint, mountlist->el[pos].mountpoint);
    482       /* gap in the partition list? */
    483       if (curr_part_no - prev_part_no > 1)
    484     {
    485       if (prev_part_no == 0)
    486         {
    487           sprintf (tmp, " Gap prior to %s.", device);
    488           log_it (tmp);
    489           strcat (flaws_str, tmp);
    490           res++;
    491         }
    492       else if (curr_part_no > 5
    493            || (curr_part_no <= 4 && prev_part_no > 0))
    494         {
    495           sprintf (tmp, " Gap between %s%d and %d.", drive, prev_part_no,
    496                curr_part_no);
    497           log_it (tmp);
    498           strcat (flaws_str, tmp);
    499           res++;
    500         }
    501     }
    502       /* GPT allows more than 4 primary partitions */
    503       part_table_fmt = which_partition_format(drive);
    504       /* no spare primary partitions to help accommodate the logical(s)? */
    505       if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt,"MBR") == 0))
    506     {
    507       sprintf (tmp, " Partition %s4 is occupied.", drive);
    508       log_it (tmp);
    509       strcat (flaws_str, tmp);
    510       res++;
    511     }
    512       /* does partition /dev/hdNX exist more than once in the mountlist? */
    513       for (i = 0, mountpoint_copies = 0, device_copies = 0;
    514        i < mountlist->entries; i++)
    515     {
    516       if (!strcmp (device, mountlist->el[i].device))
    517         {
    518           device_copies++;
    519         }
    520     }
    521       if (device_copies > 1)
    522     {
    523       sprintf (tmp, " %s %s's.", number_to_text (device_copies), device);
    524       if (!strstr (flaws_str, tmp))
    525         {
    526           log_it (tmp);
    527           strcat (flaws_str, tmp);
    528           res++;
    529         }
    530     }
    531       /* silly partition size? */
    532       if (mountlist->el[pos].size < 8192
    533       && strcmp (mountlist->el[pos].mountpoint, "lvm"))
    534     {
    535       sprintf (tmp, " %s is tiny!", device);
    536       log_it (tmp);
    537       strcat (flaws_str, tmp);
    538       res++;
    539     }
    540       /* mountpoint should begin with / unless it is swap, lvm or raid */
    541       if (strcmp (mountlist->el[pos].mountpoint, "swap")
    542       && strcmp (mountlist->el[pos].mountpoint, "lvm")
    543       && strcmp (mountlist->el[pos].mountpoint, "raid")
    544       && strcmp (mountlist->el[pos].mountpoint, "image")
    545       && mountlist->el[pos].mountpoint[0] != '/')
    546     {
    547       sprintf (tmp, " %s has a weird mountpoint.", device);
    548       log_it (tmp);
    549       strcat (flaws_str, tmp);
    550       res++;
    551     }
    552       /* is format sensible? */
    553       if (!is_this_a_valid_disk_format (mountlist->el[pos].format))
    554     {
    555       sprintf (tmp, " %s has unsupported format.", device);
    556       log_it (tmp);
    557       strcat (flaws_str, tmp);
    558       res++;
    559     }
    560       /* OK, continue with main loop */
    561       amount_allocated += mountlist->el[pos].size / 1024;
    562       prev_part_no = curr_part_no;
    563     }
    564 
    565   /* Over-allocated the disk? Unallocated space on disk? */
    566   if (amount_allocated > physical_drive_size + 1)
    567     {
    568       sprintf (tmp, " %ld MB over-allocated on %s.",
    569            amount_allocated - physical_drive_size, drive);
    570       log_it (tmp);
    571       strcat (flaws_str, tmp);
    572       res++;
    573     }
    574   else if (amount_allocated < physical_drive_size - 1)
    575     {               /* NOT AN ERROR, JUST A WARNING :-) */
    576       sprintf (tmp, " %ld MB unallocated on %s.",
    577            physical_drive_size - amount_allocated, drive);
    578       log_it (tmp), strcat (flaws_str, tmp);
    579     }
    580 
    581 endoffunc:
    582   paranoid_free(tmp);
    583   paranoid_free(device);
    584   paranoid_free(mountpoint);
    585  
    586   if (res)
    587     {
    588       return (FALSE);
    589     }
    590   else
    591     {
    592       return (TRUE);
    593     }
     405    /*@ initialize ***************************************************** */
     406    assert_string_is_neither_NULL_nor_zerolength(drive);
     407    assert(mountlist != NULL);
     408    assert(flaws_str != NULL);
     409
     410    malloc_string(tmp);
     411    malloc_string(device);
     412    malloc_string(mountpoint);
     413    flaws_str[0] = '\0';
     414    prev_part_no = 0;
     415    tmp[0] = '\0';
     416
     417
     418    physical_drive_size = get_phys_size_of_drive(drive);
     419
     420    if (physical_drive_size < 0) {
     421        sprintf(tmp, " %s does not exist.", drive);
     422        strcat(flaws_str, tmp);
     423        res++;
     424        log_msg(1, tmp);
     425        goto endoffunc;
     426    } else {
     427        sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
     428        log_it(tmp);
     429    }
     430
     431    for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
     432        sprintf(device, "%s%d", drive, curr_part_no);
     433        pos = find_device_in_mountlist(mountlist, device);
     434        if (pos < 0) {
     435            continue;
     436        }
     437        if (physical_drive_size < 0) {
     438            sprintf(tmp, " %s refers to non-existent hardware.", device);
     439            strcat(flaws_str, tmp);
     440            res++;
     441            continue;
     442        }
     443        strcpy(mountpoint, mountlist->el[pos].mountpoint);
     444        /* gap in the partition list? */
     445        if (curr_part_no - prev_part_no > 1) {
     446            if (prev_part_no == 0) {
     447                sprintf(tmp, " Gap prior to %s.", device);
     448                log_it(tmp);
     449                strcat(flaws_str, tmp);
     450                res++;
     451            } else if (curr_part_no > 5
     452                       || (curr_part_no <= 4 && prev_part_no > 0)) {
     453                sprintf(tmp, " Gap between %s%d and %d.", drive,
     454                        prev_part_no, curr_part_no);
     455                log_it(tmp);
     456                strcat(flaws_str, tmp);
     457                res++;
     458            }
     459        }
     460        /* GPT allows more than 4 primary partitions */
     461        part_table_fmt = which_partition_format(drive);
     462        /* no spare primary partitions to help accommodate the logical(s)? */
     463        if ((curr_part_no >= 5 && prev_part_no == 4)
     464            && (strcmp(part_table_fmt, "MBR") == 0)) {
     465            sprintf(tmp, " Partition %s4 is occupied.", drive);
     466            log_it(tmp);
     467            strcat(flaws_str, tmp);
     468            res++;
     469        }
     470        /* does partition /dev/hdNX exist more than once in the mountlist? */
     471        for (i = 0, mountpoint_copies = 0, device_copies = 0;
     472             i < mountlist->entries; i++) {
     473            if (!strcmp(device, mountlist->el[i].device)) {
     474                device_copies++;
     475            }
     476        }
     477        if (device_copies > 1) {
     478            sprintf(tmp, " %s %s's.", number_to_text(device_copies),
     479                    device);
     480            if (!strstr(flaws_str, tmp)) {
     481                log_it(tmp);
     482                strcat(flaws_str, tmp);
     483                res++;
     484            }
     485        }
     486        /* silly partition size? */
     487        if (mountlist->el[pos].size < 8192
     488            && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
     489            sprintf(tmp, " %s is tiny!", device);
     490            log_it(tmp);
     491            strcat(flaws_str, tmp);
     492            res++;
     493        }
     494        /* mountpoint should begin with / unless it is swap, lvm or raid */
     495        if (strcmp(mountlist->el[pos].mountpoint, "swap")
     496            && strcmp(mountlist->el[pos].mountpoint, "lvm")
     497            && strcmp(mountlist->el[pos].mountpoint, "raid")
     498            && strcmp(mountlist->el[pos].mountpoint, "image")
     499            && mountlist->el[pos].mountpoint[0] != '/') {
     500            sprintf(tmp, " %s has a weird mountpoint.", device);
     501            log_it(tmp);
     502            strcat(flaws_str, tmp);
     503            res++;
     504        }
     505        /* is format sensible? */
     506        if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
     507            sprintf(tmp, " %s has unsupported format.", device);
     508            log_it(tmp);
     509            strcat(flaws_str, tmp);
     510            res++;
     511        }
     512        /* OK, continue with main loop */
     513        amount_allocated += mountlist->el[pos].size / 1024;
     514        prev_part_no = curr_part_no;
     515    }
     516
     517    /* Over-allocated the disk? Unallocated space on disk? */
     518    if (amount_allocated > physical_drive_size + 1) {
     519        sprintf(tmp, " %ld MB over-allocated on %s.",
     520                amount_allocated - physical_drive_size, drive);
     521        log_it(tmp);
     522        strcat(flaws_str, tmp);
     523        res++;
     524    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
     525        sprintf(tmp, " %ld MB unallocated on %s.",
     526                physical_drive_size - amount_allocated, drive);
     527        log_it(tmp), strcat(flaws_str, tmp);
     528    }
     529
     530  endoffunc:
     531    paranoid_free(tmp);
     532    paranoid_free(device);
     533    paranoid_free(mountpoint);
     534
     535    if (res) {
     536        return (FALSE);
     537    } else {
     538        return (TRUE);
     539    }
    594540}
    595541#endif
     
    608554 */
    609555int
    610 evaluate_mountlist (struct mountlist_itself *mountlist, char *flaws_str_A,
    611             char *flaws_str_B, char *flaws_str_C)
    612 {
    613 
    614     /*@ buffer ************************************************************/
    615     struct list_of_disks *drivelist;
     556evaluate_mountlist(struct mountlist_itself *mountlist, char *flaws_str_A,
     557                   char *flaws_str_B, char *flaws_str_C)
     558{
     559
     560    /*@ buffer *********************************************************** */
     561    struct list_of_disks *drivelist;
    616562    char *tmp;
    617563    char *flaws_str;
    618564
    619     /*@ int ***************************************************************/
     565    /*@ int ************************************************************** */
    620566    int i = 0;
    621567    int res = 0;
    622568
    623     /*@ initialize ********************************************************/
    624 
    625   drivelist = malloc(sizeof(struct list_of_disks));
    626   malloc_string(tmp);
    627   malloc_string(flaws_str);
    628   assert(mountlist!=NULL);
    629   assert(flaws_str_A!=NULL);
    630   assert(flaws_str_B!=NULL);
    631   assert(flaws_str_C!=NULL);
    632   flaws_str[0] = '\0';
    633 
    634   make_list_of_drives_in_mountlist (mountlist, drivelist);
    635 
    636   log_it ("Evaluating mountlist...");
    637 
    638  for (i = 0; i < drivelist->entries; i++)
    639     {
    640       if (strstr (drivelist->el[i].device, DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE))
    641     {
    642       sprintf (tmp, " Not evaluating %s (I don't know how yet)",
    643            drivelist->el[i].device);
    644       log_it (tmp);
    645       tmp[0] = '\0';
    646     }
    647       else
    648     {
    649       if (!evaluate_drive_within_mountlist
    650           (mountlist, drivelist->el[i].device, tmp))
    651         {
    652           res++;
    653         }
    654     }
    655       strcat (flaws_str, tmp);
    656     }
    657   res += look_for_duplicate_mountpoints (mountlist, flaws_str);
     569    /*@ initialize ******************************************************* */
     570
     571    drivelist = malloc(sizeof(struct list_of_disks));
     572    malloc_string(tmp);
     573    malloc_string(flaws_str);
     574    assert(mountlist != NULL);
     575    assert(flaws_str_A != NULL);
     576    assert(flaws_str_B != NULL);
     577    assert(flaws_str_C != NULL);
     578    flaws_str[0] = '\0';
     579
     580    make_list_of_drives_in_mountlist(mountlist, drivelist);
     581
     582    log_it("Evaluating mountlist...");
     583
     584    for (i = 0; i < drivelist->entries; i++) {
     585        if (strstr
     586            (drivelist->el[i].device,
     587             DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) {
     588            sprintf(tmp, " Not evaluating %s (I don't know how yet)",
     589                    drivelist->el[i].device);
     590            log_it(tmp);
     591            tmp[0] = '\0';
     592        } else {
     593            if (!evaluate_drive_within_mountlist
     594                (mountlist, drivelist->el[i].device, tmp)) {
     595                res++;
     596            }
     597        }
     598        strcat(flaws_str, tmp);
     599    }
     600    res += look_for_duplicate_mountpoints(mountlist, flaws_str);
    658601/*  res+=look_for_weird_formats(mountlist,flaws_str); .. not necessary, now that we can check to see
    659602 which formarts are actually _supported_ by the kernel */
    660   /* log_it(flaws_str); */
    661   return (spread_flaws_across_three_lines
    662       (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res));
     603    /* log_it(flaws_str); */
     604    return (spread_flaws_across_three_lines
     605            (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res));
    663606}
    664607
     
    672615 */
    673616int
    674 find_device_in_mountlist (struct mountlist_itself *mountlist, char *device)
    675 {
    676 
    677     /*@ int ***************************************************************/
    678   int i = 0;
    679   char*tmp;
    680   char*flaws_str;
    681  
    682   malloc_string(tmp);
    683   malloc_string(flaws_str);
    684  
    685   assert(mountlist!=NULL);
    686   assert_string_is_neither_NULL_nor_zerolength(device);
    687   for (i = 0;
    688        i < mountlist->entries
    689        && strcmp (mountlist->el[i].device, device) != 0; i++);
    690  
    691   paranoid_free(tmp);
    692   paranoid_free(flaws_str);
    693 
    694   if (i == mountlist->entries)
    695     {
    696       return (-1);
    697     }
    698   else
    699     {
    700       return (i);
    701     }
     617find_device_in_mountlist(struct mountlist_itself *mountlist, char *device)
     618{
     619
     620    /*@ int ************************************************************** */
     621    int i = 0;
     622    char *tmp;
     623    char *flaws_str;
     624
     625    malloc_string(tmp);
     626    malloc_string(flaws_str);
     627
     628    assert(mountlist != NULL);
     629    assert_string_is_neither_NULL_nor_zerolength(device);
     630    for (i = 0;
     631         i < mountlist->entries
     632         && strcmp(mountlist->el[i].device, device) != 0; i++);
     633
     634    paranoid_free(tmp);
     635    paranoid_free(flaws_str);
     636
     637    if (i == mountlist->entries) {
     638        return (-1);
     639    } else {
     640        return (i);
     641    }
    702642}
    703643
     
    713653 */
    714654int
    715 look_for_duplicate_mountpoints (struct mountlist_itself *mountlist,
    716                 char *flaws_str)
    717 {
    718 
    719     /*@ int **************************************************************/
    720   int res = 0;
     655look_for_duplicate_mountpoints(struct mountlist_itself *mountlist,
     656                               char *flaws_str)
     657{
     658
     659    /*@ int ************************************************************* */
     660    int res = 0;
    721661    int currline = 0;
    722662    int i = 0;
     
    724664    int last_copy = 0;
    725665
    726     /*@ buffetr **********************************************************/
    727   char *curr_mountpoint;
     666    /*@ buffetr ********************************************************* */
     667    char *curr_mountpoint;
    728668    char *tmp;
    729669
    730   malloc_string(curr_mountpoint);
    731   malloc_string(tmp);
    732   assert(mountlist!=NULL);
    733   assert(flaws_str!=NULL);
    734   for (currline = 0; currline < mountlist->entries; currline++)
    735     {
    736       strcpy (curr_mountpoint, mountlist->el[currline].mountpoint);
    737       for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries; i++)
    738     {
    739       if (!strcmp (mountlist->el[i].mountpoint, curr_mountpoint)
    740           && strcmp (mountlist->el[i].mountpoint, "lvm")
    741           && strcmp (mountlist->el[i].mountpoint, "swap"))
    742         {
    743           last_copy = i;
    744           copies++;
    745         }
    746     }
    747       if (copies > 1 && last_copy == currline
    748       && strcmp (curr_mountpoint, "raid"))
    749     {
    750       sprintf (tmp, " %s %s's.", number_to_text (copies),
    751            curr_mountpoint);
    752       strcat (flaws_str, tmp);
    753       log_it (tmp);
    754       res++;
    755     }
    756     }
    757   paranoid_free(curr_mountpoint);
    758   paranoid_free(tmp);
    759   return (res);
     670    malloc_string(curr_mountpoint);
     671    malloc_string(tmp);
     672    assert(mountlist != NULL);
     673    assert(flaws_str != NULL);
     674    for (currline = 0; currline < mountlist->entries; currline++) {
     675        strcpy(curr_mountpoint, mountlist->el[currline].mountpoint);
     676        for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries;
     677             i++) {
     678            if (!strcmp(mountlist->el[i].mountpoint, curr_mountpoint)
     679                && strcmp(mountlist->el[i].mountpoint, "lvm")
     680                && strcmp(mountlist->el[i].mountpoint, "swap")) {
     681                last_copy = i;
     682                copies++;
     683            }
     684        }
     685        if (copies > 1 && last_copy == currline
     686            && strcmp(curr_mountpoint, "raid")) {
     687            sprintf(tmp, " %s %s's.", number_to_text(copies),
     688                    curr_mountpoint);
     689            strcat(flaws_str, tmp);
     690            log_it(tmp);
     691            res++;
     692        }
     693    }
     694    paranoid_free(curr_mountpoint);
     695    paranoid_free(tmp);
     696    return (res);
    760697}
    761698
     
    768705 */
    769706int
    770 look_for_weird_formats (struct mountlist_itself *mountlist, char *flaws_str)
    771 {
    772 
    773     /*@ int **************************************************************/
    774   int i = 0;
     707look_for_weird_formats(struct mountlist_itself *mountlist, char *flaws_str)
     708{
     709
     710    /*@ int ************************************************************* */
     711    int i = 0;
    775712    int res = 0;
    776713
    777     /*@ buffers **********************************************************/
    778   char *tmp;
     714    /*@ buffers ********************************************************* */
     715    char *tmp;
    779716    char *format_sz;
    780717
    781   malloc_string(tmp);
    782   malloc_string(format_sz);
    783  
    784   assert(mountlist!=NULL);
    785   assert(flaws_str!=NULL);
    786 
    787   for (i = 0; i < mountlist->entries; i++)
    788     {
    789       sprintf (format_sz, " %s ", mountlist->el[i].format);
    790       if (!strstr
    791       (SANE_FORMATS, format_sz)
    792         && strcmp (mountlist->el[i].mountpoint, "image") != 0)
    793     {
    794       sprintf (tmp, " %s has unknown format.", mountlist->el[i].device);
    795       log_it (tmp);
    796       strcat (flaws_str, tmp);
    797       res++;
    798     }
    799       else
    800     if ((!strcmp (mountlist->el[i].format, "swap")
    801          && strcmp (mountlist->el[i].mountpoint, "swap") && strcmp (mountlist->el[i].mountpoint, "none"))
    802         || (strcmp (mountlist->el[i].format, "swap")
    803         && !strcmp (mountlist->el[i].mountpoint, "swap") && !strcmp (mountlist->el[i].mountpoint, "none")))
    804     {
    805       sprintf (tmp, " %s is half-swap.", mountlist->el[i].device);
    806       log_it (tmp);
    807       strcat (flaws_str, tmp);
    808       res++;
    809     }
    810     }
    811   paranoid_free(tmp);
    812   paranoid_free(format_sz);
    813   return (res);
     718    malloc_string(tmp);
     719    malloc_string(format_sz);
     720
     721    assert(mountlist != NULL);
     722    assert(flaws_str != NULL);
     723
     724    for (i = 0; i < mountlist->entries; i++) {
     725        sprintf(format_sz, " %s ", mountlist->el[i].format);
     726        if (!strstr(SANE_FORMATS, format_sz)
     727            && strcmp(mountlist->el[i].mountpoint, "image") != 0) {
     728            sprintf(tmp, " %s has unknown format.",
     729                    mountlist->el[i].device);
     730            log_it(tmp);
     731            strcat(flaws_str, tmp);
     732            res++;
     733        } else if ((!strcmp(mountlist->el[i].format, "swap")
     734                    && strcmp(mountlist->el[i].mountpoint, "swap")
     735                    && strcmp(mountlist->el[i].mountpoint, "none"))
     736                   || (strcmp(mountlist->el[i].format, "swap")
     737                       && !strcmp(mountlist->el[i].mountpoint, "swap")
     738                       && !strcmp(mountlist->el[i].mountpoint, "none"))) {
     739            sprintf(tmp, " %s is half-swap.", mountlist->el[i].device);
     740            log_it(tmp);
     741            strcat(flaws_str, tmp);
     742            res++;
     743        }
     744    }
     745    paranoid_free(tmp);
     746    paranoid_free(format_sz);
     747    return (res);
    814748}
    815749
     
    823757 */
    824758int
    825 make_list_of_drives_in_mountlist (struct mountlist_itself *mountlist,
    826              struct list_of_disks *drivelist)
    827 {
    828 
    829         /*@ int **************************************************************/
    830   int lino;
    831   int noof_drives;
    832   int j;
    833 
    834         /*@ buffers **********************************************************/
    835   char *drive;
    836   char *tmp;
    837 
    838   long long size;
    839 
    840   malloc_string(drive);
    841   malloc_string(tmp);
    842   assert(mountlist!=NULL);
    843   assert(drivelist!=NULL);
    844   log_it ("Making list of drives");
    845   for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++)
    846     {
    847      
    848       strcpy (drive, mountlist->el[lino].device);
    849       if (!strncmp (drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)))
    850     {
    851       sprintf (tmp,
    852            "Not putting %s in list of drives: it's a virtual drive",
    853            drive);
    854       log_msg (8, tmp);
    855       continue;
    856     }
    857 
    858       size=mountlist->el[lino].size;
    859       if ( size == 0 )
    860         {
    861           sprintf (tmp,
    862                    "Not putting %s in list of drives: it has zero size (maybe an LVM volume)",
    863                    drive);
    864           log_msg (8, tmp);
    865           continue;
    866         }
     759make_list_of_drives_in_mountlist(struct mountlist_itself *mountlist,
     760                                 struct list_of_disks *drivelist)
     761{
     762
     763    /*@ int ************************************************************* */
     764    int lino;
     765    int noof_drives;
     766    int j;
     767
     768    /*@ buffers ********************************************************* */
     769    char *drive;
     770    char *tmp;
     771
     772    long long size;
     773
     774    malloc_string(drive);
     775    malloc_string(tmp);
     776    assert(mountlist != NULL);
     777    assert(drivelist != NULL);
     778    log_it("Making list of drives");
     779    for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) {
     780
     781        strcpy(drive, mountlist->el[lino].device);
     782        if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
     783            sprintf(tmp,
     784                    "Not putting %s in list of drives: it's a virtual drive",
     785                    drive);
     786            log_msg(8, tmp);
     787            continue;
     788        }
     789
     790        size = mountlist->el[lino].size;
     791        if (size == 0) {
     792            sprintf(tmp,
     793                    "Not putting %s in list of drives: it has zero size (maybe an LVM volume)",
     794                    drive);
     795            log_msg(8, tmp);
     796            continue;
     797        }
    867798
    868799/*
     
    877808*/
    878809
    879       sprintf (tmp,
    880            "Putting %s with size %lli in list of drives",
    881            drive, size);
    882       log_msg (8, tmp);
    883 
    884       (void) truncate_to_drive_name (drive);
    885       for (j = 0; j < noof_drives && strcmp (drivelist->el[j].device, drive) != 0; j++)
    886     continue;
    887       if (j == noof_drives)
    888     {
    889       strcpy (drivelist->el[noof_drives++].device, drive);
    890     }
    891     }
    892   drivelist->entries = noof_drives;
    893   log_msg (8, "Made list of drives");
    894   paranoid_free(drive);
    895   paranoid_free(tmp);
    896 
    897   return (noof_drives);
     810        sprintf(tmp,
     811                "Putting %s with size %lli in list of drives",
     812                drive, size);
     813        log_msg(8, tmp);
     814
     815        (void) truncate_to_drive_name(drive);
     816        for (j = 0;
     817             j < noof_drives
     818             && strcmp(drivelist->el[j].device, drive) != 0; j++)
     819            continue;
     820        if (j == noof_drives) {
     821            strcpy(drivelist->el[noof_drives++].device, drive);
     822        }
     823    }
     824    drivelist->entries = noof_drives;
     825    log_msg(8, "Made list of drives");
     826    paranoid_free(drive);
     827    paranoid_free(tmp);
     828
     829    return (noof_drives);
    898830}
    899831
     
    910842 * @param raidlist The raidlist to examine.
    911843 */
    912 void
    913 make_list_of_unallocated_raid_partitions (struct mountlist_itself
    914                       *output_list,
    915                       struct mountlist_itself *mountlist,
    916                       struct raidlist_itself *raidlist)
    917 {
    918 
    919     /*@ int **************************************************************/
    920   int items = 0;
     844void make_list_of_unallocated_raid_partitions(struct mountlist_itself
     845                                              *output_list,
     846                                              struct mountlist_itself
     847                                              *mountlist,
     848                                              struct raidlist_itself
     849                                              *raidlist)
     850{
     851
     852    /*@ int ************************************************************* */
     853    int items = 0;
    921854    int i = 0;
    922855    int used_by = 0;
    923856
    924     /*@ buffers **********************************************************/
    925   char *tmp;
    926 
    927   malloc_string(tmp);
    928   assert(output_list!=NULL);
    929   assert(mountlist!=NULL);
    930   assert(raidlist!=NULL);
    931   log_it ("MLOURP -- starting");
    932   items = 0;
    933 
    934 
    935   for (i = 0; i < mountlist->entries; i++)
    936     {
    937       if (strstr (mountlist->el[i].mountpoint, "raid"))
    938     {
    939       used_by =
    940         which_raid_device_is_using_this_partition (raidlist,
    941                                mountlist->el[i].
    942                                device);
    943       if (used_by < 0)
    944         {
    945           memcpy ((void *) &output_list->el[items++],
    946               (void *) &mountlist->el[i],
    947               sizeof (struct mountlist_line));
    948           sprintf (tmp,
    949                "%s is available; user may choose to add it to raid device",
    950                output_list->el[items - 1].device);
    951           log_it (tmp);
    952         }
    953     }
    954     }
    955   output_list->entries = items;
    956   log_it ("MLUORP -- ending");
    957   paranoid_free(tmp);
     857    /*@ buffers ********************************************************* */
     858    char *tmp;
     859
     860    malloc_string(tmp);
     861    assert(output_list != NULL);
     862    assert(mountlist != NULL);
     863    assert(raidlist != NULL);
     864    log_it("MLOURP -- starting");
     865    items = 0;
     866
     867
     868    for (i = 0; i < mountlist->entries; i++) {
     869        if (strstr(mountlist->el[i].mountpoint, "raid")) {
     870            used_by =
     871                which_raid_device_is_using_this_partition(raidlist,
     872                                                          mountlist->el[i].
     873                                                          device);
     874            if (used_by < 0) {
     875                memcpy((void *) &output_list->el[items++],
     876                       (void *) &mountlist->el[i],
     877                       sizeof(struct mountlist_line));
     878                sprintf(tmp,
     879                        "%s is available; user may choose to add it to raid device",
     880                        output_list->el[items - 1].device);
     881                log_it(tmp);
     882            }
     883        }
     884    }
     885    output_list->entries = items;
     886    log_it("MLUORP -- ending");
     887    paranoid_free(tmp);
    958888}
    959889
     
    969899 */
    970900long long
    971 size_of_specific_device_in_mountlist (struct mountlist_itself *mountlist, char *device)
    972 {
    973     /*@ int ***************************************************************/
    974   int i = 0;
    975 
    976 
    977   assert(mountlist!=NULL);
    978   assert_string_is_neither_NULL_nor_zerolength(device);
    979 
    980   for (i = 0;
    981        i < mountlist->entries && strcmp (mountlist->el[i].device, device);
    982        i++);
    983   if (i == mountlist->entries)
    984     {
    985       return (-1);
    986     }
    987   else
    988     {
    989       return (mountlist->el[i].size);
    990     }
     901size_of_specific_device_in_mountlist(struct mountlist_itself *mountlist,
     902                                     char *device)
     903{
     904    /*@ int ************************************************************** */
     905    int i = 0;
     906
     907
     908    assert(mountlist != NULL);
     909    assert_string_is_neither_NULL_nor_zerolength(device);
     910
     911    for (i = 0;
     912         i < mountlist->entries && strcmp(mountlist->el[i].device, device);
     913         i++);
     914    if (i == mountlist->entries) {
     915        return (-1);
     916    } else {
     917        return (mountlist->el[i].size);
     918    }
    991919}
    992920
     
    1004932 * @return 0 for success, 1 for failure.
    1005933 */
    1006 int
    1007 load_mountlist( struct mountlist_itself *mountlist, char *fname)
    1008 {
    1009   FILE *fin;
    1010   /* malloc ***/
    1011   char *incoming;
    1012   char *siz;
    1013   char *tmp;
    1014   char*p;
    1015 
    1016   int items;
    1017   int j;
    1018 
    1019   assert(mountlist!=NULL);
    1020   assert_string_is_neither_NULL_nor_zerolength(fname);
    1021   malloc_string(incoming);
    1022   malloc_string(siz);
    1023   malloc_string(tmp);
    1024   if ( !( fin = fopen( fname, "r" ) ) )
    1025     {
    1026       log_it( "Unable to open mountlist - '%s'", fname );
    1027       log_to_screen( "Cannot open mountlist" );
    1028       paranoid_free(incoming);
    1029       paranoid_free(siz);
    1030       paranoid_free(tmp);
    1031       return( 1 );
    1032     }
    1033   items = 0;
    1034   (void) fgets( incoming, MAX_STR_LEN - 1, fin );
    1035   log_it( "Loading mountlist..." );
    1036   while( !feof( fin ) )
    1037     {
     934int load_mountlist(struct mountlist_itself *mountlist, char *fname)
     935{
     936    FILE *fin;
     937    /* malloc ** */
     938    char *incoming;
     939    char *siz;
     940    char *tmp;
     941    char *p;
     942
     943    int items;
     944    int j;
     945
     946    assert(mountlist != NULL);
     947    assert_string_is_neither_NULL_nor_zerolength(fname);
     948    malloc_string(incoming);
     949    malloc_string(siz);
     950    malloc_string(tmp);
     951    if (!(fin = fopen(fname, "r"))) {
     952        log_it("Unable to open mountlist - '%s'", fname);
     953        log_to_screen("Cannot open mountlist");
     954        paranoid_free(incoming);
     955        paranoid_free(siz);
     956        paranoid_free(tmp);
     957        return (1);
     958    }
     959    items = 0;
     960    (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     961    log_it("Loading mountlist...");
     962    while (!feof(fin)) {
    1038963#if linux
    1039       sscanf( incoming,
    1040           "%s %s %s %s %s",
    1041           mountlist->el[items].device,
    1042           mountlist->el[items].mountpoint,
    1043           mountlist->el[items].format,
    1044           siz,
    1045           mountlist->el[items].label);
     964        sscanf(incoming,
     965               "%s %s %s %s %s",
     966               mountlist->el[items].device,
     967               mountlist->el[items].mountpoint,
     968               mountlist->el[items].format,
     969               siz, mountlist->el[items].label);
    1046970#elif __FreeBSD__
    1047       sscanf (incoming,
    1048           "%s %s %s %s",
    1049           mountlist->el[items].device,
    1050           mountlist->el[items].mountpoint,
    1051           mountlist->el[items].format,
    1052           siz);
    1053       strcpy (mountlist->el[items].label, "");
     971        sscanf(incoming,
     972               "%s %s %s %s",
     973               mountlist->el[items].device,
     974               mountlist->el[items].mountpoint,
     975               mountlist->el[items].format, siz);
     976        strcpy(mountlist->el[items].label, "");
    1054977#endif
    1055978
    1056       if (
    1057         !strcmp(mountlist->el[items].device,"/proc") ||
    1058         !strcmp(mountlist->el[items].device, "proc") ||
    1059         !strcmp(mountlist->el[items].device,"/sys") ||
    1060         !strcmp(mountlist->el[items].device, "sys") ||
    1061         !strcmp(mountlist->el[items].device,"/devpts") ||
    1062     !strcmp(mountlist->el[items].device, "devpts")
    1063       )
    1064         {
    1065       log_msg(1, "Ignoring %s in mountlist - not loading that line :) ", mountlist->el[items].device);
    1066           (void) fgets( incoming, MAX_STR_LEN - 1,fin );
    1067       continue;
    1068     }
    1069       mountlist->el[items].size = atoll( siz );
    1070       if ( mountlist->el[items].device[0] != '\0' && mountlist->el[items].device[0] != '#' )
    1071     {
    1072       if ( items >= ARBITRARY_MAXIMUM )
    1073         {
    1074           log_to_screen( "Too many lines in mountlist.. ABORTING" );
    1075           finish( 1 );
    1076         }
    1077       for( j=0; j < items && strcmp( mountlist->el[j].device, mountlist->el[items].device ); j++);
    1078       if (j < items)
    1079         {
    1080           strcat( mountlist->el[items].device, "_dup" );
    1081           sprintf( tmp, "Duplicate entry in mountlist - renaming to %s",mountlist->el[items].device );
    1082           log_it( tmp );
    1083         }
    1084     strcpy(tmp, mountlist->el[items].device);
    1085     if (strstr(tmp, "/dev/md/"))
    1086       {
    1087         log_it("format_device() --- Contracting %s", tmp);
    1088         p = strrchr(tmp, '/');
    1089         if (p) { *p = *(p+1); *(p+1) = *(p+2); *(p+2) = *(p+3); }
    1090         log_it("It was %s; it is now %s", mountlist->el[items].device, tmp);
    1091         strcpy(mountlist->el[items].device, tmp);
    1092       }
    1093 
    1094       sprintf( tmp,
    1095            "%s %s %s %lld %s",
    1096            mountlist->el[items].device,
    1097            mountlist->el[items].mountpoint,
    1098            mountlist->el[items].format,
    1099            mountlist->el[items].size,
    1100            mountlist->el[items].label);
    1101 
    1102       log_it( tmp );
    1103       items++;
    1104     }
    1105       (void) fgets( incoming, MAX_STR_LEN - 1,fin );
    1106     }
    1107   paranoid_fclose( fin );
    1108   mountlist->entries = items;
    1109 
    1110   log_it( "Mountlist loaded successfully." );
    1111   sprintf( tmp, "%d entries in mountlist", items );
    1112   log_it( tmp );
    1113   paranoid_free(incoming);
    1114   paranoid_free(siz);
    1115   paranoid_free(tmp);
    1116   return( 0 );
     979        if (!strcmp(mountlist->el[items].device, "/proc") ||
     980            !strcmp(mountlist->el[items].device, "proc") ||
     981            !strcmp(mountlist->el[items].device, "/sys") ||
     982            !strcmp(mountlist->el[items].device, "sys") ||
     983            !strcmp(mountlist->el[items].device, "/devpts") ||
     984            !strcmp(mountlist->el[items].device, "devpts")
     985            ) {
     986            log_msg(1,
     987                    "Ignoring %s in mountlist - not loading that line :) ",
     988                    mountlist->el[items].device);
     989            (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     990            continue;
     991        }
     992        mountlist->el[items].size = atoll(siz);
     993        if (mountlist->el[items].device[0] != '\0'
     994            && mountlist->el[items].device[0] != '#') {
     995            if (items >= ARBITRARY_MAXIMUM) {
     996                log_to_screen("Too many lines in mountlist.. ABORTING");
     997                finish(1);
     998            }
     999            for (j = 0;
     1000                 j < items
     1001                 && strcmp(mountlist->el[j].device,
     1002                           mountlist->el[items].device); j++);
     1003            if (j < items) {
     1004                strcat(mountlist->el[items].device, "_dup");
     1005                sprintf(tmp,
     1006                        "Duplicate entry in mountlist - renaming to %s",
     1007                        mountlist->el[items].device);
     1008                log_it(tmp);
     1009            }
     1010            strcpy(tmp, mountlist->el[items].device);
     1011            if (strstr(tmp, "/dev/md/")) {
     1012                log_it("format_device() --- Contracting %s", tmp);
     1013                p = strrchr(tmp, '/');
     1014                if (p) {
     1015                    *p = *(p + 1);
     1016                    *(p + 1) = *(p + 2);
     1017                    *(p + 2) = *(p + 3);
     1018                }
     1019                log_it("It was %s; it is now %s",
     1020                       mountlist->el[items].device, tmp);
     1021                strcpy(mountlist->el[items].device, tmp);
     1022            }
     1023
     1024            sprintf(tmp,
     1025                    "%s %s %s %lld %s",
     1026                    mountlist->el[items].device,
     1027                    mountlist->el[items].mountpoint,
     1028                    mountlist->el[items].format,
     1029                    mountlist->el[items].size, mountlist->el[items].label);
     1030
     1031            log_it(tmp);
     1032            items++;
     1033        }
     1034        (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     1035    }
     1036    paranoid_fclose(fin);
     1037    mountlist->entries = items;
     1038
     1039    log_it("Mountlist loaded successfully.");
     1040    sprintf(tmp, "%d entries in mountlist", items);
     1041    log_it(tmp);
     1042    paranoid_free(incoming);
     1043    paranoid_free(siz);
     1044    paranoid_free(tmp);
     1045    return (0);
    11171046}
    11181047
     
    11261055 * @see load_mountlist
    11271056 */
    1128 int
    1129 save_mountlist_to_disk(struct mountlist_itself *mountlist, char *fname)
    1130 {
    1131   FILE *fout;
    1132   int i;
    1133 
    1134   assert(mountlist!=NULL);
    1135   assert_string_is_neither_NULL_nor_zerolength(fname);
    1136 
    1137   log_it("save_mountlist_to_disk() --- saving to %s", fname);
    1138   if (!(fout=fopen(fname,"w")))
    1139     {
    1140       log_OS_error("WMTD - Cannot openout mountlist");
    1141       return(1);
    1142     }
    1143   for( i = 0; i < mountlist->entries; i++)
    1144     {
    1145       fprintf(fout,
    1146           "%-15s %-15s %-15s %-15lld %-15s\n",mountlist->el[i].device,
    1147           mountlist->el[i].mountpoint,
    1148           mountlist->el[i].format,
    1149           mountlist->el[i].size,
    1150           mountlist->el[i].label);
    1151     }
    1152   paranoid_fclose(fout);
    1153   return(0);
     1057int save_mountlist_to_disk(struct mountlist_itself *mountlist, char *fname)
     1058{
     1059    FILE *fout;
     1060    int i;
     1061
     1062    assert(mountlist != NULL);
     1063    assert_string_is_neither_NULL_nor_zerolength(fname);
     1064
     1065    log_it("save_mountlist_to_disk() --- saving to %s", fname);
     1066    if (!(fout = fopen(fname, "w"))) {
     1067        log_OS_error("WMTD - Cannot openout mountlist");
     1068        return (1);
     1069    }
     1070    for (i = 0; i < mountlist->entries; i++) {
     1071        fprintf(fout,
     1072                "%-15s %-15s %-15s %-15lld %-15s\n",
     1073                mountlist->el[i].device, mountlist->el[i].mountpoint,
     1074                mountlist->el[i].format, mountlist->el[i].size,
     1075                mountlist->el[i].label);
     1076    }
     1077    paranoid_fclose(fout);
     1078    return (0);
    11541079}
    11551080
     
    11611086 * @param mountlist The mountlist to sort.
    11621087 */
    1163 void
    1164 sort_mountlist_by_device( struct mountlist_itself *mountlist)
    1165 {
    1166   int diff;
    1167   int lino = -999;
    1168 
    1169   assert(mountlist!=NULL);
    1170 
    1171   while (lino < mountlist->entries)
    1172     {
    1173       for(lino = 1; lino < mountlist->entries; lino++)
    1174     {
    1175       diff = strcmp_inc_numbers(mountlist->el[lino-1].device,mountlist->el[lino].device);
    1176       if (diff > 0)
    1177         {
    1178           swap_mountlist_entries( mountlist, lino - 1, lino);
    1179           break;
    1180         }
    1181     }
    1182     }
     1088void sort_mountlist_by_device(struct mountlist_itself *mountlist)
     1089{
     1090    int diff;
     1091    int lino = -999;
     1092
     1093    assert(mountlist != NULL);
     1094
     1095    while (lino < mountlist->entries) {
     1096        for (lino = 1; lino < mountlist->entries; lino++) {
     1097            diff =
     1098                strcmp_inc_numbers(mountlist->el[lino - 1].device,
     1099                                   mountlist->el[lino].device);
     1100            if (diff > 0) {
     1101                swap_mountlist_entries(mountlist, lino - 1, lino);
     1102                break;
     1103            }
     1104        }
     1105    }
    11831106}
    11841107
     
    11891112 * @param reverse If TRUE, then do a reverse sort.
    11901113 */
    1191 void 
    1192 sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist, bool reverse)
    1193 {
    1194   int diff;
    1195   int lino = -999;
    1196 
    1197   assert(mountlist!=NULL);
    1198 
    1199   while(lino < mountlist->entries)
    1200     {
    1201       for(lino = 1; lino < mountlist->entries; lino++)
    1202     {
    1203       diff = strcmp( mountlist->el[lino-1].mountpoint,mountlist->el[lino].mountpoint);
    1204       if ((diff >0 && !reverse) || ((diff <0 && reverse)))
    1205         {
    1206           swap_mountlist_entries(mountlist, lino - 1, lino);
    1207           break;
    1208         }
    1209     }
    1210     }
     1114void
     1115sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist,
     1116                             bool reverse)
     1117{
     1118    int diff;
     1119    int lino = -999;
     1120
     1121    assert(mountlist != NULL);
     1122
     1123    while (lino < mountlist->entries) {
     1124        for (lino = 1; lino < mountlist->entries; lino++) {
     1125            diff =
     1126                strcmp(mountlist->el[lino - 1].mountpoint,
     1127                       mountlist->el[lino].mountpoint);
     1128            if ((diff > 0 && !reverse) || ((diff < 0 && reverse))) {
     1129                swap_mountlist_entries(mountlist, lino - 1, lino);
     1130                break;
     1131            }
     1132        }
     1133    }
    12111134}
    12121135
     
    12181141 * @param b The index number of the second entry.
    12191142 */
    1220 void 
     1143void
    12211144swap_mountlist_entries(struct mountlist_itself *mountlist, int a, int b)
    12221145{
    1223   /*@ mallocs ****/
    1224   char device[64];
    1225   char mountpoint[256];
    1226   char format[64];
    1227 
    1228   long long size;
    1229 
    1230   assert(mountlist!=NULL);
    1231   assert(a>=0);
    1232   assert(b>=0);
    1233 
    1234   strcpy(device,                    mountlist->el[a].device);
    1235   strcpy(mountpoint,                mountlist->el[a].mountpoint);
    1236   strcpy(format,                    mountlist->el[a].format);
    1237 
    1238   size=                              mountlist->el[a].size;
    1239 
    1240   strcpy(mountlist->el[a].device,    mountlist->el[b].device);
    1241   strcpy(mountlist->el[a].mountpoint,mountlist->el[b].mountpoint);
    1242   strcpy(mountlist->el[a].format,    mountlist->el[b].format);
    1243 
    1244   mountlist->el[a].size=            mountlist->el[b].size;
    1245 
    1246   strcpy(mountlist->el[b].device,    device);
    1247   strcpy(mountlist->el[b].mountpoint,mountpoint);
    1248   strcpy(mountlist->el[b].format,    format);
    1249 
    1250   mountlist->el[b].size=            size;
     1146    /*@ mallocs *** */
     1147    char device[64];
     1148    char mountpoint[256];
     1149    char format[64];
     1150
     1151    long long size;
     1152
     1153    assert(mountlist != NULL);
     1154    assert(a >= 0);
     1155    assert(b >= 0);
     1156
     1157    strcpy(device, mountlist->el[a].device);
     1158    strcpy(mountpoint, mountlist->el[a].mountpoint);
     1159    strcpy(format, mountlist->el[a].format);
     1160
     1161    size = mountlist->el[a].size;
     1162
     1163    strcpy(mountlist->el[a].device, mountlist->el[b].device);
     1164    strcpy(mountlist->el[a].mountpoint, mountlist->el[b].mountpoint);
     1165    strcpy(mountlist->el[a].format, mountlist->el[b].format);
     1166
     1167    mountlist->el[a].size = mountlist->el[b].size;
     1168
     1169    strcpy(mountlist->el[b].device, device);
     1170    strcpy(mountlist->el[b].mountpoint, mountpoint);
     1171    strcpy(mountlist->el[b].format, format);
     1172
     1173    mountlist->el[b].size = size;
    12511174}
    12521175
Note: See TracChangeset for help on using the changeset viewer.