Ignore:
Timestamp:
Feb 10, 2007, 12:38:20 AM (17 years ago)
Author:
Bruno Cornec
Message:

Still linker fixes (grrr)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-devices.c

    r1122 r1125  
    316316{
    317317    /*@ buffers **************************************************** */
    318     char *program;
     318    char *program = NULL;
    319319    char *incoming = NULL;
    320     char *searchstr;
    321     char *tmp = NULL;
     320    char *searchstr = NULL;
    322321
    323322    /*@ ints ******************************************************* */
     
    335334    malloc_string(incoming);
    336335    malloc_string(searchstr);
    337     malloc_string(tmp);
    338336
    339337#ifdef __FreeBSD__
     
    342340    mr_asprintf(&program, "ls %s >/dev/null 2>&1", drive,
    343341            build_partition_name(tmp, drive, partno));
    344     return system(program);
    345 #else
    346     tmp[0] = '\0';
    347 #endif
    348 
    349     sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive);
     342    res = system(program);
     343    mr_free(program);
     344    return(res);
     345#endif
     346
     347    mr_asprintf(&program, "parted2fdisk -l %s 2> /dev/null", drive);
    350348    fin = popen(program, "r");
    351349    if (!fin) {
    352350        log_it("program=%s", program);
    353351        log_OS_error("Cannot popen-in program");
     352        mr_free(program);
    354353        return (0);
    355354    }
     355    mr_free(program);
     356
    356357    (void) build_partition_name(searchstr, drive, partno);
    357358    strcat(searchstr, " ");
     
    361362        }
    362363    }
     364    mr_free(incoming);
     365
    363366    if (pclose(fin)) {
    364367        log_OS_error("Cannot pclose fin");
    365368    }
    366     mr_free(program);
    367     mr_free(incoming);
    368369    mr_free(searchstr);
    369     mr_free(tmp);
    370370    return (res);
    371371}
    372 
    373 
    374 
    375372
    376373
     
    384381{
    385382    /*@ buffers **************************************************** */
    386     char *command;
     383    char *command = NULL;
    387384
    388385    /*@ end vars *************************************************** */
    389     int i;
     386    int ret;
    390387
    391388    assert_string_is_neither_NULL_nor_zerolength(dev);
    392389    assert_string_is_neither_NULL_nor_zerolength(str);
    393390
    394     malloc_string(command);
    395     sprintf(command,
     391    mr_asprintf(&command,
    396392            "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    397393            dev, str);
    398     i = system(command);
     394    ret = system(command);
    399395    mr_free(command);
    400     if (i) {
     396    if (ret) {
    401397        return (FALSE);
    402398    } else {
     
    404400    }
    405401}
     402
    406403
    407404/**
     
    415412{
    416413    /*@ buffers **************************************************** */
    417     char *command;
     414    char *command = NULL;
    418415    /*@ end vars *************************************************** */
    419     int i;
    420 
    421     malloc_string(command);
    422     sprintf(command,
     416    int ret;
     417
     418    mr_asprintf(&command,
    423419            "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    424420            dev, n, str);
    425     i = system(command);
     421    ret = system(command);
    426422    mr_free(command);
    427     if (i) {
     423
     424    if (ret) {
    428425        return (FALSE);
    429426    } else {
     
    431428    }
    432429}
    433 
    434430
    435431
     
    448444    /*@ int's  ****************************************************** */
    449445    int res;
    450     char *dev;
     446    char *dev = NULL;
    451447
    452448    /*@ end vars **************************************************** */
     
    482478    }
    483479    if (res) {
    484         mr_msg(1, "mount failed");
    485     } else {
    486         mr_msg(1, "mount succeeded with %s", dev);
     480        mr_msg(1, _("mount failed"));
     481    } else {
     482        mr_msg(1, _("mount succeeded with %s"), dev);
    487483    }
    488484    mr_free(dev);
    489     return (res);
    490 }
    491 
    492 
    493 
     485    return(res);
     486}
    494487
    495488
     
    989982        mr_msg(1, "Error getting size of %s: %s", drive, strerror(errno));
    990983#if linux
    991         fileid = open(drive, O_RDONLY);
    992         if (fileid) {
    993             if (ioctl(fileid, HDIO_GETGEO, &hdgeo) != -1) {
    994                 if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
    995                     cylindersleft = cylinders = hdgeo.cylinders;
    996                     cylindersize = hdgeo.heads * hdgeo.sectors / 2;
    997                     outvalA = cylindersize * cylinders / 1024;
    998                     mr_msg(2, "Got Harddisk geometry, C:%d, H:%d, S:%d",
    999                             hdgeo.cylinders, hdgeo.heads, hdgeo.sectors);
    1000                     gotgeo = 1;
    1001                 } else {
    1002                     mr_msg(1, "Harddisk geometry wrong");
    1003                 }
     984    fileid = open(drive, O_RDONLY);
     985    if (fileid) {
     986        if (ioctl(fileid, HDIO_GETGEO, &hdgeo) != -1) {
     987            if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
     988                cylindersleft = cylinders = hdgeo.cylinders;
     989                cylindersize = hdgeo.heads * hdgeo.sectors / 2;
     990                outvalA = cylindersize * cylinders / 1024;
     991                mr_msg(2, "Got Harddisk geometry, C:%d, H:%d, S:%d",
     992                        hdgeo.cylinders, hdgeo.heads, hdgeo.sectors);
     993                gotgeo = 1;
    1004994            } else {
    1005995                mr_msg(1,
     
    10411031}
    10421032
    1043 /* The old version */
    1044 #if 0
    1045 long get_phys_size_of_drive(char *drive)
    1046 {
    1047     /*@ pointers **************************************************** */
    1048 #if linux
    1049     FILE *fin;
    1050     char *p;
    1051     char *q;
    1052     char *r;
    1053     /*@ buffers ***************************************************** */
    1054     char *tmp;
    1055     char *command;
    1056 
    1057     /*@ long ******************************************************** */
    1058     long outL;
    1059     long tempLa;
    1060     long tempLb;
    1061     long tempLc;
    1062 
    1063 #endif
    1064 
    1065     struct hd_geometry hdgeo;
    1066     int fd;
    1067 
    1068 #ifdef __FreeBSD__
    1069     off_t o;
    1070 
    1071     if ((fd = open(drive, O_RDONLY)) != -1) {
    1072         if (ioctl(fd, DIOCGMEDIASIZE, &o) != -1) {
    1073             close(fd);
    1074             return (long) (o / (off_t) (1024 * 1024));
    1075         }
    1076         close(fd);
    1077     }
    1078     mr_msg(4, "drive = %s, error = %s", drive, strerror(errno));
    1079     fatal_error("GPSOD: Unable to get size of drive");
    1080 #else
    1081 
    1082     malloc_string(tmp);
    1083     malloc_string(command);
    1084 
    1085     if ((fd = open(drive, O_RDONLY)) != -1) {
    1086         if (ioctl(fd, HDIO_GETGEO, &hdgeo) != -1) {
    1087             close(fd);
    1088             mr_msg(2,
    1089                     "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB",
    1090                     drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors,
    1091                     (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 /
    1092                      1024));
    1093             if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
    1094                 return ((long)
    1095                         (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors /
    1096                          2 / 1024));
    1097             }
    1098         }
    1099         close(fd);
    1100     }
    1101 
    1102     assert_string_is_neither_NULL_nor_zerolength(drive);
    1103 
    1104     sprintf(command,
    1105             "parted2fdisk -l %s | head -n4 | tr -s '\n' '\t' | tr -s ' ' '\t' | cut -f8,14,16",
    1106             drive);
    1107     strcpy(tmp, call_program_and_get_last_line_of_output(command));
    1108     if (tmp[0]) {
    1109         p = tmp;
    1110         q = strchr(p, ' ');
    1111         if (q) {
    1112             *(q++) = '\0';
    1113             r = strchr(q, ' ');
    1114             if (r) {
    1115                 *(r++) = '\0';
    1116                 tempLa = atol(p);
    1117                 tempLb = atol(q);
    1118                 tempLc = atol(r);
    1119                 outL = tempLa * tempLb / 1024 * tempLc / 1024;
    1120                 if (outL > 100) {
    1121                     mr_free(tmp);
    1122                     mr_free(command);
    1123                     return (outL);
    1124                 }
    1125             }
    1126         }
    1127     }
    1128 
    1129     /* try to grep for 'Drive xxxx: yyy MB' */
    1130     sprintf(command,
    1131             "parted2fdisk -l %s | grep MB | tr -s ' ' '\t' | cut -f3",
    1132             drive);
    1133     strcpy(tmp, call_program_and_get_last_line_of_output(command));
    1134     if (atol(tmp) > 0) {
    1135         mr_free(tmp);
    1136         mr_free(command);
    1137         return (atol(tmp));
    1138     }
    1139 
    1140     /* else, do it the old-fashioned way */
    1141     p = strrchr(drive, (int) '/');
    1142     if (p) {
    1143         strcpy(tmp, p + 1);
    1144     } else {
    1145         mr_free(tmp);
    1146         mr_free(command);
    1147         return (-1);
    1148     }
    1149     sprintf(command, "dmesg | grep %s 2> /dev/null", tmp);
    1150     if (!(fin = popen(command, "r"))) {
    1151         log_OS_error("Cannot popen dmesg command");
    1152     } else {
    1153         fgets(tmp, MAX_STR_LEN - 1, fin);
    1154         while (!feof(fin) && !strstr(tmp, "GB") && !strstr(tmp, "MB")) {
    1155             fgets(tmp, MAX_STR_LEN - 1, fin);
    1156         }
    1157         if (pclose(fin)) {
    1158             log_OS_error("Cannot pclose dmesg fin");
    1159         }
    1160     }
    1161     if (!(p = strstr(tmp, "GB")) && !(p = strstr(tmp, "MB"))) {
    1162         mr_msg(3, "Cannot find %s's size: dmesg isn't helping either.",
    1163                 drive);
    1164         mr_free(tmp);
    1165         mr_free(command);
    1166         return (-1);
    1167     }
    1168     for (; !isdigit(*(p - 1)); p--);
    1169     *p = '\0';
    1170     for (p--; isdigit(*(p - 1)); p--);
    1171     outL = atol(p);
    1172     if (outL <= 0) {
    1173         mr_free(tmp);
    1174         mr_free(command);
    1175         return (-1);
    1176     }
    1177     if (strstr(tmp, "GB")) {
    1178         outL = outL * 1024;
    1179     }
    1180     mr_free(tmp);
    1181     mr_free(command);
    1182     return (outL * 19 / 20);
    1183 #endif
    1184 }
    1185 #endif                          /* 0 */
    1186 
    1187 
    1188 
    1189 
    11901033
    11911034/**
     
    11971040bool is_this_a_valid_disk_format(char *format)
    11981041{
    1199     char *good_formats;
    1200     char *command;
    1201     char *format_sz;
    1202 
    1203     FILE *pin;
    1204     int retval;
    1205     malloc_string(good_formats);
    1206     malloc_string(command);
    1207     malloc_string(format_sz);
    1208 
     1042    char *good_formats = NULL;
     1043    char *command = NULL;
     1044    char *tmp = NULL;
     1045    char *format_sz = NULL;
     1046
     1047    FILE *pin = NULL;
     1048    bool retval;
     1049    size_t n = 0;
    12091050    assert_string_is_neither_NULL_nor_zerolength(format);
    12101051
    1211     sprintf(format_sz, "%s ", format);
     1052    mr_asprintf(&format_sz, "%s ", format);
    12121053
    12131054#ifdef __FreeBSD__
    1214     sprintf(command,
     1055    mr_asprintf(&command,
    12151056            "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
    12161057#else
    1217     sprintf(command,
     1058    mr_asprintf(&command,
    12181059            "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
    12191060#endif
    12201061
    12211062    pin = popen(command, "r");
     1063    mr_free(command);
     1064
    12221065    if (!pin) {
    12231066        log_OS_error("Unable to read good formats");
    1224         retval = 0;
    1225     } else {
    1226         strcpy(good_formats, " ");
    1227         (void) fgets(good_formats + 1, MAX_STR_LEN, pin);
     1067        retval = FALSE;
     1068    } else {
     1069        mr_getline(&good_formats, &n , pin);
    12281070        if (pclose(pin)) {
    12291071            log_OS_error("Cannot pclose good formats");
    12301072        }
    12311073        strip_spaces(good_formats);
    1232         strcat(good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
     1074        // " ntfs 7 " -- um, cheating much? :)
     1075        mr_asprintf(&tmp, " %s swap lvm raid ntfs 7 ",good_formats);
     1076        mr_free(good_formats);
     1077        good_formats = tmp;
     1078
    12331079        if (strstr(good_formats, format_sz)) {
    1234             retval = 1;
     1080            retval = TRUE;
    12351081        } else {
    1236             retval = 0;
    1237         }
    1238     }
    1239     mr_free(good_formats);
    1240     mr_free(command);
     1082            retval = FALSE;
     1083        }
     1084        mr_free(good_formats);
     1085    }
    12411086    mr_free(format_sz);
    12421087    return (retval);
     
    12581103
    12591104    /*@ buffers ***************************************************** */
    1260     char *incoming;
    1261     char *device_with_tab;
    1262     char *device_with_space;
    1263     char *tmp;
    1264     int retval = 0;
     1105    char *incoming = NULL;
     1106    char *device_with_tab = NULL;
     1107    char *device_with_space = NULL;
     1108    char *tmp = NULL;
     1109    size_t n = 0;
    12651110
    12661111#ifdef __FreeBSD__
     
    12721117    /*@ end vars **************************************************** */
    12731118
    1274     malloc_string(incoming);
    1275     malloc_string(device_with_tab);
    1276     malloc_string(device_with_space);
    1277     malloc_string(tmp);
    12781119    assert(device_raw != NULL);
    12791120//  assert_string_is_neither_NULL_nor_zerolength(device_raw);
     
    12811122        mr_msg(1, "%s needs to have a '/' prefixed - I'll do it",
    12821123                device_raw);
    1283         sprintf(tmp, "/%s", device_raw);
    1284     } else {
    1285         strcpy(tmp, device_raw);
     1124        mr_asprintf(&tmp, "/%s", device_raw);
     1125    } else {
     1126        mr_asprintf(&tmp, device_raw);
    12861127    }
    12871128    mr_msg(1, "Is %s mounted?", tmp);
     
    12891130        mr_msg(1,
    12901131                "I don't know how the heck /proc made it into the mountlist. I'll ignore it.");
    1291         return (0);
    1292     }
    1293     sprintf(device_with_tab, "%s\t", tmp);
    1294     sprintf(device_with_space, "%s ", tmp);
     1132        return (FALSE);
     1133    }
     1134    mr_asprintf(&device_with_tab, "%s\t", tmp);
     1135    mr_asprintf(&device_with_space, "%s ", tmp);
     1136    mr_free(tmp);
    12951137
    12961138    if (!(fin = popen("mount", "r"))) {
     
    12981140        return (FALSE);
    12991141    }
    1300     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    1301          fgets(incoming, MAX_STR_LEN - 1, fin)) {
     1142    for (mr_getline(&incoming, &n, fin); !feof(fin);
     1143         mr_getline(&incoming, &n, fin)) {
    13021144        if (strstr(incoming, device_with_space) //> incoming
    13031145            || strstr(incoming, device_with_tab))   // > incoming)
    13041146        {
    13051147            paranoid_pclose(fin);
    1306             retval = 1;
    1307             goto end_of_func;
    1308         }
    1309     }
     1148            return(TRUE);
     1149        }
     1150    }
     1151    mr_free(incoming);
     1152    mr_free(device_with_tab);
    13101153    paranoid_pclose(fin);
    1311     sprintf(tmp, "%s | grep -E \"^%s\" > /dev/null 2> /dev/null",
     1154
     1155    mr_asprintf(&tmp, "%s | grep -E \"^%s\" > /dev/null 2> /dev/null",
    13121156            SWAPLIST_COMMAND, device_with_space);
     1157    mr_free(device_with_space);
     1158
    13131159    mr_msg(4, "tmp (command) = '%s'", tmp);
    13141160    if (!system(tmp)) {
    1315         retval = 1;
    1316         goto end_of_func;
    1317     }
    1318   end_of_func:
    1319     mr_free(incoming);
    1320     mr_free(device_with_tab);
    1321     mr_free(device_with_space);
     1161        mr_free(tmp);
     1162        return(TRUE);
     1163    }
    13221164    mr_free(tmp);
    1323     return (retval);
    1324 }
     1165    return (FALSE);
     1166}
     1167
    13251168
    13261169#ifdef __FreeBSD__
     
    13331176char *make_vn(char *fname)
    13341177{
    1335     char *device = (char *) malloc(MAX_STR_LEN);
    1336     char *mddevice = (char *) malloc(32);
     1178    char *device = NULL;
     1179    char *mddevice = NULL;
    13371180    char command[MAX_STR_LEN];
    13381181    int vndev = 2;
Note: See TracChangeset for help on using the changeset viewer.