[48] | 1 | /* $Id: libmondo-mountlist.c 900 2006-10-24 06:49:18Z bruno $
|
---|
| 2 | subroutines for handling mountlist
|
---|
[1] | 3 | */
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * @file
|
---|
| 7 | * Functions which manipulate the mountlist.
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | #include "my-stuff.h"
|
---|
| 11 | #include "mondostructures.h"
|
---|
| 12 | #include "libmondo-mountlist.h"
|
---|
| 13 | #include "libmondo-raid-EXT.h"
|
---|
| 14 | #include "libmondo-devices-EXT.h"
|
---|
| 15 | #include "libmondo-tools-EXT.h"
|
---|
| 16 | #include "libmondo-string-EXT.h"
|
---|
[507] | 17 | #include "newt-specific-EXT.h"
|
---|
[900] | 18 | #include "mr_mem.h"
|
---|
[1] | 19 |
|
---|
| 20 | /*@unused@*/
|
---|
[48] | 21 | //static char cvsid[] = "$Id: libmondo-mountlist.c 900 2006-10-24 06:49:18Z bruno $";
|
---|
[1] | 22 |
|
---|
| 23 | /**
|
---|
| 24 | * A global copy of @c bkpinfo, to aid in debugging. As the name implies, <em>don't use this</em>.
|
---|
| 25 | * @ingroup globalGroup
|
---|
| 26 | */
|
---|
| 27 | struct s_bkpinfo *g_bkpinfo_DONTUSETHIS = NULL;
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * @addtogroup mountlistGroup
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /**
|
---|
| 34 | * Evaluate a drive within the mountlist for flaws. For example, too many
|
---|
| 35 | * primary partitions, the first logical isn't 5, duplicate partitions,
|
---|
| 36 | * ovar-allocated or under-allocated, unsupported format, silly size, or
|
---|
| 37 | * silly mountpoint. Under FreeBSD, this checks the disklabel too, for the above-mentioned
|
---|
| 38 | * errors as well as too many BSD partitions (more than 'h').
|
---|
| 39 | * @param mountlist The mountlist to check.
|
---|
| 40 | * @param drive The drive to check (e.g. @c /dev/hda).
|
---|
| 41 | * @param flaws_str Where to put the found flaws (human-readable).
|
---|
| 42 | * @return The number of flaws found (0 for success).
|
---|
| 43 | * @see evaluate_mountlist
|
---|
| 44 | */
|
---|
[48] | 45 | int evaluate_drive_within_mountlist(struct mountlist_itself *mountlist,
|
---|
| 46 | char *drive, char *flaws_str)
|
---|
[1] | 47 | #ifdef __FreeBSD__
|
---|
| 48 | {
|
---|
| 49 | // FreeBSD-specific version of evaluate_drive_within_mountlist()
|
---|
[48] | 50 | /*@ int ************************************************************* */
|
---|
| 51 | int prev_part_no = 0;
|
---|
[1] | 52 | int curr_part_no = 0;
|
---|
| 53 | int pos = 0, npos = 0;
|
---|
| 54 | int res = 0;
|
---|
| 55 | int mountpoint_copies = 0;
|
---|
| 56 | int device_copies = 0;
|
---|
| 57 | int i = 0;
|
---|
| 58 | int cur_sp_no = 0;
|
---|
| 59 | int prev_sp_no = 0;
|
---|
| 60 | int foundsome = FALSE;
|
---|
| 61 |
|
---|
[48] | 62 | /*@ buffers ******************************************************** */
|
---|
[688] | 63 | char *tmp = NULL;
|
---|
| 64 | char *tmp1 = NULL;
|
---|
| 65 | char *device = NULL;
|
---|
[783] | 66 | char *ndevice = NULL;
|
---|
[48] | 67 | // BERLIOS : useless ? char *mountpoint;
|
---|
[1] | 68 |
|
---|
[48] | 69 | /*@ long *********************************************************** */
|
---|
| 70 | long physical_drive_size = 0;
|
---|
[1] | 71 | long amount_allocated = 0;
|
---|
| 72 |
|
---|
[48] | 73 | /*@ pointers ******************************************************* */
|
---|
[688] | 74 | char *part_table_fmt = NULL;
|
---|
[1] | 75 |
|
---|
[48] | 76 | /*@ initialize ***************************************************** */
|
---|
| 77 | prev_part_no = 0;
|
---|
| 78 | // BERLIOS: tmp[0] = '\0';
|
---|
[1] | 79 |
|
---|
| 80 |
|
---|
[48] | 81 | physical_drive_size = get_phys_size_of_drive(drive);
|
---|
[1] | 82 |
|
---|
[48] | 83 | if (physical_drive_size < 0) {
|
---|
[900] | 84 | mr_asprintf(&tmp, " %s does not exist.", drive);
|
---|
[688] | 85 | flaws_str = tmp;
|
---|
[48] | 86 | } else {
|
---|
[900] | 87 | mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
|
---|
[688] | 88 | flaws_str = NULL;
|
---|
[48] | 89 | }
|
---|
| 90 | log_it(tmp);
|
---|
[900] | 91 | mr_free(tmp);
|
---|
[1] | 92 |
|
---|
| 93 |
|
---|
[48] | 94 | /* check DD */
|
---|
| 95 | for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
|
---|
[900] | 96 | mr_asprintf(&device, "%s%c", drive, cur_sp_no);
|
---|
[48] | 97 | if (find_device_in_mountlist(mountlist, device) >= 0)
|
---|
| 98 | foundsome = TRUE;
|
---|
[900] | 99 | mr_free(device);
|
---|
[48] | 100 | }
|
---|
| 101 | if (foundsome) {
|
---|
| 102 | for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
|
---|
[900] | 103 | mr_asprintf(&device, "%s%c", drive, cur_sp_no);
|
---|
[48] | 104 | pos = find_device_in_mountlist(mountlist, device);
|
---|
| 105 | if (pos < 0) {
|
---|
| 106 | continue;
|
---|
| 107 | }
|
---|
[900] | 108 | // BERLIOS : useless ? mr_asprintf(&mountpoint, mountlist->el[pos].mountpoint);
|
---|
[48] | 109 | /* is it too big? */
|
---|
| 110 | if (curr_part_no > 'h') {
|
---|
[900] | 111 | mr_asprintf(&tmp, " Can only have up to 'h' in disklabel.");
|
---|
[48] | 112 | log_it(tmp);
|
---|
[688] | 113 | if (flaws_str) {
|
---|
[900] | 114 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 115 | } else {
|
---|
[900] | 116 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 117 | }
|
---|
[900] | 118 | mr_free(flaws_str);
|
---|
[688] | 119 | flaws_str = tmp1;
|
---|
[900] | 120 | mr_free(tmp);
|
---|
[48] | 121 | res++;
|
---|
| 122 | }
|
---|
| 123 | /* does partition /dev/adXsYZ exist more than once in the mountlist? */
|
---|
| 124 | for (i = 0, mountpoint_copies = 0, device_copies = 0;
|
---|
| 125 | i < mountlist->entries; i++) {
|
---|
| 126 | if (!strcmp(device, mountlist->el[i].device)) {
|
---|
| 127 | device_copies++;
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | if (device_copies > 1) {
|
---|
[900] | 131 | mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
|
---|
[59] | 132 | device);
|
---|
[48] | 133 | if (!strstr(flaws_str, tmp)) {
|
---|
| 134 | log_it(tmp);
|
---|
[688] | 135 | if (flaws_str) {
|
---|
[900] | 136 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 137 | } else {
|
---|
[900] | 138 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 139 | }
|
---|
[900] | 140 | mr_free(flaws_str);
|
---|
[688] | 141 | flaws_str = tmp1;
|
---|
[48] | 142 | res++;
|
---|
| 143 | }
|
---|
[900] | 144 | mr_free(tmp);
|
---|
[48] | 145 | }
|
---|
| 146 | /* silly partition size? */
|
---|
| 147 | if (mountlist->el[pos].size < 8192
|
---|
| 148 | && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
|
---|
[900] | 149 | mr_asprintf(&tmp, " %s is tiny!", device);
|
---|
[48] | 150 | log_it(tmp);
|
---|
[688] | 151 | if (flaws_str) {
|
---|
[900] | 152 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 153 | } else {
|
---|
[900] | 154 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 155 | }
|
---|
[900] | 156 | mr_free(flaws_str);
|
---|
[688] | 157 | flaws_str = tmp1;
|
---|
[900] | 158 | mr_free(tmp);
|
---|
[48] | 159 | res++;
|
---|
| 160 | }
|
---|
| 161 | /* mountpoint should begin with / unless it is swap, lvm or raid */
|
---|
| 162 | if (strcmp(mountlist->el[pos].mountpoint, "swap")
|
---|
| 163 | && strcmp(mountlist->el[pos].mountpoint, "lvm")
|
---|
| 164 | && strcmp(mountlist->el[pos].mountpoint, "raid")
|
---|
| 165 | && strcmp(mountlist->el[pos].mountpoint, "image")
|
---|
| 166 | && strcmp(mountlist->el[pos].mountpoint, "none")
|
---|
| 167 | && mountlist->el[pos].mountpoint[0] != '/') {
|
---|
[900] | 168 | mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
|
---|
[48] | 169 | log_it(tmp);
|
---|
[688] | 170 | if (flaws_str) {
|
---|
[900] | 171 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 172 | } else {
|
---|
[900] | 173 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 174 | }
|
---|
[900] | 175 | mr_free(flaws_str);
|
---|
[688] | 176 | flaws_str = tmp1;
|
---|
[900] | 177 | mr_free(tmp);
|
---|
[48] | 178 | res++;
|
---|
| 179 | }
|
---|
| 180 | /* is format sensible? */
|
---|
| 181 | if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
|
---|
[900] | 182 | mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
|
---|
[48] | 183 | log_it(tmp);
|
---|
[688] | 184 | if (flaws_str) {
|
---|
[900] | 185 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 186 | } else {
|
---|
[900] | 187 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 188 | }
|
---|
[900] | 189 | mr_free(flaws_str);
|
---|
[688] | 190 | flaws_str = tmp1;
|
---|
[900] | 191 | mr_free(tmp);
|
---|
[48] | 192 | res++;
|
---|
| 193 | }
|
---|
| 194 | amount_allocated += mountlist->el[pos].size / 1024;
|
---|
| 195 | prev_sp_no = cur_sp_no;
|
---|
[1] | 196 |
|
---|
[900] | 197 | mr_free(device);
|
---|
[48] | 198 | }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | npos = pos = 0;
|
---|
| 202 | for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
|
---|
[900] | 203 | mr_asprintf(&device, "%ss%d", drive, curr_part_no);
|
---|
[48] | 204 | pos = find_device_in_mountlist(mountlist, device);
|
---|
| 205 | npos = 0;
|
---|
| 206 | for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) {
|
---|
[900] | 207 | mr_asprintf(&ndevice, "%ss%d%c", device, curr_part_no, cur_sp_no);
|
---|
[783] | 208 | if (find_device_in_mountlist(mountlist, ndevice) >= 0)
|
---|
[48] | 209 | npos++;
|
---|
[900] | 210 | mr_free(ndevice);
|
---|
[48] | 211 | }
|
---|
[900] | 212 | mr_free(device);
|
---|
[48] | 213 |
|
---|
| 214 | if (((pos >= 0) || npos) && foundsome) {
|
---|
[900] | 215 | mr_asprintf(&tmp, " %s has both DD and PC-style partitions.", drive);
|
---|
[688] | 216 | if (flaws_str) {
|
---|
[900] | 217 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 218 | } else {
|
---|
[900] | 219 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 220 | }
|
---|
[900] | 221 | mr_free(flaws_str);
|
---|
[688] | 222 | flaws_str = tmp1;
|
---|
[900] | 223 | mr_free(tmp);
|
---|
[48] | 224 | return ++res; // fatal error
|
---|
| 225 | }
|
---|
[900] | 226 | // BERLIOS : useless ? mr_asprintf(&mountpoint, mountlist->el[pos].mountpoint);
|
---|
[48] | 227 | if (pos > 0 && !npos) {
|
---|
[900] | 228 | mr_asprintf(&device, "%ss%d", drive, curr_part_no);
|
---|
[48] | 229 | /* gap in the partition list? */
|
---|
| 230 | if (curr_part_no - prev_part_no > 1) {
|
---|
| 231 | if (prev_part_no == 0) {
|
---|
[900] | 232 | mr_asprintf(&tmp, " Gap prior to %s.", device);
|
---|
[48] | 233 | log_it(tmp);
|
---|
[688] | 234 | if (flaws_str) {
|
---|
[900] | 235 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 236 | } else {
|
---|
[900] | 237 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 238 | }
|
---|
[900] | 239 | mr_free(flaws_str);
|
---|
[688] | 240 | flaws_str = tmp1;
|
---|
[900] | 241 | mr_free(tmp);
|
---|
[48] | 242 | res++;
|
---|
| 243 | } else if (curr_part_no > 5
|
---|
| 244 | || (curr_part_no <= 4 && prev_part_no > 0)) {
|
---|
[900] | 245 | mr_asprintf(&tmp, " Gap between %ss%d and %d.", drive,
|
---|
[59] | 246 | prev_part_no, curr_part_no);
|
---|
[48] | 247 | log_it(tmp);
|
---|
[688] | 248 | if (flaws_str) {
|
---|
[900] | 249 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 250 | } else {
|
---|
[900] | 251 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 252 | }
|
---|
[900] | 253 | mr_free(flaws_str);
|
---|
[688] | 254 | flaws_str = tmp1;
|
---|
[900] | 255 | mr_free(tmp);
|
---|
[48] | 256 | res++;
|
---|
| 257 | }
|
---|
| 258 | }
|
---|
| 259 | /* GPT allows more than 4 primary partitions */
|
---|
| 260 | part_table_fmt = which_partition_format(drive);
|
---|
| 261 | /* no spare primary partitions to help accommodate the logical(s)? */
|
---|
| 262 | if ((curr_part_no >= 5 && prev_part_no == 4)
|
---|
| 263 | && (strcmp(part_table_fmt, "MBR") == 0)) {
|
---|
[900] | 264 | mr_asprintf(&tmp, " Partition %ss4 is occupied.", drive);
|
---|
[48] | 265 | log_it(tmp);
|
---|
[688] | 266 | if (flaws_str) {
|
---|
[900] | 267 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 268 | } else {
|
---|
[900] | 269 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 270 | }
|
---|
[900] | 271 | mr_free(flaws_str);
|
---|
[688] | 272 | flaws_str = tmp1;
|
---|
[900] | 273 | mr_free(tmp);
|
---|
[48] | 274 | res++;
|
---|
| 275 | }
|
---|
| 276 | /* does partition /dev/adXsY exist more than once in the mountlist? */
|
---|
| 277 | for (i = 0, mountpoint_copies = 0, device_copies = 0;
|
---|
| 278 | i < mountlist->entries; i++) {
|
---|
| 279 | if (!strcmp(device, mountlist->el[i].device)) {
|
---|
| 280 | device_copies++;
|
---|
| 281 | }
|
---|
| 282 | }
|
---|
| 283 | if (device_copies > 1) {
|
---|
[900] | 284 | mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
|
---|
[59] | 285 | device);
|
---|
[48] | 286 | if (!strstr(flaws_str, tmp)) {
|
---|
| 287 | log_it(tmp);
|
---|
[688] | 288 | if (flaws_str) {
|
---|
[900] | 289 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 290 | } else {
|
---|
[900] | 291 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 292 | }
|
---|
[900] | 293 | mr_free(flaws_str);
|
---|
[688] | 294 | flaws_str = tmp1;
|
---|
[48] | 295 | res++;
|
---|
| 296 | }
|
---|
[900] | 297 | mr_free(tmp);
|
---|
[48] | 298 | }
|
---|
| 299 | /* silly partition size? */
|
---|
| 300 | if (mountlist->el[pos].size < 8192
|
---|
| 301 | && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
|
---|
[900] | 302 | mr_asprintf(&tmp, " %s is tiny!", device);
|
---|
[48] | 303 | log_it(tmp);
|
---|
[688] | 304 | if (flaws_str) {
|
---|
[900] | 305 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 306 | } else {
|
---|
[900] | 307 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 308 | }
|
---|
[900] | 309 | mr_free(flaws_str);
|
---|
[688] | 310 | flaws_str = tmp1;
|
---|
[900] | 311 | mr_free(tmp);
|
---|
[48] | 312 | res++;
|
---|
| 313 | }
|
---|
| 314 | /* mountpoint should begin with / unless it is swap, lvm or raid */
|
---|
| 315 | if (strcmp(mountlist->el[pos].mountpoint, "swap")
|
---|
| 316 | && strcmp(mountlist->el[pos].mountpoint, "lvm")
|
---|
| 317 | && strcmp(mountlist->el[pos].mountpoint, "raid")
|
---|
| 318 | && strcmp(mountlist->el[pos].mountpoint, "image")
|
---|
| 319 | && strcmp(mountlist->el[pos].mountpoint, "none")
|
---|
| 320 | && mountlist->el[pos].mountpoint[0] != '/') {
|
---|
[900] | 321 | mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
|
---|
[48] | 322 | log_it(tmp);
|
---|
[688] | 323 | if (flaws_str) {
|
---|
[900] | 324 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 325 | } else {
|
---|
[900] | 326 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 327 | }
|
---|
[900] | 328 | mr_free(flaws_str);
|
---|
[688] | 329 | flaws_str = tmp1;
|
---|
[900] | 330 | mr_free(tmp);
|
---|
[48] | 331 | res++;
|
---|
| 332 | }
|
---|
| 333 | /* is format sensible? */
|
---|
| 334 | if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
|
---|
[900] | 335 | mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
|
---|
[48] | 336 | log_it(tmp);
|
---|
[688] | 337 | if (flaws_str) {
|
---|
[900] | 338 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 339 | } else {
|
---|
[900] | 340 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 341 | }
|
---|
[900] | 342 | mr_free(flaws_str);
|
---|
[688] | 343 | flaws_str = tmp1;
|
---|
[900] | 344 | mr_free(tmp);
|
---|
[48] | 345 | res++;
|
---|
| 346 | }
|
---|
[900] | 347 | mr_free(device);
|
---|
[48] | 348 | } else {
|
---|
| 349 | /* Check subpartitions */
|
---|
| 350 | for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
|
---|
[900] | 351 | mr_asprintf(&device, "%ss%d%c", drive, curr_part_no,
|
---|
[59] | 352 | cur_sp_no);
|
---|
[48] | 353 | pos = find_device_in_mountlist(mountlist, device);
|
---|
| 354 | if (pos < 0) {
|
---|
| 355 | continue;
|
---|
| 356 | }
|
---|
[900] | 357 | // BERLIOS : useless ? mr_asprintf(&mountpoint, mountlist->el[pos].mountpoint);
|
---|
[48] | 358 | /* is it too big? */
|
---|
| 359 | if (curr_part_no > 'h') {
|
---|
[900] | 360 | mr_asprintf(&tmp,
|
---|
[59] | 361 | " Can only have up to 'h' in disklabel.");
|
---|
[48] | 362 | log_it(tmp);
|
---|
[688] | 363 | if (flaws_str) {
|
---|
[900] | 364 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 365 | } else {
|
---|
[900] | 366 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 367 | }
|
---|
[900] | 368 | mr_free(flaws_str);
|
---|
[688] | 369 | flaws_str = tmp1;
|
---|
[900] | 370 | mr_free(tmp);
|
---|
[48] | 371 | res++;
|
---|
| 372 | }
|
---|
| 373 | /* does partition /dev/adXsYZ exist more than once in the mountlist? */
|
---|
| 374 | for (i = 0, mountpoint_copies = 0, device_copies = 0;
|
---|
| 375 | i < mountlist->entries; i++) {
|
---|
| 376 | if (!strcmp(device, mountlist->el[i].device)) {
|
---|
| 377 | device_copies++;
|
---|
| 378 | }
|
---|
| 379 | }
|
---|
| 380 | if (device_copies > 1) {
|
---|
[900] | 381 | mr_asprintf(&tmp, " %s %s's.",
|
---|
[59] | 382 | number_to_text(device_copies), device);
|
---|
[48] | 383 | if (!strstr(flaws_str, tmp)) {
|
---|
| 384 | log_it(tmp);
|
---|
[688] | 385 | if (flaws_str) {
|
---|
[900] | 386 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 387 | } else {
|
---|
[900] | 388 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 389 | }
|
---|
[900] | 390 | mr_free(flaws_str);
|
---|
[688] | 391 | flaws_str = tmp1;
|
---|
[48] | 392 | res++;
|
---|
| 393 | }
|
---|
[900] | 394 | mr_free(tmp);
|
---|
[48] | 395 | }
|
---|
| 396 | /* silly partition size? */
|
---|
| 397 | if (mountlist->el[pos].size < 8192
|
---|
| 398 | && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
|
---|
[900] | 399 | mr_asprintf(&tmp, " %s is tiny!", device);
|
---|
[48] | 400 | log_it(tmp);
|
---|
[688] | 401 | if (flaws_str) {
|
---|
[900] | 402 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 403 | } else {
|
---|
[900] | 404 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 405 | }
|
---|
[900] | 406 | mr_free(flaws_str);
|
---|
[688] | 407 | flaws_str = tmp1;
|
---|
[900] | 408 | mr_free(tmp);
|
---|
[48] | 409 | res++;
|
---|
| 410 | }
|
---|
| 411 | /* mountpoint should begin with / unless it is swap, lvm or raid */
|
---|
| 412 | if (strcmp(mountlist->el[pos].mountpoint, "swap")
|
---|
| 413 | && strcmp(mountlist->el[pos].mountpoint, "lvm")
|
---|
| 414 | && strcmp(mountlist->el[pos].mountpoint, "raid")
|
---|
| 415 | && strcmp(mountlist->el[pos].mountpoint, "image")
|
---|
| 416 | && strcmp(mountlist->el[pos].mountpoint, "none")
|
---|
| 417 | && mountlist->el[pos].mountpoint[0] != '/') {
|
---|
[900] | 418 | mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
|
---|
[48] | 419 | log_it(tmp);
|
---|
[688] | 420 | if (flaws_str) {
|
---|
[900] | 421 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 422 | } else {
|
---|
[900] | 423 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 424 | }
|
---|
[900] | 425 | mr_free(flaws_str);
|
---|
[688] | 426 | flaws_str = tmp1;
|
---|
[900] | 427 | mr_free(tmp);
|
---|
[48] | 428 | res++;
|
---|
| 429 | }
|
---|
| 430 | /* is format sensible? */
|
---|
| 431 | if (!is_this_a_valid_disk_format
|
---|
| 432 | (mountlist->el[pos].format)) {
|
---|
[900] | 433 | mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
|
---|
[48] | 434 | log_it(tmp);
|
---|
[688] | 435 | if (flaws_str) {
|
---|
[900] | 436 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 437 | } else {
|
---|
[900] | 438 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 439 | }
|
---|
[900] | 440 | mr_free(flaws_str);
|
---|
[688] | 441 | flaws_str = tmp1;
|
---|
[900] | 442 | mr_free(tmp);
|
---|
[48] | 443 | res++;
|
---|
| 444 | }
|
---|
| 445 | amount_allocated += mountlist->el[pos].size / 1024;
|
---|
| 446 | prev_sp_no = cur_sp_no;
|
---|
[900] | 447 | mr_free(device);
|
---|
[48] | 448 | }
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | /* OK, continue with main loop */
|
---|
| 452 | amount_allocated += mountlist->el[pos].size / 1024;
|
---|
| 453 | prev_part_no = curr_part_no;
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 | /* Over-allocated the disk? Unallocated space on disk? */
|
---|
| 457 | if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high?
|
---|
| 458 | {
|
---|
[900] | 459 | mr_asprintf(&tmp, " %ld MB over-allocated on %s.",
|
---|
[59] | 460 | amount_allocated - physical_drive_size, drive);
|
---|
[48] | 461 | log_it(tmp);
|
---|
[688] | 462 | if (flaws_str) {
|
---|
[900] | 463 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 464 | } else {
|
---|
[900] | 465 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 466 | }
|
---|
[900] | 467 | mr_free(flaws_str);
|
---|
[688] | 468 | flaws_str = tmp1;
|
---|
[900] | 469 | mr_free(tmp);
|
---|
[48] | 470 | res++;
|
---|
| 471 | } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */
|
---|
[900] | 472 | mr_asprintf(&tmp, " %ld MB unallocated on %s.",
|
---|
[59] | 473 | physical_drive_size - amount_allocated, drive);
|
---|
[48] | 474 | log_it(tmp);
|
---|
[688] | 475 | if (flaws_str) {
|
---|
[900] | 476 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 477 | } else {
|
---|
[900] | 478 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 479 | }
|
---|
[900] | 480 | mr_free(flaws_str);
|
---|
[688] | 481 | flaws_str = tmp1;
|
---|
[900] | 482 | mr_free(tmp);
|
---|
[48] | 483 | }
|
---|
| 484 | if (res) {
|
---|
| 485 | return (FALSE);
|
---|
| 486 | } else {
|
---|
| 487 | return (TRUE);
|
---|
| 488 | }
|
---|
[1] | 489 | }
|
---|
| 490 |
|
---|
| 491 | #else
|
---|
| 492 | // Linux-specific version of evaluate_drive_within_mountlist()
|
---|
| 493 | {
|
---|
| 494 |
|
---|
[48] | 495 | /*@ int ************************************************************* */
|
---|
| 496 | int prev_part_no = 0;
|
---|
[1] | 497 | int curr_part_no = 0;
|
---|
| 498 | int pos = 0;
|
---|
| 499 | int res = 0;
|
---|
| 500 | int mountpoint_copies = 0;
|
---|
| 501 | int device_copies = 0;
|
---|
| 502 | int i = 0;
|
---|
| 503 |
|
---|
[48] | 504 | /*@ buffers ******************************************************** */
|
---|
[783] | 505 | char *tmp = NULL;
|
---|
| 506 | char *tmp1 = NULL;
|
---|
| 507 | char *device = NULL;
|
---|
[1] | 508 |
|
---|
[48] | 509 | /*@ long *********************************************************** */
|
---|
[783] | 510 | long physical_drive_size = 0L;
|
---|
| 511 | long amount_allocated = 0L;
|
---|
[1] | 512 |
|
---|
[48] | 513 | /*@ pointers ******************************************************* */
|
---|
[783] | 514 | char *part_table_fmt = NULL;
|
---|
[1] | 515 |
|
---|
[48] | 516 | /*@ initialize ***************************************************** */
|
---|
| 517 | assert_string_is_neither_NULL_nor_zerolength(drive);
|
---|
| 518 | assert(mountlist != NULL);
|
---|
[688] | 519 | flaws_str = NULL;
|
---|
[1] | 520 |
|
---|
[48] | 521 | prev_part_no = 0;
|
---|
| 522 | // BERLIOS : useless ? tmp[0] = '\0';
|
---|
[1] | 523 |
|
---|
| 524 |
|
---|
[48] | 525 | physical_drive_size = get_phys_size_of_drive(drive);
|
---|
[1] | 526 |
|
---|
[48] | 527 | if (physical_drive_size < 0) {
|
---|
[900] | 528 | mr_asprintf(&tmp, " %s does not exist.", drive);
|
---|
[688] | 529 | if (flaws_str) {
|
---|
[900] | 530 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 531 | } else {
|
---|
[900] | 532 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 533 | }
|
---|
[900] | 534 | mr_free(flaws_str);
|
---|
[688] | 535 | flaws_str = tmp1;
|
---|
[48] | 536 | res++;
|
---|
| 537 | log_msg(1, tmp);
|
---|
[900] | 538 | mr_free(tmp);
|
---|
[59] | 539 | return (FALSE);
|
---|
[48] | 540 | } else {
|
---|
[900] | 541 | mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
|
---|
[48] | 542 | log_it(tmp);
|
---|
[900] | 543 | mr_free(tmp);
|
---|
[48] | 544 | }
|
---|
[1] | 545 |
|
---|
[48] | 546 | for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
|
---|
[900] | 547 | mr_asprintf(&device, "%s%d", drive, curr_part_no);
|
---|
[48] | 548 | pos = find_device_in_mountlist(mountlist, device);
|
---|
| 549 | if (pos < 0) {
|
---|
| 550 | continue;
|
---|
| 551 | }
|
---|
| 552 | if (physical_drive_size < 0) {
|
---|
[900] | 553 | mr_asprintf(&tmp, " %s refers to non-existent hardware.", device);
|
---|
[688] | 554 | if (flaws_str) {
|
---|
[900] | 555 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 556 | } else {
|
---|
[900] | 557 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 558 | }
|
---|
[900] | 559 | mr_free(flaws_str);
|
---|
[688] | 560 | flaws_str = tmp1;
|
---|
[48] | 561 | res++;
|
---|
[900] | 562 | mr_free(tmp);
|
---|
[48] | 563 | continue;
|
---|
| 564 | }
|
---|
[783] | 565 | // BERLIOS : useless ? str-cpy(mountpoint, mountlist->el[pos].mountpoint);
|
---|
[48] | 566 | /* gap in the partition list? */
|
---|
| 567 | if (curr_part_no - prev_part_no > 1) {
|
---|
| 568 | if (prev_part_no == 0) {
|
---|
[900] | 569 | mr_asprintf(&tmp, " Gap prior to %s.", device);
|
---|
[48] | 570 | log_it(tmp);
|
---|
[688] | 571 | if (flaws_str) {
|
---|
[900] | 572 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 573 | } else {
|
---|
[900] | 574 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 575 | }
|
---|
[900] | 576 | mr_free(flaws_str);
|
---|
[688] | 577 | flaws_str = tmp1;
|
---|
[900] | 578 | mr_free(tmp);
|
---|
[48] | 579 | res++;
|
---|
| 580 | } else if (curr_part_no > 5
|
---|
| 581 | || (curr_part_no <= 4 && prev_part_no > 0)) {
|
---|
[900] | 582 | mr_asprintf(&tmp, " Gap between %s%d and %d.", drive,
|
---|
[59] | 583 | prev_part_no, curr_part_no);
|
---|
[48] | 584 | log_it(tmp);
|
---|
[688] | 585 | if (flaws_str) {
|
---|
[900] | 586 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 587 | } else {
|
---|
[900] | 588 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 589 | }
|
---|
[900] | 590 | mr_free(flaws_str);
|
---|
[688] | 591 | flaws_str = tmp1;
|
---|
[900] | 592 | mr_free(tmp);
|
---|
[48] | 593 | res++;
|
---|
| 594 | }
|
---|
| 595 | }
|
---|
| 596 | /* GPT allows more than 4 primary partitions */
|
---|
| 597 | part_table_fmt = which_partition_format(drive);
|
---|
| 598 | /* no spare primary partitions to help accommodate the logical(s)? */
|
---|
| 599 | if ((curr_part_no >= 5 && prev_part_no == 4)
|
---|
| 600 | && (strcmp(part_table_fmt, "MBR") == 0)) {
|
---|
[900] | 601 | mr_asprintf(&tmp, " Partition %s4 is occupied.", drive);
|
---|
[48] | 602 | log_it(tmp);
|
---|
[688] | 603 | if (flaws_str) {
|
---|
[900] | 604 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 605 | } else {
|
---|
[900] | 606 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 607 | }
|
---|
[900] | 608 | mr_free(flaws_str);
|
---|
[688] | 609 | flaws_str = tmp1;
|
---|
[900] | 610 | mr_free(tmp);
|
---|
[48] | 611 | res++;
|
---|
| 612 | }
|
---|
[900] | 613 | mr_free(part_table_fmt);
|
---|
[146] | 614 |
|
---|
[48] | 615 | /* does partition /dev/hdNX exist more than once in the mountlist? */
|
---|
| 616 | for (i = 0, mountpoint_copies = 0, device_copies = 0;
|
---|
| 617 | i < mountlist->entries; i++) {
|
---|
| 618 | if (!strcmp(device, mountlist->el[i].device)) {
|
---|
| 619 | device_copies++;
|
---|
| 620 | }
|
---|
| 621 | }
|
---|
| 622 | if (device_copies > 1) {
|
---|
[900] | 623 | mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
|
---|
[59] | 624 | device);
|
---|
[48] | 625 | if (!strstr(flaws_str, tmp)) {
|
---|
| 626 | log_it(tmp);
|
---|
[688] | 627 | if (flaws_str) {
|
---|
[900] | 628 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 629 | } else {
|
---|
[900] | 630 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 631 | }
|
---|
[900] | 632 | mr_free(flaws_str);
|
---|
[688] | 633 | flaws_str = tmp1;
|
---|
[48] | 634 | res++;
|
---|
| 635 | }
|
---|
[900] | 636 | mr_free(tmp);
|
---|
[48] | 637 | }
|
---|
| 638 | /* silly partition size? */
|
---|
| 639 | if (mountlist->el[pos].size < 8192
|
---|
| 640 | && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
|
---|
[900] | 641 | mr_asprintf(&tmp, " %s is tiny!", device);
|
---|
[48] | 642 | log_it(tmp);
|
---|
[688] | 643 | if (flaws_str) {
|
---|
[900] | 644 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 645 | } else {
|
---|
[900] | 646 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 647 | }
|
---|
[900] | 648 | mr_free(flaws_str);
|
---|
[688] | 649 | flaws_str = tmp1;
|
---|
[900] | 650 | mr_free(tmp);
|
---|
[48] | 651 | res++;
|
---|
| 652 | }
|
---|
| 653 | /* mountpoint should begin with / unless it is swap, lvm or raid */
|
---|
| 654 | if (strcmp(mountlist->el[pos].mountpoint, "swap")
|
---|
| 655 | && strcmp(mountlist->el[pos].mountpoint, "lvm")
|
---|
| 656 | && strcmp(mountlist->el[pos].mountpoint, "raid")
|
---|
| 657 | && strcmp(mountlist->el[pos].mountpoint, "image")
|
---|
| 658 | && mountlist->el[pos].mountpoint[0] != '/') {
|
---|
[900] | 659 | mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
|
---|
[48] | 660 | log_it(tmp);
|
---|
[688] | 661 | if (flaws_str) {
|
---|
[900] | 662 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 663 | } else {
|
---|
[900] | 664 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 665 | }
|
---|
[900] | 666 | mr_free(flaws_str);
|
---|
[688] | 667 | flaws_str = tmp1;
|
---|
[900] | 668 | mr_free(tmp);
|
---|
[48] | 669 | res++;
|
---|
| 670 | }
|
---|
| 671 | /* is format sensible? */
|
---|
| 672 | if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
|
---|
[900] | 673 | mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
|
---|
[48] | 674 | log_it(tmp);
|
---|
[688] | 675 | if (flaws_str) {
|
---|
[900] | 676 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 677 | } else {
|
---|
[900] | 678 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 679 | }
|
---|
[900] | 680 | mr_free(flaws_str);
|
---|
[688] | 681 | flaws_str = tmp1;
|
---|
[900] | 682 | mr_free(tmp);
|
---|
[48] | 683 | res++;
|
---|
| 684 | }
|
---|
| 685 | /* OK, continue with main loop */
|
---|
| 686 | amount_allocated += mountlist->el[pos].size / 1024;
|
---|
| 687 | prev_part_no = curr_part_no;
|
---|
[900] | 688 | mr_free(device);
|
---|
[1] | 689 | }
|
---|
[48] | 690 |
|
---|
| 691 | /* Over-allocated the disk? Unallocated space on disk? */
|
---|
| 692 | if (amount_allocated > physical_drive_size + 1) {
|
---|
[900] | 693 | mr_asprintf(&tmp, " %ld MB over-allocated on %s.",
|
---|
[59] | 694 | amount_allocated - physical_drive_size, drive);
|
---|
[48] | 695 | log_it(tmp);
|
---|
[688] | 696 | if (flaws_str) {
|
---|
[900] | 697 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 698 | } else {
|
---|
[900] | 699 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 700 | }
|
---|
[900] | 701 | mr_free(flaws_str);
|
---|
[688] | 702 | flaws_str = tmp1;
|
---|
[900] | 703 | mr_free(tmp);
|
---|
[48] | 704 | res++;
|
---|
| 705 | } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */
|
---|
[900] | 706 | mr_asprintf(&tmp, " %ld MB unallocated on %s.",
|
---|
[59] | 707 | physical_drive_size - amount_allocated, drive);
|
---|
[48] | 708 | log_it(tmp);
|
---|
[688] | 709 | if (flaws_str) {
|
---|
[900] | 710 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
[688] | 711 | } else {
|
---|
[900] | 712 | mr_asprintf(&tmp1, "%s", tmp);
|
---|
[688] | 713 | }
|
---|
[900] | 714 | mr_free(flaws_str);
|
---|
[688] | 715 | flaws_str = tmp1;
|
---|
[900] | 716 | mr_free(tmp);
|
---|
[1] | 717 | }
|
---|
[48] | 718 |
|
---|
| 719 | if (res) {
|
---|
| 720 | return (FALSE);
|
---|
| 721 | } else {
|
---|
| 722 | return (TRUE);
|
---|
[1] | 723 | }
|
---|
| 724 | }
|
---|
| 725 | #endif
|
---|
| 726 |
|
---|
| 727 |
|
---|
| 728 | /**
|
---|
| 729 | * Evaluate a whole mountlist for flaws. Calls evaluate_drive_within_mountlist()
|
---|
| 730 | * for each drive, and then spreads the flaws across three lines.
|
---|
| 731 | * @param mountlist The mountlist to evaluate.
|
---|
| 732 | * @param flaws_str_A Where to put the first line listing errors found.
|
---|
| 733 | * @param flaws_str_B Where to put the second line listing errors found.
|
---|
| 734 | * @param flaws_str_C Where to put the third line listing errors found.
|
---|
| 735 | * @return The number of flaws found (0 for success).
|
---|
| 736 | * @see evaluate_drive_within_mountlist
|
---|
| 737 | */
|
---|
| 738 | int
|
---|
[48] | 739 | evaluate_mountlist(struct mountlist_itself *mountlist, char *flaws_str_A,
|
---|
| 740 | char *flaws_str_B, char *flaws_str_C)
|
---|
[1] | 741 | {
|
---|
| 742 |
|
---|
[48] | 743 | /*@ buffer *********************************************************** */
|
---|
| 744 | struct list_of_disks *drivelist;
|
---|
[1] | 745 | char *tmp;
|
---|
[48] | 746 | char *tmp1;
|
---|
[1] | 747 | char *flaws_str;
|
---|
| 748 |
|
---|
[48] | 749 | /*@ int ************************************************************** */
|
---|
[1] | 750 | int i = 0;
|
---|
| 751 | int res = 0;
|
---|
| 752 |
|
---|
[48] | 753 | /*@ initialize ******************************************************* */
|
---|
[1] | 754 |
|
---|
[48] | 755 | drivelist = malloc(sizeof(struct list_of_disks));
|
---|
| 756 | assert(mountlist != NULL);
|
---|
[1] | 757 |
|
---|
[900] | 758 | mr_asprintf(&flaws_str, " ");
|
---|
[1] | 759 |
|
---|
[48] | 760 | make_list_of_drives_in_mountlist(mountlist, drivelist);
|
---|
[1] | 761 |
|
---|
[48] | 762 | log_it("Evaluating mountlist...");
|
---|
| 763 |
|
---|
| 764 | for (i = 0; i < drivelist->entries; i++) {
|
---|
| 765 | if (strstr
|
---|
| 766 | (drivelist->el[i].device,
|
---|
| 767 | DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) {
|
---|
[900] | 768 | mr_asprintf(&tmp, " Not evaluating %s (I don't know how yet)",
|
---|
[59] | 769 | drivelist->el[i].device);
|
---|
[48] | 770 | log_it(tmp);
|
---|
| 771 | } else {
|
---|
[688] | 772 | // This function allocates tmp
|
---|
[48] | 773 | if (!evaluate_drive_within_mountlist
|
---|
| 774 | (mountlist, drivelist->el[i].device, tmp)) {
|
---|
| 775 | res++;
|
---|
| 776 | }
|
---|
| 777 | }
|
---|
[900] | 778 | mr_asprintf(&tmp1, "%s%s", flaws_str, tmp);
|
---|
| 779 | mr_free(tmp);
|
---|
| 780 | mr_free(flaws_str);
|
---|
[48] | 781 | flaws_str = tmp1;
|
---|
[1] | 782 | }
|
---|
[48] | 783 | res += look_for_duplicate_mountpoints(mountlist, flaws_str);
|
---|
| 784 | return (spread_flaws_across_three_lines
|
---|
| 785 | (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res));
|
---|
[1] | 786 | }
|
---|
| 787 |
|
---|
| 788 |
|
---|
| 789 | /**
|
---|
| 790 | * Find the index number of @p device in the mountlist.
|
---|
| 791 | * The device given must match @p mountlist->el[N].device exactly, case-sensitive.
|
---|
| 792 | * @param mountlist The mountlist to search in.
|
---|
| 793 | * @param device The device to search for.
|
---|
| 794 | * @return The zero-based index of the device, or -1 if it could not be found.
|
---|
| 795 | */
|
---|
| 796 | int
|
---|
[48] | 797 | find_device_in_mountlist(struct mountlist_itself *mountlist, char *device)
|
---|
[1] | 798 | {
|
---|
| 799 |
|
---|
[48] | 800 | /*@ int ************************************************************** */
|
---|
| 801 | int i = 0;
|
---|
[1] | 802 |
|
---|
[48] | 803 | assert(mountlist != NULL);
|
---|
| 804 | assert_string_is_neither_NULL_nor_zerolength(device);
|
---|
| 805 | for (i = 0;
|
---|
| 806 | i < mountlist->entries
|
---|
| 807 | && strcmp(mountlist->el[i].device, device) != 0; i++);
|
---|
| 808 |
|
---|
| 809 | if (i == mountlist->entries) {
|
---|
| 810 | return (-1);
|
---|
| 811 | } else {
|
---|
| 812 | return (i);
|
---|
| 813 | }
|
---|
[1] | 814 | }
|
---|
| 815 |
|
---|
| 816 |
|
---|
| 817 | /**
|
---|
| 818 | * Look for duplicate mountpoints in @p mountlist.
|
---|
| 819 | * @param mountlist The mountlist to check.
|
---|
| 820 | * @param flaws_str The flaws string to append the results to.
|
---|
| 821 | * @return The number of mountpoints that have duplicates, or 0 for success.
|
---|
| 822 | */
|
---|
| 823 | int
|
---|
[48] | 824 | look_for_duplicate_mountpoints(struct mountlist_itself *mountlist,
|
---|
| 825 | char *flaws_str)
|
---|
[1] | 826 | {
|
---|
| 827 |
|
---|
[48] | 828 | /*@ int ************************************************************* */
|
---|
| 829 | int res = 0;
|
---|
[1] | 830 | int currline = 0;
|
---|
| 831 | int i = 0;
|
---|
| 832 | int copies = 0;
|
---|
| 833 | int last_copy = 0;
|
---|
| 834 |
|
---|
[48] | 835 | /*@ buffetr ********************************************************* */
|
---|
[688] | 836 | char *curr_mountpoint = NULL;
|
---|
| 837 | char *tmp = NULL;
|
---|
| 838 | char *tmp1 = NULL;
|
---|
[1] | 839 |
|
---|
[48] | 840 | assert(mountlist != NULL);
|
---|
| 841 | assert(flaws_str != NULL);
|
---|
[688] | 842 |
|
---|
[48] | 843 | for (currline = 0; currline < mountlist->entries; currline++) {
|
---|
[900] | 844 | mr_asprintf(&curr_mountpoint, mountlist->el[currline].mountpoint);
|
---|
[48] | 845 | for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries;
|
---|
| 846 | i++) {
|
---|
| 847 | if (!strcmp(mountlist->el[i].mountpoint, curr_mountpoint)
|
---|
| 848 | && strcmp(mountlist->el[i].mountpoint, "lvm")
|
---|
| 849 | && strcmp(mountlist->el[i].mountpoint, "swap")) {
|
---|
| 850 | last_copy = i;
|
---|
| 851 | copies++;
|
---|
| 852 | }
|
---|
| 853 | }
|
---|
| 854 | if (copies > 1 && last_copy == currline
|
---|
| 855 | && strcmp(curr_mountpoint, "raid")) {
|
---|
[900] | 856 | mr_asprintf(&tmp, " %s %s's.", number_to_text(copies),
|
---|
[59] | 857 | curr_mountpoint);
|
---|
[48] | 858 | log_it(tmp);
|
---|
[900] | 859 | mr_asprintf(&tmp1, "%s%s",flaws_str, tmp);
|
---|
| 860 | mr_free(flaws_str);
|
---|
[688] | 861 | flaws_str = tmp1;
|
---|
[900] | 862 | mr_free(tmp);
|
---|
[48] | 863 | res++;
|
---|
| 864 | }
|
---|
[900] | 865 | mr_free(curr_mountpoint);
|
---|
[1] | 866 | }
|
---|
[48] | 867 | return (res);
|
---|
[1] | 868 | }
|
---|
| 869 |
|
---|
[48] | 870 |
|
---|
[1] | 871 | /**
|
---|
| 872 | * Make a list of the drives mentioned in the mountlist.
|
---|
| 873 | * @param mountlist The mountlist to examine.
|
---|
| 874 | * @param drivelist Where to put the list of drives found.
|
---|
| 875 | * @return The number of physical (non-RAID non-LVM) drives found, or \<= 0 for error.
|
---|
| 876 | */
|
---|
| 877 | int
|
---|
[48] | 878 | make_list_of_drives_in_mountlist(struct mountlist_itself *mountlist,
|
---|
| 879 | struct list_of_disks *drivelist)
|
---|
[1] | 880 | {
|
---|
| 881 |
|
---|
[48] | 882 | /*@ int ************************************************************* */
|
---|
| 883 | int lino;
|
---|
| 884 | int noof_drives;
|
---|
| 885 | int j;
|
---|
[1] | 886 |
|
---|
[48] | 887 | /*@ buffers ********************************************************* */
|
---|
| 888 | char *drive;
|
---|
| 889 | char *tmp;
|
---|
[1] | 890 |
|
---|
[48] | 891 | long long size;
|
---|
[1] | 892 |
|
---|
[48] | 893 | assert(mountlist != NULL);
|
---|
| 894 | assert(drivelist != NULL);
|
---|
| 895 | log_it("Making list of drives");
|
---|
| 896 | for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) {
|
---|
[1] | 897 |
|
---|
[900] | 898 | mr_asprintf(&drive, mountlist->el[lino].device);
|
---|
[48] | 899 | if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
|
---|
[900] | 900 | mr_asprintf(&tmp,
|
---|
[59] | 901 | "Not putting %s in list of drives: it's a virtual drive",
|
---|
| 902 | drive);
|
---|
[48] | 903 | log_msg(8, tmp);
|
---|
[900] | 904 | mr_free(tmp);
|
---|
[48] | 905 | continue;
|
---|
| 906 | }
|
---|
[1] | 907 |
|
---|
[48] | 908 | size = mountlist->el[lino].size;
|
---|
| 909 | if (size == 0) {
|
---|
[900] | 910 | mr_asprintf(&tmp,
|
---|
[59] | 911 | "Not putting %s in list of drives: it has zero size (maybe an LVM volume)",
|
---|
| 912 | drive);
|
---|
[48] | 913 | log_msg(8, tmp);
|
---|
[900] | 914 | mr_free(tmp);
|
---|
[48] | 915 | continue;
|
---|
| 916 | }
|
---|
| 917 |
|
---|
[1] | 918 | /*
|
---|
| 919 | for (i = strlen (drive); isdigit (drive[i - 1]); i--);
|
---|
| 920 | drive[i] = '\0';
|
---|
| 921 | if (get_phys_size_of_drive (drive) <= 0 && drive[i - 1] == 'p')
|
---|
| 922 | {
|
---|
| 923 | i--;
|
---|
| 924 | drive[i] = '\0';
|
---|
| 925 | }
|
---|
| 926 | for (j = 0; j < noof_drives && strcmp (drivelist[j], drive) != 0; j++);
|
---|
| 927 | */
|
---|
| 928 |
|
---|
[900] | 929 | mr_asprintf(&tmp,
|
---|
[59] | 930 | "Putting %s with size %lli in list of drives",
|
---|
| 931 | drive, size);
|
---|
[48] | 932 | log_msg(8, tmp);
|
---|
[900] | 933 | mr_free(tmp);
|
---|
[1] | 934 |
|
---|
[48] | 935 | (void) truncate_to_drive_name(drive);
|
---|
| 936 | for (j = 0;
|
---|
| 937 | j < noof_drives
|
---|
| 938 | && strcmp(drivelist->el[j].device, drive) != 0; j++)
|
---|
| 939 | continue;
|
---|
| 940 | if (j == noof_drives) {
|
---|
| 941 | strcpy(drivelist->el[noof_drives++].device, drive);
|
---|
| 942 | }
|
---|
[900] | 943 | mr_free(drive);
|
---|
[48] | 944 |
|
---|
[1] | 945 | }
|
---|
[48] | 946 | drivelist->entries = noof_drives;
|
---|
| 947 | log_msg(8, "Made list of drives");
|
---|
[1] | 948 |
|
---|
[48] | 949 | return (noof_drives);
|
---|
[1] | 950 | }
|
---|
| 951 |
|
---|
| 952 |
|
---|
| 953 | /**
|
---|
| 954 | * Make a list of RAID partitions not currently associated with any RAID device.
|
---|
| 955 | * The user may add any of these partitions to the RAID device.
|
---|
| 956 | * @param output_list Where to put the list of unallocated RAID partitions.
|
---|
| 957 | * @param mountlist The mountlist to examine.
|
---|
| 958 | * @param raidlist The raidlist to examine.
|
---|
| 959 | */
|
---|
[48] | 960 | void make_list_of_unallocated_raid_partitions(struct mountlist_itself
|
---|
[59] | 961 | *output_list, struct mountlist_itself
|
---|
| 962 | *mountlist, struct raidlist_itself
|
---|
[48] | 963 | *raidlist)
|
---|
[1] | 964 | {
|
---|
| 965 |
|
---|
[48] | 966 | /*@ int ************************************************************* */
|
---|
| 967 | int items = 0;
|
---|
[1] | 968 | int i = 0;
|
---|
| 969 | int used_by = 0;
|
---|
| 970 |
|
---|
[48] | 971 | /*@ buffers ********************************************************* */
|
---|
| 972 | char *tmp;
|
---|
[1] | 973 |
|
---|
[48] | 974 | assert(output_list != NULL);
|
---|
| 975 | assert(mountlist != NULL);
|
---|
| 976 | assert(raidlist != NULL);
|
---|
| 977 | log_it("MLOURP -- starting");
|
---|
| 978 | items = 0;
|
---|
[1] | 979 |
|
---|
| 980 |
|
---|
[48] | 981 | for (i = 0; i < mountlist->entries; i++) {
|
---|
| 982 | if (strstr(mountlist->el[i].mountpoint, "raid")) {
|
---|
| 983 | used_by =
|
---|
| 984 | which_raid_device_is_using_this_partition(raidlist,
|
---|
| 985 | mountlist->el[i].
|
---|
| 986 | device);
|
---|
| 987 | if (used_by < 0) {
|
---|
| 988 | memcpy((void *) &output_list->el[items++],
|
---|
| 989 | (void *) &mountlist->el[i],
|
---|
| 990 | sizeof(struct mountlist_line));
|
---|
[900] | 991 | mr_asprintf(&tmp,
|
---|
[59] | 992 | "%s is available; user may choose to add it to raid device",
|
---|
| 993 | output_list->el[items - 1].device);
|
---|
[48] | 994 | log_it(tmp);
|
---|
[900] | 995 | mr_free(tmp);
|
---|
[48] | 996 | }
|
---|
| 997 | }
|
---|
[1] | 998 | }
|
---|
[48] | 999 | output_list->entries = items;
|
---|
| 1000 | log_it("MLUORP -- ending");
|
---|
[1] | 1001 | }
|
---|
| 1002 |
|
---|
| 1003 |
|
---|
| 1004 | /**
|
---|
| 1005 | * Get the size of a mountlist entry by the @c device field.
|
---|
| 1006 | * @param mountlist The mountlist to search in.
|
---|
| 1007 | * @param device The device to search for
|
---|
| 1008 | * @return The size of the device (in KB), or -1 if it could not be found.
|
---|
| 1009 | */
|
---|
| 1010 | long long
|
---|
[48] | 1011 | size_of_specific_device_in_mountlist(struct mountlist_itself *mountlist,
|
---|
| 1012 | char *device)
|
---|
[1] | 1013 | {
|
---|
[48] | 1014 | /*@ int ************************************************************** */
|
---|
| 1015 | int i = 0;
|
---|
[1] | 1016 |
|
---|
| 1017 |
|
---|
[48] | 1018 | assert(mountlist != NULL);
|
---|
| 1019 | assert_string_is_neither_NULL_nor_zerolength(device);
|
---|
[1] | 1020 |
|
---|
[48] | 1021 | for (i = 0;
|
---|
| 1022 | i < mountlist->entries && strcmp(mountlist->el[i].device, device);
|
---|
| 1023 | i++);
|
---|
| 1024 | if (i == mountlist->entries) {
|
---|
| 1025 | return (-1);
|
---|
| 1026 | } else {
|
---|
| 1027 | return (mountlist->el[i].size);
|
---|
| 1028 | }
|
---|
[1] | 1029 | }
|
---|
| 1030 |
|
---|
| 1031 |
|
---|
| 1032 | /**
|
---|
| 1033 | * Load a file on disk into @p mountlist.
|
---|
| 1034 | * The file on disk should consist of multiple lines, each containing 4 or 5
|
---|
| 1035 | * columns: the device, the mountpoint, the filesystem type, the size in kilobytes, and optionally the filesystem label.
|
---|
| 1036 | * Comments begin with a '#' without any leading whitespace. Any duplicate
|
---|
| 1037 | * entries are renamed.
|
---|
| 1038 | * @param mountlist The mountlist to load into.
|
---|
| 1039 | * @param fname The name of the file to load the mountlist from.
|
---|
| 1040 | * @return 0 for success, 1 for failure.
|
---|
| 1041 | */
|
---|
[48] | 1042 | int load_mountlist(struct mountlist_itself *mountlist, char *fname)
|
---|
[1] | 1043 | {
|
---|
[48] | 1044 | FILE *fin;
|
---|
| 1045 | /* malloc ** */
|
---|
| 1046 | char *incoming = NULL;
|
---|
| 1047 | char *siz;
|
---|
| 1048 | char *tmp;
|
---|
| 1049 | char *p;
|
---|
[1] | 1050 |
|
---|
[48] | 1051 | int items;
|
---|
| 1052 | int j;
|
---|
[49] | 1053 | size_t n = 0;
|
---|
[1] | 1054 |
|
---|
[48] | 1055 | assert(mountlist != NULL);
|
---|
| 1056 | assert_string_is_neither_NULL_nor_zerolength(fname);
|
---|
| 1057 | malloc_string(siz);
|
---|
| 1058 | if (!(fin = fopen(fname, "r"))) {
|
---|
| 1059 | log_it("Unable to open mountlist - '%s'", fname);
|
---|
[507] | 1060 | log_to_screen(_("Cannot open mountlist"));
|
---|
[900] | 1061 | mr_free(siz);
|
---|
[48] | 1062 | return (1);
|
---|
| 1063 | }
|
---|
| 1064 | items = 0;
|
---|
[900] | 1065 | mr_getline(&incoming, &n, fin);
|
---|
[48] | 1066 | log_it("Loading mountlist...");
|
---|
| 1067 | while (!feof(fin)) {
|
---|
[1] | 1068 | #if linux
|
---|
[48] | 1069 | sscanf(incoming,
|
---|
| 1070 | "%s %s %s %s %s",
|
---|
| 1071 | mountlist->el[items].device,
|
---|
| 1072 | mountlist->el[items].mountpoint,
|
---|
| 1073 | mountlist->el[items].format,
|
---|
| 1074 | siz, mountlist->el[items].label);
|
---|
[1] | 1075 | #elif __FreeBSD__
|
---|
[48] | 1076 | sscanf(incoming,
|
---|
| 1077 | "%s %s %s %s",
|
---|
| 1078 | mountlist->el[items].device,
|
---|
| 1079 | mountlist->el[items].mountpoint,
|
---|
| 1080 | mountlist->el[items].format, siz);
|
---|
| 1081 | strcpy(mountlist->el[items].label, "");
|
---|
[1] | 1082 | #endif
|
---|
| 1083 |
|
---|
[48] | 1084 | if (!strcmp(mountlist->el[items].device, "/proc") ||
|
---|
| 1085 | !strcmp(mountlist->el[items].device, "proc") ||
|
---|
| 1086 | !strcmp(mountlist->el[items].device, "/sys") ||
|
---|
| 1087 | !strcmp(mountlist->el[items].device, "sys") ||
|
---|
| 1088 | !strcmp(mountlist->el[items].device, "/devpts") ||
|
---|
| 1089 | !strcmp(mountlist->el[items].device, "devpts")
|
---|
| 1090 | ) {
|
---|
| 1091 | log_msg(1,
|
---|
| 1092 | "Ignoring %s in mountlist - not loading that line :) ",
|
---|
| 1093 | mountlist->el[items].device);
|
---|
[900] | 1094 | mr_getline(&incoming, &n, fin);
|
---|
[48] | 1095 | continue;
|
---|
| 1096 | }
|
---|
| 1097 | mountlist->el[items].size = atoll(siz);
|
---|
| 1098 | if (mountlist->el[items].device[0] != '\0'
|
---|
| 1099 | && mountlist->el[items].device[0] != '#') {
|
---|
| 1100 | if (items >= ARBITRARY_MAXIMUM) {
|
---|
[507] | 1101 | log_to_screen(_("Too many lines in mountlist.. ABORTING"));
|
---|
[48] | 1102 | finish(1);
|
---|
| 1103 | }
|
---|
| 1104 | for (j = 0;
|
---|
| 1105 | j < items
|
---|
| 1106 | && strcmp(mountlist->el[j].device,
|
---|
| 1107 | mountlist->el[items].device); j++);
|
---|
| 1108 | if (j < items) {
|
---|
| 1109 | strcat(mountlist->el[items].device, "_dup");
|
---|
[900] | 1110 | mr_asprintf(&tmp,
|
---|
[59] | 1111 | "Duplicate entry in mountlist - renaming to %s",
|
---|
| 1112 | mountlist->el[items].device);
|
---|
[48] | 1113 | log_it(tmp);
|
---|
[900] | 1114 | mr_free(tmp);
|
---|
[48] | 1115 | }
|
---|
[900] | 1116 | mr_asprintf(&tmp, mountlist->el[items].device);
|
---|
[48] | 1117 | if (strstr(tmp, "/dev/md/")) {
|
---|
| 1118 | log_it("format_device() --- Contracting %s", tmp);
|
---|
| 1119 | p = strrchr(tmp, '/');
|
---|
| 1120 | if (p) {
|
---|
| 1121 | *p = *(p + 1);
|
---|
| 1122 | *(p + 1) = *(p + 2);
|
---|
| 1123 | *(p + 2) = *(p + 3);
|
---|
| 1124 | }
|
---|
| 1125 | log_it("It was %s; it is now %s",
|
---|
| 1126 | mountlist->el[items].device, tmp);
|
---|
| 1127 | strcpy(mountlist->el[items].device, tmp);
|
---|
| 1128 | }
|
---|
[900] | 1129 | mr_free(tmp);
|
---|
[1] | 1130 |
|
---|
[900] | 1131 | mr_asprintf(&tmp,
|
---|
[59] | 1132 | "%s %s %s %lld %s",
|
---|
| 1133 | mountlist->el[items].device,
|
---|
| 1134 | mountlist->el[items].mountpoint,
|
---|
| 1135 | mountlist->el[items].format,
|
---|
| 1136 | mountlist->el[items].size,
|
---|
| 1137 | mountlist->el[items].label);
|
---|
[1] | 1138 |
|
---|
[48] | 1139 | log_it(tmp);
|
---|
[900] | 1140 | mr_free(tmp);
|
---|
[48] | 1141 | items++;
|
---|
| 1142 | }
|
---|
[900] | 1143 | mr_getline(&incoming, &n, fin);
|
---|
[1] | 1144 | }
|
---|
[48] | 1145 | paranoid_fclose(fin);
|
---|
[900] | 1146 | mr_free(incoming);
|
---|
[48] | 1147 | mountlist->entries = items;
|
---|
[1] | 1148 |
|
---|
[48] | 1149 | log_it("Mountlist loaded successfully.");
|
---|
[900] | 1150 | mr_asprintf(&tmp, "%d entries in mountlist", items);
|
---|
[48] | 1151 | log_it(tmp);
|
---|
[900] | 1152 | mr_free(tmp);
|
---|
[48] | 1153 |
|
---|
[900] | 1154 | mr_free(siz);
|
---|
[48] | 1155 | return (0);
|
---|
[1] | 1156 | }
|
---|
| 1157 |
|
---|
| 1158 |
|
---|
| 1159 |
|
---|
| 1160 | /**
|
---|
| 1161 | * Save @p mountlist to a file on disk.
|
---|
| 1162 | * @param mountlist The mountlist to save.
|
---|
| 1163 | * @param fname The file to save it to.
|
---|
| 1164 | * @return 0 for success, 1 for failure.
|
---|
| 1165 | * @see load_mountlist
|
---|
| 1166 | */
|
---|
[48] | 1167 | int save_mountlist_to_disk(struct mountlist_itself *mountlist, char *fname)
|
---|
[1] | 1168 | {
|
---|
[48] | 1169 | FILE *fout;
|
---|
| 1170 | int i;
|
---|
[1] | 1171 |
|
---|
[48] | 1172 | assert(mountlist != NULL);
|
---|
| 1173 | assert_string_is_neither_NULL_nor_zerolength(fname);
|
---|
[1] | 1174 |
|
---|
[48] | 1175 | log_it("save_mountlist_to_disk() --- saving to %s", fname);
|
---|
| 1176 | if (!(fout = fopen(fname, "w"))) {
|
---|
| 1177 | log_OS_error("WMTD - Cannot openout mountlist");
|
---|
| 1178 | return (1);
|
---|
| 1179 | }
|
---|
| 1180 | for (i = 0; i < mountlist->entries; i++) {
|
---|
| 1181 | fprintf(fout,
|
---|
| 1182 | "%-15s %-15s %-15s %-15lld %-15s\n",
|
---|
| 1183 | mountlist->el[i].device, mountlist->el[i].mountpoint,
|
---|
| 1184 | mountlist->el[i].format, mountlist->el[i].size,
|
---|
| 1185 | mountlist->el[i].label);
|
---|
| 1186 | }
|
---|
| 1187 | paranoid_fclose(fout);
|
---|
| 1188 | return (0);
|
---|
[1] | 1189 | }
|
---|
| 1190 |
|
---|
| 1191 |
|
---|
| 1192 | /**
|
---|
| 1193 | * Sort the mountlist alphabetically by device.
|
---|
| 1194 | * The sorting is done in-place.
|
---|
| 1195 | * @param mountlist The mountlist to sort.
|
---|
| 1196 | */
|
---|
[48] | 1197 | void sort_mountlist_by_device(struct mountlist_itself *mountlist)
|
---|
[1] | 1198 | {
|
---|
[48] | 1199 | int diff;
|
---|
| 1200 | int lino = -999;
|
---|
[1] | 1201 |
|
---|
[48] | 1202 | assert(mountlist != NULL);
|
---|
[1] | 1203 |
|
---|
[48] | 1204 | while (lino < mountlist->entries) {
|
---|
| 1205 | for (lino = 1; lino < mountlist->entries; lino++) {
|
---|
| 1206 | diff =
|
---|
| 1207 | strcmp_inc_numbers(mountlist->el[lino - 1].device,
|
---|
| 1208 | mountlist->el[lino].device);
|
---|
| 1209 | if (diff > 0) {
|
---|
| 1210 | swap_mountlist_entries(mountlist, lino - 1, lino);
|
---|
| 1211 | break;
|
---|
| 1212 | }
|
---|
| 1213 | }
|
---|
[1] | 1214 | }
|
---|
| 1215 | }
|
---|
| 1216 |
|
---|
[48] | 1217 |
|
---|
[1] | 1218 | /**
|
---|
| 1219 | * Sort the mountlist alphabetically by mountpoint.
|
---|
| 1220 | * The sorting is done in-place.
|
---|
| 1221 | * @param mountlist The mountlist to sort.
|
---|
| 1222 | * @param reverse If TRUE, then do a reverse sort.
|
---|
| 1223 | */
|
---|
[48] | 1224 | void
|
---|
| 1225 | sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist,
|
---|
| 1226 | bool reverse)
|
---|
[1] | 1227 | {
|
---|
[48] | 1228 | int diff;
|
---|
| 1229 | int lino = -999;
|
---|
[1] | 1230 |
|
---|
[48] | 1231 | assert(mountlist != NULL);
|
---|
[1] | 1232 |
|
---|
[48] | 1233 | while (lino < mountlist->entries) {
|
---|
| 1234 | for (lino = 1; lino < mountlist->entries; lino++) {
|
---|
| 1235 | diff =
|
---|
| 1236 | strcmp(mountlist->el[lino - 1].mountpoint,
|
---|
| 1237 | mountlist->el[lino].mountpoint);
|
---|
| 1238 | if ((diff > 0 && !reverse) || ((diff < 0 && reverse))) {
|
---|
| 1239 | swap_mountlist_entries(mountlist, lino - 1, lino);
|
---|
| 1240 | break;
|
---|
| 1241 | }
|
---|
| 1242 | }
|
---|
[1] | 1243 | }
|
---|
| 1244 | }
|
---|
| 1245 |
|
---|
| 1246 |
|
---|
| 1247 | /**
|
---|
| 1248 | * Swap two entries in the mountlist in-place.
|
---|
| 1249 | * @param mountlist The mountlist to swap the entries in.
|
---|
| 1250 | * @param a The index number of the first entry.
|
---|
| 1251 | * @param b The index number of the second entry.
|
---|
| 1252 | */
|
---|
[48] | 1253 | void
|
---|
[1] | 1254 | swap_mountlist_entries(struct mountlist_itself *mountlist, int a, int b)
|
---|
| 1255 | {
|
---|
[48] | 1256 | /*@ mallocs *** */
|
---|
| 1257 | char *device;
|
---|
| 1258 | char *mountpoint;
|
---|
| 1259 | char *format;
|
---|
[1] | 1260 |
|
---|
[48] | 1261 | long long size;
|
---|
[1] | 1262 |
|
---|
[48] | 1263 | assert(mountlist != NULL);
|
---|
| 1264 | assert(a >= 0);
|
---|
| 1265 | assert(b >= 0);
|
---|
[1] | 1266 |
|
---|
[900] | 1267 | mr_asprintf(&device, mountlist->el[a].device);
|
---|
| 1268 | mr_asprintf(&mountpoint, mountlist->el[a].mountpoint);
|
---|
| 1269 | mr_asprintf(&format, mountlist->el[a].format);
|
---|
[1] | 1270 |
|
---|
[48] | 1271 | size = mountlist->el[a].size;
|
---|
[1] | 1272 |
|
---|
[48] | 1273 | strcpy(mountlist->el[a].device, mountlist->el[b].device);
|
---|
| 1274 | strcpy(mountlist->el[a].mountpoint, mountlist->el[b].mountpoint);
|
---|
| 1275 | strcpy(mountlist->el[a].format, mountlist->el[b].format);
|
---|
[1] | 1276 |
|
---|
[48] | 1277 | mountlist->el[a].size = mountlist->el[b].size;
|
---|
[1] | 1278 |
|
---|
[48] | 1279 | strcpy(mountlist->el[b].device, device);
|
---|
| 1280 | strcpy(mountlist->el[b].mountpoint, mountpoint);
|
---|
| 1281 | strcpy(mountlist->el[b].format, format);
|
---|
[1] | 1282 |
|
---|
[48] | 1283 | mountlist->el[b].size = size;
|
---|
[1] | 1284 | }
|
---|
| 1285 |
|
---|
| 1286 | /* @} - end of mountlistGroup */
|
---|