Changeset 2052 in MondoRescue for branches/2.2.8/mondo/src/common
- Timestamp:
- Oct 23, 2008, 2:55:59 PM (16 years ago)
- Location:
- branches/2.2.8/mondo/src/common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.8/mondo/src/common/libmondo-devices.c
r2050 r2052 1017 1017 log_msg(1, "Failed to get harddisk geometry, using old mode"); 1018 1018 } 1019 /*1020 if ((fd = open (drive, O_RDONLY)) != -1) {1021 if (ioctl (fd, HDIO_GETGEO, &hdgeo) != -1) {1022 close (fd);1023 log_msg (2, "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB", drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors, (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1024));1024 if ( hdgeo.cylinders && hdgeo.heads && hdgeo.sectors ) {1025 outvalB = ((long) (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1024));1026 }1027 }1028 close (fd);1029 */1030 1019 #endif 1031 1020 } … … 1042 1031 return (outvalC); 1043 1032 } 1044 1045 /* The old version */1046 #if 01047 long get_phys_size_of_drive(char *drive)1048 {1049 /*@ pointers **************************************************** */1050 #if linux1051 FILE *fin;1052 char *p;1053 char *q;1054 char *r;1055 /*@ buffers ***************************************************** */1056 char *tmp;1057 char *command;1058 1059 /*@ long ******************************************************** */1060 long outL;1061 long tempLa;1062 long tempLb;1063 long tempLc;1064 1065 #endif1066 1067 struct hd_geometry hdgeo;1068 int fd;1069 1070 #ifdef __FreeBSD__1071 off_t o;1072 1073 if ((fd = open(drive, O_RDONLY)) != -1) {1074 if (ioctl(fd, DIOCGMEDIASIZE, &o) != -1) {1075 close(fd);1076 return (long) (o / (off_t) (1024 * 1024));1077 }1078 close(fd);1079 }1080 log_msg(4, "drive = %s, error = %s", drive, strerror(errno));1081 fatal_error("GPSOD: Unable to get size of drive");1082 #else1083 1084 malloc_string(tmp);1085 malloc_string(command);1086 1087 if ((fd = open(drive, O_RDONLY)) != -1) {1088 if (ioctl(fd, HDIO_GETGEO, &hdgeo) != -1) {1089 close(fd);1090 log_msg(2,1091 "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB",1092 drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors,1093 (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 /1094 1024));1095 if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {1096 return ((long)1097 (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors /1098 2 / 1024));1099 }1100 }1101 close(fd);1102 }1103 1104 assert_string_is_neither_NULL_nor_zerolength(drive);1105 1106 sprintf(command,1107 "parted2fdisk -l %s | head -n4 | tr -s '\n' '\t' | tr -s ' ' '\t' | cut -f8,14,16",1108 drive);1109 strcpy(tmp, call_program_and_get_last_line_of_output(command));1110 if (tmp[0]) {1111 p = tmp;1112 q = strchr(p, ' ');1113 if (q) {1114 *(q++) = '\0';1115 r = strchr(q, ' ');1116 if (r) {1117 *(r++) = '\0';1118 tempLa = atol(p);1119 tempLb = atol(q);1120 tempLc = atol(r);1121 outL = tempLa * tempLb / 1024 * tempLc / 1024;1122 if (outL > 100) {1123 paranoid_free(tmp);1124 paranoid_free(command);1125 return (outL);1126 }1127 }1128 }1129 }1130 1131 /* try to grep for 'Drive xxxx: yyy MB' */1132 sprintf(command,1133 "parted2fdisk -l %s | grep MB | tr -s ' ' '\t' | cut -f3",1134 drive);1135 strcpy(tmp, call_program_and_get_last_line_of_output(command));1136 if (atol(tmp) > 0) {1137 paranoid_free(tmp);1138 paranoid_free(command);1139 return (atol(tmp));1140 }1141 1142 /* else, do it the old-fashioned way */1143 p = strrchr(drive, (int) '/');1144 if (p) {1145 strcpy(tmp, p + 1);1146 } else {1147 paranoid_free(tmp);1148 paranoid_free(command);1149 return (-1);1150 }1151 sprintf(command, "dmesg | grep %s 2> /dev/null", tmp);1152 if (!(fin = popen(command, "r"))) {1153 log_OS_error("Cannot popen dmesg command");1154 } else {1155 fgets(tmp, MAX_STR_LEN - 1, fin);1156 while (!feof(fin) && !strstr(tmp, "GB") && !strstr(tmp, "MB")) {1157 fgets(tmp, MAX_STR_LEN - 1, fin);1158 }1159 if (pclose(fin)) {1160 log_OS_error("Cannot pclose dmesg fin");1161 }1162 }1163 if (!(p = strstr(tmp, "GB")) && !(p = strstr(tmp, "MB"))) {1164 log_msg(3, "Cannot find %s's size: dmesg isn't helping either.",1165 drive);1166 paranoid_free(tmp);1167 paranoid_free(command);1168 return (-1);1169 }1170 for (; !isdigit(*(p - 1)); p--);1171 *p = '\0';1172 for (p--; isdigit(*(p - 1)); p--);1173 outL = atol(p);1174 if (outL <= 0) {1175 paranoid_free(tmp);1176 paranoid_free(command);1177 return (-1);1178 }1179 if (strstr(tmp, "GB")) {1180 outL = outL * 1024;1181 }1182 paranoid_free(tmp);1183 paranoid_free(command);1184 return (outL * 19 / 20);1185 #endif1186 }1187 #endif /* 0 */1188 1189 1190 1191 1192 1033 1193 1034 /** -
branches/2.2.8/mondo/src/common/libmondo-mountlist.c
r1909 r2052 1 /* libmondo-mountlist.csubroutines for handling mountlist1 /* subroutines for handling mountlist 2 2 $Id$ 3 4 5 6 08/017 - when evaluating mountlist, skip drive entirely if it does not exist8 9 07/1410 - always exclude /devpts, /proc, /sys from mountlist11 12 06/29/200413 - changed some char[] to *char14 - drivelist is struct now, not char[][]15 16 10/19/200317 - format_device() --- contract /dev/md/N to /dev/mdN to18 overcome devfs problems19 20 06/1121 - added support for 5th column in mountlist.txt, for labels22 23 05/0824 - added save_mountlist_to_disk() and load_mountlist()25 and misc other funcs from mondorestore.c26 27 05/0528 - added Joshua Oreman's FreeBSD patches29 30 04/2431 - added some assert()'s32 33 04/2334 - cleaned up evaluate_drive_within_mountlist() a bit35 36 01/15/200337 - added code for LVM (Brian Borgeson)38 39 10/19/200240 - added some comments41 42 07/24/200243 - created44 3 */ 45 4 … … 786 745 } 787 746 788 /*789 for (i = strlen (drive); isdigit (drive[i - 1]); i--);790 drive[i] = '\0';791 if (get_phys_size_of_drive (drive) <= 0 && drive[i - 1] == 'p')792 {793 i--;794 drive[i] = '\0';795 }796 for (j = 0; j < noof_drives && strcmp (drivelist[j], drive) != 0; j++);797 */798 799 747 sprintf(tmp, 800 748 "Putting %s with size %lli in list of drives", -
branches/2.2.8/mondo/src/common/libmondo-string.c
r1687 r2052 862 862 return partition; 863 863 } 864 /* then see if it's a dm style device */ 865 if (c && strncmp(c, "/dm-", 5) == 0) { 866 /* yup it's dm, return the full path */ 867 return partition; 868 } 864 869 865 870 for (i = strlen(partition); isdigit(partition[i - 1]); i--)
Note:
See TracChangeset
for help on using the changeset viewer.