Changeset 1125 in MondoRescue
- Timestamp:
- Feb 10, 2007, 12:38:20 AM (18 years ago)
- Location:
- branches/stable/mondo/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/libmondo-devices.c
r1122 r1125 316 316 { 317 317 /*@ buffers **************************************************** */ 318 char *program ;318 char *program = NULL; 319 319 char *incoming = NULL; 320 char *searchstr; 321 char *tmp = NULL; 320 char *searchstr = NULL; 322 321 323 322 /*@ ints ******************************************************* */ … … 335 334 malloc_string(incoming); 336 335 malloc_string(searchstr); 337 malloc_string(tmp);338 336 339 337 #ifdef __FreeBSD__ … … 342 340 mr_asprintf(&program, "ls %s >/dev/null 2>&1", drive, 343 341 build_partition_name(tmp, drive, partno)); 344 re turnsystem(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); 350 348 fin = popen(program, "r"); 351 349 if (!fin) { 352 350 log_it("program=%s", program); 353 351 log_OS_error("Cannot popen-in program"); 352 mr_free(program); 354 353 return (0); 355 354 } 355 mr_free(program); 356 356 357 (void) build_partition_name(searchstr, drive, partno); 357 358 strcat(searchstr, " "); … … 361 362 } 362 363 } 364 mr_free(incoming); 365 363 366 if (pclose(fin)) { 364 367 log_OS_error("Cannot pclose fin"); 365 368 } 366 mr_free(program);367 mr_free(incoming);368 369 mr_free(searchstr); 369 mr_free(tmp);370 370 return (res); 371 371 } 372 373 374 375 372 376 373 … … 384 381 { 385 382 /*@ buffers **************************************************** */ 386 char *command ;383 char *command = NULL; 387 384 388 385 /*@ end vars *************************************************** */ 389 int i;386 int ret; 390 387 391 388 assert_string_is_neither_NULL_nor_zerolength(dev); 392 389 assert_string_is_neither_NULL_nor_zerolength(str); 393 390 394 malloc_string(command); 395 sprintf(command, 391 mr_asprintf(&command, 396 392 "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 397 393 dev, str); 398 i= system(command);394 ret = system(command); 399 395 mr_free(command); 400 if ( i) {396 if (ret) { 401 397 return (FALSE); 402 398 } else { … … 404 400 } 405 401 } 402 406 403 407 404 /** … … 415 412 { 416 413 /*@ buffers **************************************************** */ 417 char *command ;414 char *command = NULL; 418 415 /*@ end vars *************************************************** */ 419 int i; 420 421 malloc_string(command); 422 sprintf(command, 416 int ret; 417 418 mr_asprintf(&command, 423 419 "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 424 420 dev, n, str); 425 i= system(command);421 ret = system(command); 426 422 mr_free(command); 427 if (i) { 423 424 if (ret) { 428 425 return (FALSE); 429 426 } else { … … 431 428 } 432 429 } 433 434 430 435 431 … … 448 444 /*@ int's ****************************************************** */ 449 445 int res; 450 char *dev ;446 char *dev = NULL; 451 447 452 448 /*@ end vars **************************************************** */ … … 482 478 } 483 479 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); 487 483 } 488 484 mr_free(dev); 489 return (res); 490 } 491 492 493 485 return(res); 486 } 494 487 495 488 … … 989 982 mr_msg(1, "Error getting size of %s: %s", drive, strerror(errno)); 990 983 #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; 1004 994 } else { 1005 995 mr_msg(1, … … 1041 1031 } 1042 1032 1043 /* The old version */1044 #if 01045 long get_phys_size_of_drive(char *drive)1046 {1047 /*@ pointers **************************************************** */1048 #if linux1049 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 #endif1064 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 #else1081 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 #endif1184 }1185 #endif /* 0 */1186 1187 1188 1189 1190 1033 1191 1034 /** … … 1197 1040 bool is_this_a_valid_disk_format(char *format) 1198 1041 { 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; 1209 1050 assert_string_is_neither_NULL_nor_zerolength(format); 1210 1051 1211 sprintf(format_sz, "%s ", format);1052 mr_asprintf(&format_sz, "%s ", format); 1212 1053 1213 1054 #ifdef __FreeBSD__ 1214 sprintf(command,1055 mr_asprintf(&command, 1215 1056 "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1216 1057 #else 1217 sprintf(command,1058 mr_asprintf(&command, 1218 1059 "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1219 1060 #endif 1220 1061 1221 1062 pin = popen(command, "r"); 1063 mr_free(command); 1064 1222 1065 if (!pin) { 1223 1066 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); 1228 1070 if (pclose(pin)) { 1229 1071 log_OS_error("Cannot pclose good formats"); 1230 1072 } 1231 1073 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 1233 1079 if (strstr(good_formats, format_sz)) { 1234 retval = 1;1080 retval = TRUE; 1235 1081 } 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 } 1241 1086 mr_free(format_sz); 1242 1087 return (retval); … … 1258 1103 1259 1104 /*@ 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; 1265 1110 1266 1111 #ifdef __FreeBSD__ … … 1272 1117 /*@ end vars **************************************************** */ 1273 1118 1274 malloc_string(incoming);1275 malloc_string(device_with_tab);1276 malloc_string(device_with_space);1277 malloc_string(tmp);1278 1119 assert(device_raw != NULL); 1279 1120 // assert_string_is_neither_NULL_nor_zerolength(device_raw); … … 1281 1122 mr_msg(1, "%s needs to have a '/' prefixed - I'll do it", 1282 1123 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); 1286 1127 } 1287 1128 mr_msg(1, "Is %s mounted?", tmp); … … 1289 1130 mr_msg(1, 1290 1131 "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); 1295 1137 1296 1138 if (!(fin = popen("mount", "r"))) { … … 1298 1140 return (FALSE); 1299 1141 } 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)) { 1302 1144 if (strstr(incoming, device_with_space) //> incoming 1303 1145 || strstr(incoming, device_with_tab)) // > incoming) 1304 1146 { 1305 1147 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); 1310 1153 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", 1312 1156 SWAPLIST_COMMAND, device_with_space); 1157 mr_free(device_with_space); 1158 1313 1159 mr_msg(4, "tmp (command) = '%s'", tmp); 1314 1160 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 } 1322 1164 mr_free(tmp); 1323 return (retval); 1324 } 1165 return (FALSE); 1166 } 1167 1325 1168 1326 1169 #ifdef __FreeBSD__ … … 1333 1176 char *make_vn(char *fname) 1334 1177 { 1335 char *device = (char *) malloc(MAX_STR_LEN);1336 char *mddevice = (char *) malloc(32);1178 char *device = NULL; 1179 char *mddevice = NULL; 1337 1180 char command[MAX_STR_LEN]; 1338 1181 int vndev = 2; -
branches/stable/mondo/src/mondorestore/mondo-restore.c
r1108 r1125 21 21 #include "mondo-rstr-tools-EXT.h" 22 22 #include "mr_mem.h" 23 #include "mr_msg.h" 23 24 24 25 extern void twenty_seconds_til_yikes(void); -
branches/stable/mondo/src/mondorestore/mondo-rstr-compare.c
r1108 r1125 9 9 #include "../common/libmondo.h" 10 10 //#include "../../config.h" 11 #include "mr_msg.h" 11 12 #include "mr-externs.h" 12 13 #include "mondo-rstr-compare.h" -
branches/stable/mondo/src/mondorestore/mondo-rstr-newt.c
r1124 r1125 4 4 5 5 #include "mr_mem.h" 6 #include "mr_msg.h" 6 7 7 8 extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored -
branches/stable/mondo/src/mondorestore/mondo-rstr-tools.c
r1124 r1125 13 13 #include "mondo-rstr-tools.h" 14 14 #include "mr_mem.h" 15 #include "mr_msg.h" 15 16 16 17 extern bool g_sigpipe_caught;
Note:
See TracChangeset
for help on using the changeset viewer.