Ignore:
Timestamp:
Oct 23, 2008, 2:55:59 PM (15 years ago)
Author:
Bruno Cornec
Message:

Adds support for dm devices in truncate_to_drive_name

File:
1 edited

Legend:

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

    r2050 r2052  
    10171017            log_msg(1, "Failed to get harddisk geometry, using old mode");
    10181018        }
    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  */
    10301019#endif
    10311020    }
     
    10421031    return (outvalC);
    10431032}
    1044 
    1045 /* The old version */
    1046 #if 0
    1047 long get_phys_size_of_drive(char *drive)
    1048 {
    1049     /*@ pointers **************************************************** */
    1050 #if linux
    1051     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 #endif
    1066 
    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 #else
    1083 
    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 #endif
    1186 }
    1187 #endif                          /* 0 */
    1188 
    1189 
    1190 
    1191 
    11921033
    11931034/**
Note: See TracChangeset for help on using the changeset viewer.