Changeset 48 in MondoRescue
- Timestamp:
- Oct 6, 2005, 6:08:17 PM (20 years ago)
- Location:
- trunk/mondo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/TODO
r30 r48 1 TODO: 2 3 - add encryption option (so that the archives will be encrypted) 4 - remove mktemp command 5 - remove goto 6 - remove strcat, strcpy, sprintf 7 - manage all memory dynamically (remove MAX_STR_LEN,...) 8 - find safe equivalent to fread 9 10 11 12 13 Old version: 14 1 15 MONDO TODO Hugo Rabson <hugorabson@msn.com> 07/04/2004 2 16 … … 21 35 - thoroughly document each script & its function, in the source code 22 36 - flowchart everything; save in PostScript & publish on web 23 24 25 TASKS PROCESSED26 - write a TODO file :-)27 - write a CHANGES file28 - proper command-line switches29 - more switches/options30 - make switches and '--help' user-friendly31 - make it possible to burn CDs straight from script, if user wants to32 (using the '--call-after-iso <call>' switch)33 - well, implement some, to start with :-) <-- command-line switches34 - make it possible to write to CDRW disks directly from script,35 prompting for disk change <-- using '--call-make-iso <call>' switch36 - clean up the scripts, esp. mondo-archive, its "MakeTarballsAndImages"37 routine and the main loop38 - release a stable copy w/no known bugs & declare v0.90 (it's about time)39 ...well, one problem reported w/user's BASH but I'm working on that ;)40 - rewrite filelist splitter (parallelize it)41 - MakeAllFilelists &42 - while [ "`ps MakeAllFilelists`' is running ] || [ "filelist.N+1" exists ] ; do43 WaitForFilelist N44 MakeSet N45 done46 - directly support CDRs in kernel and scripts (?)47 - to burn a CD after creating the ISO image, use48 --call-after-iso "cdrecord ... ; eject /dev/cdrom" etc.49 - I'm not sure if the kernel has all the necessary features compiled50 into it; I'm looking into it.51 - write a 'man' page <----- type 'mondo-archive --help'52 - verify ISO archives against filesystem, to make sure there's no corruption53 - verify ISO filelists against original filelist, to make sure all files were54 backed up that should have been, and none were backed up that shouldn't55 - parallelized filelist-creation and -tarballing, to improve speed56 - added --verify option, to give LOTS more confidence in archives57 - mailing list? <----- now possible, thanks to SourceForge (underway)58 - write a proper README / quickstart file59 - better self-checking for prep-me60 - make kernel modular; include modules in tarball, to be put on CD61 - multi-volume backup/restore <-- works well! :-) [v0.916]62 - easier installation from tarball63 - faster code, esp. 'set-chopper'64 - proper '--help' thingy65 - better mondo-archive and mondo-restore progress reports66 - offer to restore MBRs for user67 - give user the option of _not_ wiping all hard drives68 - let user choose which files to restore (e.g. restore-me /mnt/dos)69 - finally, Mondo uses SYSLINUX instead of COMMAND.COM (thanks, Steve Pitts)70 - hack user's restored lilo.conf and fstab to reflect the mountlist, if the71 user has modified it;72 - let user amend mountlist semi-automatically to reflect larger/smaller hard73 drives than original (useful for moving files from one hard drive to another)74 ...part of check-mountlist-sanity75 - mondo-restore ----- edit mountlist (using pico)76 - Mondo now uses afio instead of tar77 - mondo-archive now much more sensible when sending info between processes78 - make Mondo distro-independent79 - save&restore all boot sectors automatically (MBRs remaining optional)80 - release RPMs and tarballs at same time81 - mondo-restore --- verify disk copy after extracting from archive82 - chop large files into blocks; reassemble them at restore-time83 - MD5 checksum for every file, inc. chopped-up files84 - remove '[' from overhead-list; put list of required packages on web page85 - make sure user knows --skip-spacetest is AT OWN RISK86 - replace instances of 'cat | grep' with just plain 'grep'87 - concatenate all fileset lists; compare to original filelist.full88 - compare mode: nondestructive comparison of filesystem with Rescue CD89 - better verify-progress feedback [Verifying 5/107]90 - hdX2,3,4 layout now works OK at backup and restore time! W00H00! :-)91 - fix Win98 boot sector kludge problem92 - speed up mondo-checksum (thanks, Fabrice!)93 - to save some time & space, do not pad the ISO image94 - build and burn CDs with one command95 - support CDRW drives96 - support SCSI hard drives97 - write straight to CD-R by calling mondo-archive w/correct params98 - use optional 2nd floppy to support extras modules, inc. SCSI hard drives99 - only let Mondo run as root100 - recompile kernel + modules for i386101 - added ReiserFS support102 - amalgamated the Mondo RPMs/TGZs into a single ball103 - let user incorporate their own kernel and tools (thanks to Mindi!)104 - Linux 2.4 kernel support105 - add XFS support106 - add ext3 support107 - add JFS support108 - add ReiserFS support109 - give comprehensive restore-time feedback (not just '%done')110 - pipe mkisofs to cdrecord, saving a lot of disk space & some time111 - add Windows ME and Windows 2000 support (VFAT only)112 - make the SRPM recompile Mondo's C programs113 - RAID support114 - make it possible to use an NFS-mounted partition as scratch/iso dir115 - write a proper manual116 - add Red Hat LABEL support (/etc/fstab)117 - record '%age full' of each partition at backup-time118 - newt/ncurses interface would be cool119 - implement user-friendly mountlist editor120 - progress screen (mondo-tarme)121 - check that the partitions will fit on the hard drives122 - verify ISO after creating if (if user uses '--verify')123 - verify CD after burning if (if user uses '--verify')124 - support parallel-port CD writers125 - support tape drives126 - test with Red Hat 7.2127 - incremental/differential backup mode128 - add GRUB support129 - make it possible to backup and restore partitions of an unknown type130 - incorporate busybox-0.60-2131 - put data disks on tape, so that tape users only need 1 floppy + tape132 - text mode133 - add "NFS" boot option134 - drop trailing slashes from all params of --exclude-path135 - add Petris :)136 - Tab-format fstab after 'hacking' it137 - Interactive Mode should let the user choose which partitions to format138 - add an "exclude path?" dialog to Interactive Mode139 - re-enable CD verification140 - if creation/format fails, go back to mountlist editor141 - let user choose which partitions to format142 - port mondo-archive entirely to C143 - if -E /dev/xxx then exclude _device_ from mountlist but don't exclude144 /dev file from filelist145 - rewrite the "is tape there?" test: if 'V' then RO test; if 'O' then RW test146 - allow mondorestore to be used to restore to live filesystems147 - add /proc/cpuinfo to logfile148 - enable Ctrl-C --> abort in mondoarchive and mindi149 - write a 'man' page150 - test w/multiple tapes151 - an easy-to-use interface to Mondo-archive which does a lot of the152 fiddly configurating for you153 - if Compare Mode then popup list of /tmp/changed.files154 - only zero drive /dev/hdXn if /dev/hdX1 is being prepped155 - if differential backup then disable nuke at restore-time156 - write X-based front end to mondoarchive/mondorestore (XMondo)157 - added partimagehack to Mondo (freeloader - you know who you are - please158 quit being a dick)159 - put serial# on each CD/tape160 - give Mondo+Mindi a CVS161 - add parted162 - Ian Mortimer's spec patches163 - encourage -X164 165 166 ABANDONED167 - detect size of CDR automatically (I don't know how)168 - allow user to choose archive engine besides tar (e.g. star, cpio)169 ...tar sucked; star _really_ sucked; cpio, forget it; I chose afio in the end170 because it was the only engine which I knew would work. I've used it for171 years w/o any problems. Tar has been nothing but a headache.172 - split up mondo-archive's functionality into separate scripts, so that it will173 be possible to backup files, do something else, then archive it, etc.etc.174 ...too much trouble; no incentive to do it; no-one asked me to :)175 - pseudocode176 ...why bother? If bash scripts are too complicated for you, try COBOL... -
trunk/mondo/mondo/common/libmondo-mountlist.c
r30 r48 1 /* libmondo-mountlist.c subroutines for handling mountlist 2 $Id: libmondo-mountlist.c,v 1.2 2004/06/10 15:29:12 hugo Exp $ 3 4 5 6 08/01 7 - when evaluating mountlist, skip drive entirely if it does not exist 8 9 07/14 10 - always exclude /devpts, /proc, /sys from mountlist 11 12 06/29/2004 13 - changed some char[] to *char 14 - drivelist is struct now, not char[][] 15 16 10/19/2003 17 - format_device() --- contract /dev/md/N to /dev/mdN to 18 overcome devfs problems 19 20 06/11 21 - added support for 5th column in mountlist.txt, for labels 22 23 05/08 24 - added save_mountlist_to_disk() and load_mountlist() 25 and misc other funcs from mondorestore.c 26 27 05/05 28 - added Joshua Oreman's FreeBSD patches 29 30 04/24 31 - added some assert()'s 32 33 04/23 34 - cleaned up evaluate_drive_within_mountlist() a bit 35 36 01/15/2003 37 - added code for LVM (Brian Borgeson) 38 39 10/19/2002 40 - added some comments 41 42 07/24/2002 43 - created 1 /* $Id$ 2 subroutines for handling mountlist 44 3 */ 45 46 4 47 5 /** … … 61 19 62 20 /*@unused@*/ 63 //static char cvsid[] = "$Id : libmondo-mountlist.c,v 1.2 2004/06/10 15:29:12 hugo Exp$";21 //static char cvsid[] = "$Id$"; 64 22 65 23 /** … … 85 43 * @see evaluate_mountlist 86 44 */ 87 int evaluate_drive_within_mountlist 88 45 int evaluate_drive_within_mountlist(struct mountlist_itself *mountlist, 46 char *drive, char *flaws_str) 89 47 #ifdef __FreeBSD__ 90 48 { 91 49 // FreeBSD-specific version of evaluate_drive_within_mountlist() 92 /*@ int ************************************************************* */93 50 /*@ int ************************************************************* */ 51 int prev_part_no = 0; 94 52 int curr_part_no = 0; 95 53 int pos = 0, npos = 0; … … 102 60 int foundsome = FALSE; 103 61 104 /*@ buffers ******************************************************** */105 char tmp[MAX_STR_LEN];106 char device[MAX_STR_LEN];107 char mountpoint[MAX_STR_LEN];108 109 /*@ long *********************************************************** */110 62 /*@ buffers ******************************************************** */ 63 char *tmp; 64 char *device; 65 // BERLIOS : useless ? char *mountpoint; 66 67 /*@ long *********************************************************** */ 68 long physical_drive_size = 0; 111 69 long amount_allocated = 0; 112 70 113 /*@ pointers ******************************************************* */71 /*@ pointers ******************************************************* */ 114 72 char *part_table_fmt; 115 73 116 /*@ initialize ******************************************************/ 117 flaws_str[0] = '\0'; 118 prev_part_no = 0; 119 tmp[0] = '\0'; 120 121 122 physical_drive_size = get_phys_size_of_drive (drive); 123 124 if (physical_drive_size < 0) 125 { 126 sprintf (tmp, " %s does not exist.", drive); 127 strcat (flaws_str, tmp); 128 } 129 else 130 { 131 sprintf (tmp, "%s is %ld MB", drive, physical_drive_size); 132 } 133 log_it (tmp); 134 135 136 /* check DD */ 137 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 138 sprintf (device, "%s%c", drive, cur_sp_no); 139 if (find_device_in_mountlist (mountlist, device) >= 0) 140 foundsome = TRUE; 141 } 142 if (foundsome) { 143 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 144 sprintf (device, "%s%c", drive, cur_sp_no); 145 pos = find_device_in_mountlist (mountlist, device); 146 if (pos < 0) 147 { 148 continue; 149 } 150 strcpy (mountpoint, mountlist->el[pos].mountpoint); 151 /* is it too big? */ 152 if (curr_part_no > 'h') 153 { 154 sprintf (tmp, " Can only have up to 'h' in disklabel."); 155 log_it (tmp); 156 strcat (flaws_str, tmp); 157 res++; 158 } 159 /* does partition /dev/adXsYZ exist more than once in the mountlist? */ 160 for (i = 0, mountpoint_copies = 0, device_copies = 0; 161 i < mountlist->entries; i++) 162 { 163 if (!strcmp (device, mountlist->el[i].device)) 164 { 165 device_copies++; 166 } 167 } 168 if (device_copies > 1) 169 { 170 sprintf (tmp, " %s %s's.", number_to_text (device_copies), device); 171 if (!strstr (flaws_str, tmp)) 172 { 173 log_it (tmp); 174 strcat (flaws_str, tmp); 175 res++; 176 } 177 } 178 /* silly partition size? */ 179 if (mountlist->el[pos].size < 8192 180 && strcmp (mountlist->el[pos].mountpoint, "lvm")) 181 { 182 sprintf (tmp, " %s is tiny!", device); 183 log_it (tmp); 184 strcat (flaws_str, tmp); 185 res++; 186 } 187 /* mountpoint should begin with / unless it is swap, lvm or raid */ 188 if (strcmp (mountlist->el[pos].mountpoint, "swap") 189 && strcmp (mountlist->el[pos].mountpoint, "lvm") 190 && strcmp (mountlist->el[pos].mountpoint, "raid") 191 && strcmp (mountlist->el[pos].mountpoint, "image") 192 && strcmp (mountlist->el[pos].mountpoint, "none") 193 && mountlist->el[pos].mountpoint[0] != '/') 194 { 195 sprintf (tmp, " %s has a weird mountpoint.", device); 196 log_it (tmp); 197 strcat (flaws_str, tmp); 198 res++; 199 } 200 /* is format sensible? */ 201 if (!is_this_a_valid_disk_format (mountlist->el[pos].format)) 202 { 203 sprintf (tmp, " %s has unsupported format.", device); 204 log_it (tmp); 205 strcat (flaws_str, tmp); 206 res++; 207 } 208 amount_allocated += mountlist->el[pos].size / 1024; 209 prev_sp_no = cur_sp_no; 210 } 211 } 212 213 npos = pos = 0; 214 for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) 215 { 216 sprintf (device, "%ss%d", drive, curr_part_no); 217 pos = find_device_in_mountlist (mountlist, device); 218 npos = 0; 219 for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) { 220 sprintf (device, "%ss%i%c", device, curr_part_no, cur_sp_no); 221 if (find_device_in_mountlist (mountlist, device) >= 0) npos++; 222 } 223 if (((pos >= 0) || npos) && foundsome) { 224 sprintf (flaws_str + strlen (flaws_str), " %s has both DD and PC-style partitions.", drive); 225 return ++res; // fatal error 226 } 227 228 sprintf (device, "%ss%d", drive, curr_part_no); 229 strcpy (mountpoint, mountlist->el[pos].mountpoint); 230 if (pos > 0 && !npos) { 231 /* gap in the partition list? */ 232 if (curr_part_no - prev_part_no > 1) 233 { 234 if (prev_part_no == 0) 235 { 236 sprintf (tmp, " Gap prior to %s.", device); 237 log_it (tmp); 238 strcat (flaws_str, tmp); 239 res++; 240 } 241 else if (curr_part_no > 5 242 || (curr_part_no <= 4 && prev_part_no > 0)) 243 { 244 sprintf (tmp, " Gap between %ss%d and %d.", drive, prev_part_no, 245 curr_part_no); 246 log_it (tmp); 247 strcat (flaws_str, tmp); 248 res++; 249 } 250 } 251 /* GPT allows more than 4 primary partitions */ 252 part_table_fmt = which_partition_format(drive); 253 /* no spare primary partitions to help accommodate the logical(s)? */ 254 if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt,"MBR") == 0)) 255 { 256 sprintf (tmp, " Partition %ss4 is occupied.", drive); 257 log_it (tmp); 258 strcat (flaws_str, tmp); 259 res++; 260 } 261 /* does partition /dev/adXsY exist more than once in the mountlist? */ 262 for (i = 0, mountpoint_copies = 0, device_copies = 0; 263 i < mountlist->entries; i++) 264 { 265 if (!strcmp (device, mountlist->el[i].device)) 266 { 267 device_copies++; 268 } 269 } 270 if (device_copies > 1) 271 { 272 sprintf (tmp, " %s %s's.", number_to_text (device_copies), device); 273 if (!strstr (flaws_str, tmp)) 274 { 275 log_it (tmp); 276 strcat (flaws_str, tmp); 277 res++; 278 } 279 } 280 /* silly partition size? */ 281 if (mountlist->el[pos].size < 8192 282 && strcmp (mountlist->el[pos].mountpoint, "lvm")) 283 { 284 sprintf (tmp, " %s is tiny!", device); 285 log_it (tmp); 286 strcat (flaws_str, tmp); 287 res++; 288 } 289 /* mountpoint should begin with / unless it is swap, lvm or raid */ 290 if (strcmp (mountlist->el[pos].mountpoint, "swap") 291 && strcmp (mountlist->el[pos].mountpoint, "lvm") 292 && strcmp (mountlist->el[pos].mountpoint, "raid") 293 && strcmp (mountlist->el[pos].mountpoint, "image") 294 && strcmp (mountlist->el[pos].mountpoint, "none") 295 && mountlist->el[pos].mountpoint[0] != '/') 296 { 297 sprintf (tmp, " %s has a weird mountpoint.", device); 298 log_it (tmp); 299 strcat (flaws_str, tmp); 300 res++; 301 } 302 /* is format sensible? */ 303 if (!is_this_a_valid_disk_format (mountlist->el[pos].format)) 304 { 305 sprintf (tmp, " %s has unsupported format.", device); 306 log_it (tmp); 307 strcat (flaws_str, tmp); 308 res++; 309 } 310 } else { 311 /* Check subpartitions */ 312 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 313 sprintf (device, "%ss%d%c", drive, curr_part_no, cur_sp_no); 314 pos = find_device_in_mountlist (mountlist, device); 315 if (pos < 0) 316 { 317 continue; 318 } 319 strcpy (mountpoint, mountlist->el[pos].mountpoint); 320 /* is it too big? */ 321 if (curr_part_no > 'h') 322 { 323 sprintf (tmp, " Can only have up to 'h' in disklabel."); 324 log_it (tmp); 325 strcat (flaws_str, tmp); 326 res++; 327 } 328 /* does partition /dev/adXsYZ exist more than once in the mountlist? */ 329 for (i = 0, mountpoint_copies = 0, device_copies = 0; 330 i < mountlist->entries; i++) 331 { 332 if (!strcmp (device, mountlist->el[i].device)) 333 { 334 device_copies++; 335 } 336 } 337 if (device_copies > 1) 338 { 339 sprintf (tmp, " %s %s's.", number_to_text (device_copies), device); 340 if (!strstr (flaws_str, tmp)) 341 { 342 log_it (tmp); 343 strcat (flaws_str, tmp); 344 res++; 345 } 346 } 347 /* silly partition size? */ 348 if (mountlist->el[pos].size < 8192 349 && strcmp (mountlist->el[pos].mountpoint, "lvm")) 350 { 351 sprintf (tmp, " %s is tiny!", device); 352 log_it (tmp); 353 strcat (flaws_str, tmp); 354 res++; 355 } 356 /* mountpoint should begin with / unless it is swap, lvm or raid */ 357 if (strcmp (mountlist->el[pos].mountpoint, "swap") 358 && strcmp (mountlist->el[pos].mountpoint, "lvm") 359 && strcmp (mountlist->el[pos].mountpoint, "raid") 360 && strcmp (mountlist->el[pos].mountpoint, "image") 361 && strcmp (mountlist->el[pos].mountpoint, "none") 362 && mountlist->el[pos].mountpoint[0] != '/') 363 { 364 sprintf (tmp, " %s has a weird mountpoint.", device); 365 log_it (tmp); 366 strcat (flaws_str, tmp); 367 res++; 368 } 369 /* is format sensible? */ 370 if (!is_this_a_valid_disk_format (mountlist->el[pos].format)) 371 { 372 sprintf (tmp, " %s has unsupported format.", device); 373 log_it (tmp); 374 strcat (flaws_str, tmp); 375 res++; 376 } 377 amount_allocated += mountlist->el[pos].size / 1024; 378 prev_sp_no = cur_sp_no; 379 } 380 } 381 382 /* OK, continue with main loop */ 383 amount_allocated += mountlist->el[pos].size / 1024; 384 prev_part_no = curr_part_no; 385 } 386 387 /* Over-allocated the disk? Unallocated space on disk? */ 388 if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high? 389 { 390 sprintf (tmp, " %ld MB over-allocated on %s.", 391 amount_allocated - physical_drive_size, drive); 392 log_it (tmp); 393 strcat (flaws_str, tmp); 394 res++; 395 } 396 else if (amount_allocated < physical_drive_size - 1) 397 { /* NOT AN ERROR, JUST A WARNING :-) */ 398 sprintf (tmp, " %ld MB unallocated on %s.", 399 physical_drive_size - amount_allocated, drive); 400 log_it (tmp), strcat (flaws_str, tmp); 401 } 402 if (res) 403 { 404 return (FALSE); 405 } 406 else 407 { 408 return (TRUE); 409 } 74 /*@ initialize ***************************************************** */ 75 flaws_str[0] = '\0'; 76 prev_part_no = 0; 77 // BERLIOS: tmp[0] = '\0'; 78 79 80 physical_drive_size = get_phys_size_of_drive(drive); 81 82 if (physical_drive_size < 0) { 83 asprintf(&tmp, " %s does not exist.", drive); 84 strcat(flaws_str, tmp); 85 } else { 86 asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size); 87 } 88 log_it(tmp); 89 paranoid_free(tmp); 90 91 92 /* check DD */ 93 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 94 asprintf(&device, "%s%c", drive, cur_sp_no); 95 if (find_device_in_mountlist(mountlist, device) >= 0) 96 foundsome = TRUE; 97 paranoid_free(device); 98 } 99 if (foundsome) { 100 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 101 asprintf(&device, "%s%c", drive, cur_sp_no); 102 pos = find_device_in_mountlist(mountlist, device); 103 if (pos < 0) { 104 continue; 105 } 106 // BERLIOS : useless ? asprintf(&mountpoint, mountlist->el[pos].mountpoint); 107 /* is it too big? */ 108 if (curr_part_no > 'h') { 109 asprintf(&tmp, " Can only have up to 'h' in disklabel."); 110 log_it(tmp); 111 strcat(flaws_str, tmp); 112 paranoid_free(tmp); 113 res++; 114 } 115 /* does partition /dev/adXsYZ exist more than once in the mountlist? */ 116 for (i = 0, mountpoint_copies = 0, device_copies = 0; 117 i < mountlist->entries; i++) { 118 if (!strcmp(device, mountlist->el[i].device)) { 119 device_copies++; 120 } 121 } 122 if (device_copies > 1) { 123 asprintf(&tmp, " %s %s's.", number_to_text(device_copies), 124 device); 125 if (!strstr(flaws_str, tmp)) { 126 log_it(tmp); 127 strcat(flaws_str, tmp); 128 res++; 129 } 130 paranoid_free(tmp); 131 } 132 /* silly partition size? */ 133 if (mountlist->el[pos].size < 8192 134 && strcmp(mountlist->el[pos].mountpoint, "lvm")) { 135 asprintf(&tmp, " %s is tiny!", device); 136 log_it(tmp); 137 strcat(flaws_str, tmp); 138 paranoid_free(tmp); 139 res++; 140 } 141 /* mountpoint should begin with / unless it is swap, lvm or raid */ 142 if (strcmp(mountlist->el[pos].mountpoint, "swap") 143 && strcmp(mountlist->el[pos].mountpoint, "lvm") 144 && strcmp(mountlist->el[pos].mountpoint, "raid") 145 && strcmp(mountlist->el[pos].mountpoint, "image") 146 && strcmp(mountlist->el[pos].mountpoint, "none") 147 && mountlist->el[pos].mountpoint[0] != '/') { 148 asprintf(&tmp, " %s has a weird mountpoint.", device); 149 log_it(tmp); 150 strcat(flaws_str, tmp); 151 paranoid_free(tmp); 152 res++; 153 } 154 /* is format sensible? */ 155 if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) { 156 asprintf(&tmp, " %s has unsupported format.", device); 157 log_it(tmp); 158 strcat(flaws_str, tmp); 159 paranoid_free(tmp); 160 res++; 161 } 162 amount_allocated += mountlist->el[pos].size / 1024; 163 prev_sp_no = cur_sp_no; 164 165 paranoid_free(device); 166 } 167 } 168 169 npos = pos = 0; 170 for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) { 171 asprintf(&device, "%ss%d", drive, curr_part_no); 172 pos = find_device_in_mountlist(mountlist, device); 173 npos = 0; 174 for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) { 175 sprintf(device, "%ss%i%c", device, curr_part_no, cur_sp_no); 176 if (find_device_in_mountlist(mountlist, device) >= 0) 177 npos++; 178 } 179 paranoid_free(device); 180 181 if (((pos >= 0) || npos) && foundsome) { 182 sprintf(flaws_str + strlen(flaws_str), 183 " %s has both DD and PC-style partitions.", drive); 184 return ++res; // fatal error 185 } 186 187 // BERLIOS : useless ? asprintf(&mountpoint, mountlist->el[pos].mountpoint); 188 if (pos > 0 && !npos) { 189 asprintf(&device, "%ss%d", drive, curr_part_no); 190 /* gap in the partition list? */ 191 if (curr_part_no - prev_part_no > 1) { 192 if (prev_part_no == 0) { 193 asprintf(&tmp, " Gap prior to %s.", device); 194 log_it(tmp); 195 strcat(flaws_str, tmp); 196 paranoid_free(tmp); 197 res++; 198 } else if (curr_part_no > 5 199 || (curr_part_no <= 4 && prev_part_no > 0)) { 200 asprintf(&tmp, " Gap between %ss%d and %d.", drive, 201 prev_part_no, curr_part_no); 202 log_it(tmp); 203 strcat(flaws_str, tmp); 204 paranoid_free(tmp); 205 res++; 206 } 207 } 208 /* GPT allows more than 4 primary partitions */ 209 part_table_fmt = which_partition_format(drive); 210 /* no spare primary partitions to help accommodate the logical(s)? */ 211 if ((curr_part_no >= 5 && prev_part_no == 4) 212 && (strcmp(part_table_fmt, "MBR") == 0)) { 213 asprintf(&tmp, " Partition %ss4 is occupied.", drive); 214 log_it(tmp); 215 strcat(flaws_str, tmp); 216 paranoid_free(tmp); 217 res++; 218 } 219 /* does partition /dev/adXsY exist more than once in the mountlist? */ 220 for (i = 0, mountpoint_copies = 0, device_copies = 0; 221 i < mountlist->entries; i++) { 222 if (!strcmp(device, mountlist->el[i].device)) { 223 device_copies++; 224 } 225 } 226 if (device_copies > 1) { 227 asprintf(&tmp, " %s %s's.", number_to_text(device_copies), 228 device); 229 if (!strstr(flaws_str, tmp)) { 230 log_it(tmp); 231 strcat(flaws_str, tmp); 232 res++; 233 } 234 paranoid_free(tmp); 235 } 236 /* silly partition size? */ 237 if (mountlist->el[pos].size < 8192 238 && strcmp(mountlist->el[pos].mountpoint, "lvm")) { 239 asprintf(&tmp, " %s is tiny!", device); 240 log_it(tmp); 241 strcat(flaws_str, tmp); 242 paranoid_free(tmp); 243 res++; 244 } 245 /* mountpoint should begin with / unless it is swap, lvm or raid */ 246 if (strcmp(mountlist->el[pos].mountpoint, "swap") 247 && strcmp(mountlist->el[pos].mountpoint, "lvm") 248 && strcmp(mountlist->el[pos].mountpoint, "raid") 249 && strcmp(mountlist->el[pos].mountpoint, "image") 250 && strcmp(mountlist->el[pos].mountpoint, "none") 251 && mountlist->el[pos].mountpoint[0] != '/') { 252 asprintf(&tmp, " %s has a weird mountpoint.", device); 253 log_it(tmp); 254 strcat(flaws_str, tmp); 255 paranoid_free(tmp); 256 res++; 257 } 258 /* is format sensible? */ 259 if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) { 260 asprintf(&tmp, " %s has unsupported format.", device); 261 log_it(tmp); 262 strcat(flaws_str, tmp); 263 paranoid_free(tmp); 264 res++; 265 } 266 paranoid_free(device); 267 } else { 268 /* Check subpartitions */ 269 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 270 asprintf(&device, "%ss%d%c", drive, curr_part_no, cur_sp_no); 271 pos = find_device_in_mountlist(mountlist, device); 272 if (pos < 0) { 273 continue; 274 } 275 // BERLIOS : useless ? asprintf(&mountpoint, mountlist->el[pos].mountpoint); 276 /* is it too big? */ 277 if (curr_part_no > 'h') { 278 asprintf(&tmp, " Can only have up to 'h' in disklabel."); 279 log_it(tmp); 280 strcat(flaws_str, tmp); 281 paranoid_free(tmp); 282 res++; 283 } 284 /* does partition /dev/adXsYZ exist more than once in the mountlist? */ 285 for (i = 0, mountpoint_copies = 0, device_copies = 0; 286 i < mountlist->entries; i++) { 287 if (!strcmp(device, mountlist->el[i].device)) { 288 device_copies++; 289 } 290 } 291 if (device_copies > 1) { 292 asprintf(&tmp, " %s %s's.", 293 number_to_text(device_copies), device); 294 if (!strstr(flaws_str, tmp)) { 295 log_it(tmp); 296 strcat(flaws_str, tmp); 297 res++; 298 } 299 paranoid_free(tmp); 300 } 301 /* silly partition size? */ 302 if (mountlist->el[pos].size < 8192 303 && strcmp(mountlist->el[pos].mountpoint, "lvm")) { 304 asprintf(&tmp, " %s is tiny!", device); 305 log_it(tmp); 306 strcat(flaws_str, tmp); 307 paranoid_free(tmp); 308 res++; 309 } 310 /* mountpoint should begin with / unless it is swap, lvm or raid */ 311 if (strcmp(mountlist->el[pos].mountpoint, "swap") 312 && strcmp(mountlist->el[pos].mountpoint, "lvm") 313 && strcmp(mountlist->el[pos].mountpoint, "raid") 314 && strcmp(mountlist->el[pos].mountpoint, "image") 315 && strcmp(mountlist->el[pos].mountpoint, "none") 316 && mountlist->el[pos].mountpoint[0] != '/') { 317 asprintf(&tmp, " %s has a weird mountpoint.", device); 318 log_it(tmp); 319 strcat(flaws_str, tmp); 320 paranoid_free(tmp); 321 res++; 322 } 323 /* is format sensible? */ 324 if (!is_this_a_valid_disk_format 325 (mountlist->el[pos].format)) { 326 asprintf(&tmp, " %s has unsupported format.", device); 327 log_it(tmp); 328 strcat(flaws_str, tmp); 329 paranoid_free(tmp); 330 res++; 331 } 332 amount_allocated += mountlist->el[pos].size / 1024; 333 prev_sp_no = cur_sp_no; 334 paranoid_free(device); 335 } 336 } 337 338 /* OK, continue with main loop */ 339 amount_allocated += mountlist->el[pos].size / 1024; 340 prev_part_no = curr_part_no; 341 } 342 343 /* Over-allocated the disk? Unallocated space on disk? */ 344 if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high? 345 { 346 asprintf(&tmp, " %ld MB over-allocated on %s.", 347 amount_allocated - physical_drive_size, drive); 348 log_it(tmp); 349 strcat(flaws_str, tmp); 350 paranoid_free(tmp); 351 res++; 352 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 353 asprintf(&tmp, " %ld MB unallocated on %s.", 354 physical_drive_size - amount_allocated, drive); 355 log_it(tmp); 356 strcat(flaws_str, tmp); 357 paranoid_free(tmp); 358 } 359 if (res) { 360 return (FALSE); 361 } else { 362 return (TRUE); 363 } 410 364 } 411 365 … … 414 368 { 415 369 416 /*@ int ************************************************************* */417 370 /*@ int ************************************************************* */ 371 int prev_part_no = 0; 418 372 int curr_part_no = 0; 419 373 int pos = 0; … … 423 377 int i = 0; 424 378 425 /*@ buffers ******************************************************** */426 379 /*@ buffers ******************************************************** */ 380 char *tmp; 427 381 char *device; 428 382 char *mountpoint; 429 383 430 /*@ long *********************************************************** */431 384 /*@ long *********************************************************** */ 385 long physical_drive_size = 0; 432 386 long amount_allocated = 0; 433 387 434 /*@ pointers ******************************************************* */388 /*@ pointers ******************************************************* */ 435 389 char *part_table_fmt; 436 390 437 /*@ initialize ******************************************************/ 438 assert_string_is_neither_NULL_nor_zerolength(drive); 439 assert(mountlist!=NULL); 440 assert(flaws_str!=NULL); 441 442 malloc_string(tmp); 443 malloc_string(device); 444 malloc_string(mountpoint); 445 flaws_str[0] = '\0'; 446 prev_part_no = 0; 447 tmp[0] = '\0'; 448 449 450 physical_drive_size = get_phys_size_of_drive (drive); 451 452 if (physical_drive_size < 0) 453 { 454 sprintf (tmp, " %s does not exist.", drive); 455 strcat (flaws_str, tmp); 456 res++; 457 log_msg(1, tmp); 458 goto endoffunc; 459 } 460 else 461 { 462 sprintf (tmp, "%s is %ld MB", drive, physical_drive_size); 463 log_it (tmp); 464 } 465 466 for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) 467 { 468 sprintf (device, "%s%d", drive, curr_part_no); 469 pos = find_device_in_mountlist (mountlist, device); 470 if (pos < 0) 471 { 472 continue; 473 } 474 if (physical_drive_size < 0) 475 { 476 sprintf(tmp, " %s refers to non-existent hardware.", device); 477 strcat (flaws_str, tmp); 478 res++; 479 continue; 480 } 481 strcpy (mountpoint, mountlist->el[pos].mountpoint); 482 /* gap in the partition list? */ 483 if (curr_part_no - prev_part_no > 1) 484 { 485 if (prev_part_no == 0) 486 { 487 sprintf (tmp, " Gap prior to %s.", device); 488 log_it (tmp); 489 strcat (flaws_str, tmp); 490 res++; 491 } 492 else if (curr_part_no > 5 493 || (curr_part_no <= 4 && prev_part_no > 0)) 494 { 495 sprintf (tmp, " Gap between %s%d and %d.", drive, prev_part_no, 496 curr_part_no); 497 log_it (tmp); 498 strcat (flaws_str, tmp); 499 res++; 500 } 501 } 502 /* GPT allows more than 4 primary partitions */ 503 part_table_fmt = which_partition_format(drive); 504 /* no spare primary partitions to help accommodate the logical(s)? */ 505 if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt,"MBR") == 0)) 506 { 507 sprintf (tmp, " Partition %s4 is occupied.", drive); 508 log_it (tmp); 509 strcat (flaws_str, tmp); 510 res++; 511 } 512 /* does partition /dev/hdNX exist more than once in the mountlist? */ 513 for (i = 0, mountpoint_copies = 0, device_copies = 0; 514 i < mountlist->entries; i++) 515 { 516 if (!strcmp (device, mountlist->el[i].device)) 517 { 518 device_copies++; 519 } 520 } 521 if (device_copies > 1) 522 { 523 sprintf (tmp, " %s %s's.", number_to_text (device_copies), device); 524 if (!strstr (flaws_str, tmp)) 525 { 526 log_it (tmp); 527 strcat (flaws_str, tmp); 528 res++; 529 } 530 } 531 /* silly partition size? */ 532 if (mountlist->el[pos].size < 8192 533 && strcmp (mountlist->el[pos].mountpoint, "lvm")) 534 { 535 sprintf (tmp, " %s is tiny!", device); 536 log_it (tmp); 537 strcat (flaws_str, tmp); 538 res++; 539 } 540 /* mountpoint should begin with / unless it is swap, lvm or raid */ 541 if (strcmp (mountlist->el[pos].mountpoint, "swap") 542 && strcmp (mountlist->el[pos].mountpoint, "lvm") 543 && strcmp (mountlist->el[pos].mountpoint, "raid") 544 && strcmp (mountlist->el[pos].mountpoint, "image") 545 && mountlist->el[pos].mountpoint[0] != '/') 546 { 547 sprintf (tmp, " %s has a weird mountpoint.", device); 548 log_it (tmp); 549 strcat (flaws_str, tmp); 550 res++; 551 } 552 /* is format sensible? */ 553 if (!is_this_a_valid_disk_format (mountlist->el[pos].format)) 554 { 555 sprintf (tmp, " %s has unsupported format.", device); 556 log_it (tmp); 557 strcat (flaws_str, tmp); 558 res++; 559 } 560 /* OK, continue with main loop */ 561 amount_allocated += mountlist->el[pos].size / 1024; 562 prev_part_no = curr_part_no; 563 } 564 565 /* Over-allocated the disk? Unallocated space on disk? */ 566 if (amount_allocated > physical_drive_size + 1) 567 { 568 sprintf (tmp, " %ld MB over-allocated on %s.", 569 amount_allocated - physical_drive_size, drive); 570 log_it (tmp); 571 strcat (flaws_str, tmp); 572 res++; 573 } 574 else if (amount_allocated < physical_drive_size - 1) 575 { /* NOT AN ERROR, JUST A WARNING :-) */ 576 sprintf (tmp, " %ld MB unallocated on %s.", 577 physical_drive_size - amount_allocated, drive); 578 log_it (tmp), strcat (flaws_str, tmp); 579 } 580 581 endoffunc: 582 paranoid_free(tmp); 583 paranoid_free(device); 584 paranoid_free(mountpoint); 585 586 if (res) 587 { 588 return (FALSE); 589 } 590 else 591 { 592 return (TRUE); 593 } 391 /*@ initialize ***************************************************** */ 392 assert_string_is_neither_NULL_nor_zerolength(drive); 393 assert(mountlist != NULL); 394 assert(flaws_str != NULL); 395 396 flaws_str[0] = '\0'; 397 prev_part_no = 0; 398 // BERLIOS : useless ? tmp[0] = '\0'; 399 400 401 physical_drive_size = get_phys_size_of_drive(drive); 402 403 if (physical_drive_size < 0) { 404 asprintf(&tmp, " %s does not exist.", drive); 405 strcat(flaws_str, tmp); 406 res++; 407 log_msg(1, tmp); 408 paranoid_free(tmp); 409 return(FALSE); 410 } else { 411 asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size); 412 log_it(tmp); 413 paranoid_free(tmp); 414 } 415 416 for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) { 417 asprintf(&device, "%s%d", drive, curr_part_no); 418 pos = find_device_in_mountlist(mountlist, device); 419 if (pos < 0) { 420 continue; 421 } 422 if (physical_drive_size < 0) { 423 asprintf(&tmp, " %s refers to non-existent hardware.", device); 424 strcat(flaws_str, tmp); 425 res++; 426 paranoid_free(tmp); 427 continue; 428 } 429 // BERLIOS : useless ? strcpy(mountpoint, mountlist->el[pos].mountpoint); 430 /* gap in the partition list? */ 431 if (curr_part_no - prev_part_no > 1) { 432 if (prev_part_no == 0) { 433 asprintf(&tmp, " Gap prior to %s.", device); 434 log_it(tmp); 435 strcat(flaws_str, tmp); 436 paranoid_free(tmp); 437 res++; 438 } else if (curr_part_no > 5 439 || (curr_part_no <= 4 && prev_part_no > 0)) { 440 asprintf(&tmp, " Gap between %s%d and %d.", drive, 441 prev_part_no, curr_part_no); 442 log_it(tmp); 443 strcat(flaws_str, tmp); 444 paranoid_free(tmp); 445 res++; 446 } 447 } 448 /* GPT allows more than 4 primary partitions */ 449 part_table_fmt = which_partition_format(drive); 450 /* no spare primary partitions to help accommodate the logical(s)? */ 451 if ((curr_part_no >= 5 && prev_part_no == 4) 452 && (strcmp(part_table_fmt, "MBR") == 0)) { 453 asprintf(&tmp, " Partition %s4 is occupied.", drive); 454 log_it(tmp); 455 strcat(flaws_str, tmp); 456 paranoid_free(tmp); 457 res++; 458 } 459 /* does partition /dev/hdNX exist more than once in the mountlist? */ 460 for (i = 0, mountpoint_copies = 0, device_copies = 0; 461 i < mountlist->entries; i++) { 462 if (!strcmp(device, mountlist->el[i].device)) { 463 device_copies++; 464 } 465 } 466 if (device_copies > 1) { 467 asprintf(&tmp, " %s %s's.", number_to_text(device_copies), 468 device); 469 if (!strstr(flaws_str, tmp)) { 470 log_it(tmp); 471 strcat(flaws_str, tmp); 472 res++; 473 } 474 paranoid_free(tmp); 475 } 476 /* silly partition size? */ 477 if (mountlist->el[pos].size < 8192 478 && strcmp(mountlist->el[pos].mountpoint, "lvm")) { 479 asprintf(&tmp, " %s is tiny!", device); 480 log_it(tmp); 481 strcat(flaws_str, tmp); 482 paranoid_free(tmp); 483 res++; 484 } 485 /* mountpoint should begin with / unless it is swap, lvm or raid */ 486 if (strcmp(mountlist->el[pos].mountpoint, "swap") 487 && strcmp(mountlist->el[pos].mountpoint, "lvm") 488 && strcmp(mountlist->el[pos].mountpoint, "raid") 489 && strcmp(mountlist->el[pos].mountpoint, "image") 490 && mountlist->el[pos].mountpoint[0] != '/') { 491 asprintf(&tmp, " %s has a weird mountpoint.", device); 492 log_it(tmp); 493 strcat(flaws_str, tmp); 494 paranoid_free(tmp); 495 res++; 496 } 497 /* is format sensible? */ 498 if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) { 499 asprintf(&tmp, " %s has unsupported format.", device); 500 log_it(tmp); 501 strcat(flaws_str, tmp); 502 paranoid_free(tmp); 503 res++; 504 } 505 /* OK, continue with main loop */ 506 amount_allocated += mountlist->el[pos].size / 1024; 507 prev_part_no = curr_part_no; 508 paranoid_free(device); 509 } 510 511 /* Over-allocated the disk? Unallocated space on disk? */ 512 if (amount_allocated > physical_drive_size + 1) { 513 asprintf(&tmp, " %ld MB over-allocated on %s.", 514 amount_allocated - physical_drive_size, drive); 515 log_it(tmp); 516 strcat(flaws_str, tmp); 517 paranoid_free(tmp); 518 res++; 519 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 520 asprintf(&tmp, " %ld MB unallocated on %s.", 521 physical_drive_size - amount_allocated, drive); 522 log_it(tmp); 523 strcat(flaws_str, tmp); 524 paranoid_free(tmp); 525 } 526 527 if (res) { 528 return (FALSE); 529 } else { 530 return (TRUE); 531 } 594 532 } 595 533 #endif 596 597 534 598 535 … … 608 545 */ 609 546 int 610 evaluate_mountlist 611 612 { 613 614 /*@ buffer *********************************************************** */615 547 evaluate_mountlist(struct mountlist_itself *mountlist, char *flaws_str_A, 548 char *flaws_str_B, char *flaws_str_C) 549 { 550 551 /*@ buffer *********************************************************** */ 552 struct list_of_disks *drivelist; 616 553 char *tmp; 554 char *tmp1; 617 555 char *flaws_str; 618 556 619 /*@ int ************************************************************** */557 /*@ int ************************************************************** */ 620 558 int i = 0; 621 559 int res = 0; 622 560 623 /*@ initialize ******************************************************* */624 625 626 malloc_string(tmp);627 malloc_string(flaws_str);628 assert(mountlist!=NULL);629 assert(flaws_str_A!=NULL);630 assert(flaws_str_B!=NULL); 631 assert(flaws_str_C!=NULL);632 flaws_str[0] = '\0'; 633 634 make_list_of_drives_in_mountlist (mountlist, drivelist); 635 636 log_it ("Evaluating mountlist..."); 637 638 for (i = 0; i < drivelist->entries; i++) 639 { 640 if (strstr (drivelist->el[i].device, DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) 641 {642 sprintf (tmp, " Not evaluating %s (I don't know how yet)",643 drivelist->el[i].device);644 log_it (tmp);645 tmp[0] = '\0';646 }647 else 648 {649 if (!evaluate_drive_within_mountlist650 (mountlist, drivelist->el[i].device, tmp))651 {652 res++;653 }654 }655 strcat (flaws_str, tmp);656 657 res += look_for_duplicate_mountpoints(mountlist, flaws_str);561 /*@ initialize ******************************************************* */ 562 563 drivelist = malloc(sizeof(struct list_of_disks)); 564 assert(mountlist != NULL); 565 assert(flaws_str_A != NULL); 566 assert(flaws_str_B != NULL); 567 assert(flaws_str_C != NULL); 568 569 asprintf(&flaws_str, ""); 570 571 make_list_of_drives_in_mountlist(mountlist, drivelist); 572 573 log_it("Evaluating mountlist..."); 574 575 for (i = 0; i < drivelist->entries; i++) { 576 if (strstr 577 (drivelist->el[i].device, 578 DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) { 579 asprintf(&tmp, " Not evaluating %s (I don't know how yet)", 580 drivelist->el[i].device); 581 log_it(tmp); 582 } else { 583 asprintf(&tmp, ""); 584 // BERLIOS : tmp was NOT initialized ??? 585 if (!evaluate_drive_within_mountlist 586 (mountlist, drivelist->el[i].device, tmp)) { 587 res++; 588 } 589 } 590 asprintf(&tmp1, "%s%s", flaws_str, tmp); 591 paranoid_free(tmp); 592 paranoid_free(flaws_str); 593 flaws_str = tmp1; 594 } 595 res += look_for_duplicate_mountpoints(mountlist, flaws_str); 658 596 /* res+=look_for_weird_formats(mountlist,flaws_str); .. not necessary, now that we can check to see 659 597 which formarts are actually _supported_ by the kernel */ 660 661 662 598 /* log_it(flaws_str); */ 599 return (spread_flaws_across_three_lines 600 (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res)); 663 601 } 664 602 … … 672 610 */ 673 611 int 674 find_device_in_mountlist (struct mountlist_itself *mountlist, char *device) 675 { 676 677 /*@ int ***************************************************************/ 678 int i = 0; 679 char*tmp; 680 char*flaws_str; 681 682 malloc_string(tmp); 683 malloc_string(flaws_str); 684 685 assert(mountlist!=NULL); 686 assert_string_is_neither_NULL_nor_zerolength(device); 687 for (i = 0; 688 i < mountlist->entries 689 && strcmp (mountlist->el[i].device, device) != 0; i++); 690 691 paranoid_free(tmp); 692 paranoid_free(flaws_str); 693 694 if (i == mountlist->entries) 695 { 696 return (-1); 697 } 698 else 699 { 700 return (i); 701 } 702 } 703 704 705 612 find_device_in_mountlist(struct mountlist_itself *mountlist, char *device) 613 { 614 615 /*@ int ************************************************************** */ 616 int i = 0; 617 618 assert(mountlist != NULL); 619 assert_string_is_neither_NULL_nor_zerolength(device); 620 for (i = 0; 621 i < mountlist->entries 622 && strcmp(mountlist->el[i].device, device) != 0; i++); 623 624 if (i == mountlist->entries) { 625 return (-1); 626 } else { 627 return (i); 628 } 629 } 706 630 707 631 … … 713 637 */ 714 638 int 715 look_for_duplicate_mountpoints 716 char *flaws_str)717 { 718 719 /*@ int ************************************************************* */720 639 look_for_duplicate_mountpoints(struct mountlist_itself *mountlist, 640 char *flaws_str) 641 { 642 643 /*@ int ************************************************************* */ 644 int res = 0; 721 645 int currline = 0; 722 646 int i = 0; … … 724 648 int last_copy = 0; 725 649 726 /*@ buffetr ********************************************************* */727 650 /*@ buffetr ********************************************************* */ 651 char *curr_mountpoint; 728 652 char *tmp; 729 653 730 malloc_string(curr_mountpoint); 731 malloc_string(tmp); 732 assert(mountlist!=NULL); 733 assert(flaws_str!=NULL); 734 for (currline = 0; currline < mountlist->entries; currline++) 735 { 736 strcpy (curr_mountpoint, mountlist->el[currline].mountpoint); 737 for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries; i++) 738 { 739 if (!strcmp (mountlist->el[i].mountpoint, curr_mountpoint) 740 && strcmp (mountlist->el[i].mountpoint, "lvm") 741 && strcmp (mountlist->el[i].mountpoint, "swap")) 742 { 743 last_copy = i; 744 copies++; 745 } 746 } 747 if (copies > 1 && last_copy == currline 748 && strcmp (curr_mountpoint, "raid")) 749 { 750 sprintf (tmp, " %s %s's.", number_to_text (copies), 751 curr_mountpoint); 752 strcat (flaws_str, tmp); 753 log_it (tmp); 754 res++; 755 } 756 } 757 paranoid_free(curr_mountpoint); 758 paranoid_free(tmp); 759 return (res); 760 } 654 assert(mountlist != NULL); 655 assert(flaws_str != NULL); 656 for (currline = 0; currline < mountlist->entries; currline++) { 657 asprintf(&curr_mountpoint, mountlist->el[currline].mountpoint); 658 for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries; 659 i++) { 660 if (!strcmp(mountlist->el[i].mountpoint, curr_mountpoint) 661 && strcmp(mountlist->el[i].mountpoint, "lvm") 662 && strcmp(mountlist->el[i].mountpoint, "swap")) { 663 last_copy = i; 664 copies++; 665 } 666 } 667 if (copies > 1 && last_copy == currline 668 && strcmp(curr_mountpoint, "raid")) { 669 asprintf(&tmp, " %s %s's.", number_to_text(copies), 670 curr_mountpoint); 671 strcat(flaws_str, tmp); 672 log_it(tmp); 673 paranoid_free(tmp); 674 res++; 675 } 676 paranoid_free(curr_mountpoint); 677 } 678 return (res); 679 } 680 761 681 762 682 /** … … 768 688 */ 769 689 int 770 look_for_weird_formats 771 { 772 773 /*@ int ************************************************************* */774 int i= 0;690 look_for_weird_formats(struct mountlist_itself *mountlist, char *flaws_str) 691 { 692 693 /*@ int ************************************************************* */ 694 int i = 0; 775 695 int res = 0; 776 696 777 /*@ buffers ********************************************************* */778 697 /*@ buffers ********************************************************* */ 698 char *tmp; 779 699 char *format_sz; 780 700 781 malloc_string(tmp); 782 malloc_string(format_sz); 783 784 assert(mountlist!=NULL); 785 assert(flaws_str!=NULL); 786 787 for (i = 0; i < mountlist->entries; i++) 788 { 789 sprintf (format_sz, " %s ", mountlist->el[i].format); 790 if (!strstr 791 (SANE_FORMATS, format_sz) 792 && strcmp (mountlist->el[i].mountpoint, "image") != 0) 793 { 794 sprintf (tmp, " %s has unknown format.", mountlist->el[i].device); 795 log_it (tmp); 796 strcat (flaws_str, tmp); 797 res++; 798 } 799 else 800 if ((!strcmp (mountlist->el[i].format, "swap") 801 && strcmp (mountlist->el[i].mountpoint, "swap") && strcmp (mountlist->el[i].mountpoint, "none")) 802 || (strcmp (mountlist->el[i].format, "swap") 803 && !strcmp (mountlist->el[i].mountpoint, "swap") && !strcmp (mountlist->el[i].mountpoint, "none"))) 804 { 805 sprintf (tmp, " %s is half-swap.", mountlist->el[i].device); 806 log_it (tmp); 807 strcat (flaws_str, tmp); 808 res++; 809 } 810 } 811 paranoid_free(tmp); 812 paranoid_free(format_sz); 813 return (res); 814 } 815 701 assert(mountlist != NULL); 702 assert(flaws_str != NULL); 703 704 for (i = 0; i < mountlist->entries; i++) { 705 asprintf(&format_sz, " %s ", mountlist->el[i].format); 706 if (!strstr(SANE_FORMATS, format_sz) 707 && strcmp(mountlist->el[i].mountpoint, "image") != 0) { 708 asprintf(&tmp, " %s has unknown format.", 709 mountlist->el[i].device); 710 log_it(tmp); 711 strcat(flaws_str, tmp); 712 paranoid_free(tmp); 713 res++; 714 } else if ((!strcmp(mountlist->el[i].format, "swap") 715 && strcmp(mountlist->el[i].mountpoint, "swap") 716 && strcmp(mountlist->el[i].mountpoint, "none")) 717 || (strcmp(mountlist->el[i].format, "swap") 718 && !strcmp(mountlist->el[i].mountpoint, "swap") 719 && !strcmp(mountlist->el[i].mountpoint, "none"))) { 720 asprintf(&tmp, " %s is half-swap.", mountlist->el[i].device); 721 log_it(tmp); 722 strcat(flaws_str, tmp); 723 paranoid_free(tmp); 724 res++; 725 } 726 paranoid_free(format_sz); 727 } 728 return (res); 729 } 816 730 817 731 … … 823 737 */ 824 738 int 825 make_list_of_drives_in_mountlist (struct mountlist_itself *mountlist, 826 struct list_of_disks *drivelist) 827 { 828 829 /*@ int **************************************************************/ 830 int lino; 831 int noof_drives; 832 int j; 833 834 /*@ buffers **********************************************************/ 835 char *drive; 836 char *tmp; 837 838 long long size; 839 840 malloc_string(drive); 841 malloc_string(tmp); 842 assert(mountlist!=NULL); 843 assert(drivelist!=NULL); 844 log_it ("Making list of drives"); 845 for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) 846 { 847 848 strcpy (drive, mountlist->el[lino].device); 849 if (!strncmp (drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) 850 { 851 sprintf (tmp, 852 "Not putting %s in list of drives: it's a virtual drive", 853 drive); 854 log_msg (8, tmp); 855 continue; 856 } 857 858 size=mountlist->el[lino].size; 859 if ( size == 0 ) 860 { 861 sprintf (tmp, 862 "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", 863 drive); 864 log_msg (8, tmp); 865 continue; 866 } 739 make_list_of_drives_in_mountlist(struct mountlist_itself *mountlist, 740 struct list_of_disks *drivelist) 741 { 742 743 /*@ int ************************************************************* */ 744 int lino; 745 int noof_drives; 746 int j; 747 748 /*@ buffers ********************************************************* */ 749 char *drive; 750 char *tmp; 751 752 long long size; 753 754 assert(mountlist != NULL); 755 assert(drivelist != NULL); 756 log_it("Making list of drives"); 757 for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) { 758 759 asprintf(&drive, mountlist->el[lino].device); 760 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { 761 asprintf(&tmp, 762 "Not putting %s in list of drives: it's a virtual drive", 763 drive); 764 log_msg(8, tmp); 765 paranoid_free(tmp); 766 continue; 767 } 768 769 size = mountlist->el[lino].size; 770 if (size == 0) { 771 asprintf(&tmp, 772 "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", 773 drive); 774 log_msg(8, tmp); 775 paranoid_free(tmp); 776 continue; 777 } 867 778 868 779 /* … … 877 788 */ 878 789 879 sprintf (tmp, 880 "Putting %s with size %lli in list of drives", 881 drive, size); 882 log_msg (8, tmp); 883 884 (void) truncate_to_drive_name (drive); 885 for (j = 0; j < noof_drives && strcmp (drivelist->el[j].device, drive) != 0; j++) 886 continue; 887 if (j == noof_drives) 888 { 889 strcpy (drivelist->el[noof_drives++].device, drive); 890 } 891 } 892 drivelist->entries = noof_drives; 893 log_msg (8, "Made list of drives"); 894 paranoid_free(drive); 895 paranoid_free(tmp); 896 897 return (noof_drives); 898 } 899 900 901 902 790 asprintf(&tmp, 791 "Putting %s with size %lli in list of drives", 792 drive, size); 793 log_msg(8, tmp); 794 paranoid_free(tmp); 795 796 (void) truncate_to_drive_name(drive); 797 for (j = 0; 798 j < noof_drives 799 && strcmp(drivelist->el[j].device, drive) != 0; j++) 800 continue; 801 if (j == noof_drives) { 802 strcpy(drivelist->el[noof_drives++].device, drive); 803 } 804 paranoid_free(drive); 805 806 } 807 drivelist->entries = noof_drives; 808 log_msg(8, "Made list of drives"); 809 810 return (noof_drives); 811 } 903 812 904 813 … … 910 819 * @param raidlist The raidlist to examine. 911 820 */ 912 void 913 make_list_of_unallocated_raid_partitions (struct mountlist_itself 914 *output_list, 915 struct mountlist_itself *mountlist, 916 struct raidlist_itself *raidlist) 917 { 918 919 /*@ int **************************************************************/ 920 int items = 0; 821 void make_list_of_unallocated_raid_partitions(struct mountlist_itself 822 *output_list, 823 struct mountlist_itself 824 *mountlist, 825 struct raidlist_itself 826 *raidlist) 827 { 828 829 /*@ int ************************************************************* */ 830 int items = 0; 921 831 int i = 0; 922 832 int used_by = 0; 923 833 924 /*@ buffers **********************************************************/ 925 char *tmp; 926 927 malloc_string(tmp); 928 assert(output_list!=NULL); 929 assert(mountlist!=NULL); 930 assert(raidlist!=NULL); 931 log_it ("MLOURP -- starting"); 932 items = 0; 933 934 935 for (i = 0; i < mountlist->entries; i++) 936 { 937 if (strstr (mountlist->el[i].mountpoint, "raid")) 938 { 939 used_by = 940 which_raid_device_is_using_this_partition (raidlist, 941 mountlist->el[i]. 942 device); 943 if (used_by < 0) 944 { 945 memcpy ((void *) &output_list->el[items++], 946 (void *) &mountlist->el[i], 947 sizeof (struct mountlist_line)); 948 sprintf (tmp, 949 "%s is available; user may choose to add it to raid device", 950 output_list->el[items - 1].device); 951 log_it (tmp); 952 } 953 } 954 } 955 output_list->entries = items; 956 log_it ("MLUORP -- ending"); 957 paranoid_free(tmp); 958 } 959 960 961 834 /*@ buffers ********************************************************* */ 835 char *tmp; 836 837 assert(output_list != NULL); 838 assert(mountlist != NULL); 839 assert(raidlist != NULL); 840 log_it("MLOURP -- starting"); 841 items = 0; 842 843 844 for (i = 0; i < mountlist->entries; i++) { 845 if (strstr(mountlist->el[i].mountpoint, "raid")) { 846 used_by = 847 which_raid_device_is_using_this_partition(raidlist, 848 mountlist->el[i]. 849 device); 850 if (used_by < 0) { 851 memcpy((void *) &output_list->el[items++], 852 (void *) &mountlist->el[i], 853 sizeof(struct mountlist_line)); 854 asprintf(&tmp, 855 "%s is available; user may choose to add it to raid device", 856 output_list->el[items - 1].device); 857 log_it(tmp); 858 paranoid_free(tmp); 859 } 860 } 861 } 862 output_list->entries = items; 863 log_it("MLUORP -- ending"); 864 } 962 865 963 866 … … 969 872 */ 970 873 long long 971 size_of_specific_device_in_mountlist (struct mountlist_itself *mountlist, char *device) 972 { 973 /*@ int ***************************************************************/ 974 int i = 0; 975 976 977 assert(mountlist!=NULL); 978 assert_string_is_neither_NULL_nor_zerolength(device); 979 980 for (i = 0; 981 i < mountlist->entries && strcmp (mountlist->el[i].device, device); 982 i++); 983 if (i == mountlist->entries) 984 { 985 return (-1); 986 } 987 else 988 { 989 return (mountlist->el[i].size); 990 } 991 } 992 993 874 size_of_specific_device_in_mountlist(struct mountlist_itself *mountlist, 875 char *device) 876 { 877 /*@ int ************************************************************** */ 878 int i = 0; 879 880 881 assert(mountlist != NULL); 882 assert_string_is_neither_NULL_nor_zerolength(device); 883 884 for (i = 0; 885 i < mountlist->entries && strcmp(mountlist->el[i].device, device); 886 i++); 887 if (i == mountlist->entries) { 888 return (-1); 889 } else { 890 return (mountlist->el[i].size); 891 } 892 } 994 893 995 894 … … 1004 903 * @return 0 for success, 1 for failure. 1005 904 */ 1006 int 1007 load_mountlist( struct mountlist_itself *mountlist, char *fname) 1008 { 1009 FILE *fin; 1010 /* malloc ***/ 1011 char *incoming; 1012 char *siz; 1013 char *tmp; 1014 char*p; 1015 1016 int items; 1017 int j; 1018 1019 assert(mountlist!=NULL); 1020 assert_string_is_neither_NULL_nor_zerolength(fname); 1021 malloc_string(incoming); 1022 malloc_string(siz); 1023 malloc_string(tmp); 1024 if ( !( fin = fopen( fname, "r" ) ) ) 1025 { 1026 log_it( "Unable to open mountlist - '%s'", fname ); 1027 log_to_screen( "Cannot open mountlist" ); 1028 paranoid_free(incoming); 1029 paranoid_free(siz); 1030 paranoid_free(tmp); 1031 return( 1 ); 1032 } 1033 items = 0; 1034 (void) fgets( incoming, MAX_STR_LEN - 1, fin ); 1035 log_it( "Loading mountlist..." ); 1036 while( !feof( fin ) ) 1037 { 905 int load_mountlist(struct mountlist_itself *mountlist, char *fname) 906 { 907 FILE *fin; 908 /* malloc ** */ 909 char *incoming = NULL; 910 char *siz; 911 char *tmp; 912 char *p; 913 914 int items; 915 int j; 916 int n = 0; 917 918 assert(mountlist != NULL); 919 assert_string_is_neither_NULL_nor_zerolength(fname); 920 malloc_string(siz); 921 if (!(fin = fopen(fname, "r"))) { 922 log_it("Unable to open mountlist - '%s'", fname); 923 log_to_screen("Cannot open mountlist"); 924 paranoid_free(siz); 925 return (1); 926 } 927 items = 0; 928 (void) getline(&incoming, &n, fin); 929 log_it("Loading mountlist..."); 930 while (!feof(fin)) { 1038 931 #if linux 1039 sscanf( incoming, 1040 "%s %s %s %s %s", 1041 mountlist->el[items].device, 1042 mountlist->el[items].mountpoint, 1043 mountlist->el[items].format, 1044 siz, 1045 mountlist->el[items].label); 932 sscanf(incoming, 933 "%s %s %s %s %s", 934 mountlist->el[items].device, 935 mountlist->el[items].mountpoint, 936 mountlist->el[items].format, 937 siz, mountlist->el[items].label); 1046 938 #elif __FreeBSD__ 1047 sscanf (incoming, 1048 "%s %s %s %s", 1049 mountlist->el[items].device, 1050 mountlist->el[items].mountpoint, 1051 mountlist->el[items].format, 1052 siz); 1053 strcpy (mountlist->el[items].label, ""); 939 sscanf(incoming, 940 "%s %s %s %s", 941 mountlist->el[items].device, 942 mountlist->el[items].mountpoint, 943 mountlist->el[items].format, siz); 944 strcpy(mountlist->el[items].label, ""); 1054 945 #endif 1055 946 1056 if ( 1057 !strcmp(mountlist->el[items].device,"/proc") || 1058 !strcmp(mountlist->el[items].device, "proc") || 1059 !strcmp(mountlist->el[items].device,"/sys") || 1060 !strcmp(mountlist->el[items].device, "sys") || 1061 !strcmp(mountlist->el[items].device,"/devpts") || 1062 !strcmp(mountlist->el[items].device, "devpts") 1063 ) 1064 { 1065 log_msg(1, "Ignoring %s in mountlist - not loading that line :) ", mountlist->el[items].device); 1066 (void) fgets( incoming, MAX_STR_LEN - 1,fin ); 1067 continue; 1068 } 1069 mountlist->el[items].size = atoll( siz ); 1070 if ( mountlist->el[items].device[0] != '\0' && mountlist->el[items].device[0] != '#' ) 1071 { 1072 if ( items >= ARBITRARY_MAXIMUM ) 1073 { 1074 log_to_screen( "Too many lines in mountlist.. ABORTING" ); 1075 finish( 1 ); 1076 } 1077 for( j=0; j < items && strcmp( mountlist->el[j].device, mountlist->el[items].device ); j++); 1078 if (j < items) 1079 { 1080 strcat( mountlist->el[items].device, "_dup" ); 1081 sprintf( tmp, "Duplicate entry in mountlist - renaming to %s",mountlist->el[items].device ); 1082 log_it( tmp ); 1083 } 1084 strcpy(tmp, mountlist->el[items].device); 1085 if (strstr(tmp, "/dev/md/")) 1086 { 1087 log_it("format_device() --- Contracting %s", tmp); 1088 p = strrchr(tmp, '/'); 1089 if (p) { *p = *(p+1); *(p+1) = *(p+2); *(p+2) = *(p+3); } 1090 log_it("It was %s; it is now %s", mountlist->el[items].device, tmp); 1091 strcpy(mountlist->el[items].device, tmp); 1092 } 1093 1094 sprintf( tmp, 1095 "%s %s %s %lld %s", 1096 mountlist->el[items].device, 1097 mountlist->el[items].mountpoint, 1098 mountlist->el[items].format, 1099 mountlist->el[items].size, 1100 mountlist->el[items].label); 1101 1102 log_it( tmp ); 1103 items++; 1104 } 1105 (void) fgets( incoming, MAX_STR_LEN - 1,fin ); 1106 } 1107 paranoid_fclose( fin ); 1108 mountlist->entries = items; 1109 1110 log_it( "Mountlist loaded successfully." ); 1111 sprintf( tmp, "%d entries in mountlist", items ); 1112 log_it( tmp ); 1113 paranoid_free(incoming); 1114 paranoid_free(siz); 1115 paranoid_free(tmp); 1116 return( 0 ); 947 if (!strcmp(mountlist->el[items].device, "/proc") || 948 !strcmp(mountlist->el[items].device, "proc") || 949 !strcmp(mountlist->el[items].device, "/sys") || 950 !strcmp(mountlist->el[items].device, "sys") || 951 !strcmp(mountlist->el[items].device, "/devpts") || 952 !strcmp(mountlist->el[items].device, "devpts") 953 ) { 954 log_msg(1, 955 "Ignoring %s in mountlist - not loading that line :) ", 956 mountlist->el[items].device); 957 (void) getline(&incoming, &n, fin); 958 continue; 959 } 960 mountlist->el[items].size = atoll(siz); 961 if (mountlist->el[items].device[0] != '\0' 962 && mountlist->el[items].device[0] != '#') { 963 if (items >= ARBITRARY_MAXIMUM) { 964 log_to_screen("Too many lines in mountlist.. ABORTING"); 965 finish(1); 966 } 967 for (j = 0; 968 j < items 969 && strcmp(mountlist->el[j].device, 970 mountlist->el[items].device); j++); 971 if (j < items) { 972 strcat(mountlist->el[items].device, "_dup"); 973 asprintf(&tmp, 974 "Duplicate entry in mountlist - renaming to %s", 975 mountlist->el[items].device); 976 log_it(tmp); 977 paranoid_free(tmp); 978 } 979 asprintf(&tmp, mountlist->el[items].device); 980 if (strstr(tmp, "/dev/md/")) { 981 log_it("format_device() --- Contracting %s", tmp); 982 p = strrchr(tmp, '/'); 983 if (p) { 984 *p = *(p + 1); 985 *(p + 1) = *(p + 2); 986 *(p + 2) = *(p + 3); 987 } 988 log_it("It was %s; it is now %s", 989 mountlist->el[items].device, tmp); 990 strcpy(mountlist->el[items].device, tmp); 991 } 992 paranoid_free(tmp); 993 994 asprintf(&tmp, 995 "%s %s %s %lld %s", 996 mountlist->el[items].device, 997 mountlist->el[items].mountpoint, 998 mountlist->el[items].format, 999 mountlist->el[items].size, mountlist->el[items].label); 1000 1001 log_it(tmp); 1002 paranoid_free(tmp); 1003 items++; 1004 } 1005 (void) getline(&incoming, &n, fin); 1006 } 1007 paranoid_fclose(fin); 1008 paranoid_free(incoming); 1009 mountlist->entries = items; 1010 1011 log_it("Mountlist loaded successfully."); 1012 asprintf(&tmp, "%d entries in mountlist", items); 1013 log_it(tmp); 1014 paranoid_free(tmp); 1015 1016 paranoid_free(siz); 1017 return (0); 1117 1018 } 1118 1019 … … 1126 1027 * @see load_mountlist 1127 1028 */ 1128 int 1129 save_mountlist_to_disk(struct mountlist_itself *mountlist, char *fname) 1130 { 1131 FILE *fout; 1132 int i; 1133 1134 assert(mountlist!=NULL); 1135 assert_string_is_neither_NULL_nor_zerolength(fname); 1136 1137 log_it("save_mountlist_to_disk() --- saving to %s", fname); 1138 if (!(fout=fopen(fname,"w"))) 1139 { 1140 log_OS_error("WMTD - Cannot openout mountlist"); 1141 return(1); 1142 } 1143 for( i = 0; i < mountlist->entries; i++) 1144 { 1145 fprintf(fout, 1146 "%-15s %-15s %-15s %-15lld %-15s\n",mountlist->el[i].device, 1147 mountlist->el[i].mountpoint, 1148 mountlist->el[i].format, 1149 mountlist->el[i].size, 1150 mountlist->el[i].label); 1151 } 1152 paranoid_fclose(fout); 1153 return(0); 1154 } 1155 1029 int save_mountlist_to_disk(struct mountlist_itself *mountlist, char *fname) 1030 { 1031 FILE *fout; 1032 int i; 1033 1034 assert(mountlist != NULL); 1035 assert_string_is_neither_NULL_nor_zerolength(fname); 1036 1037 log_it("save_mountlist_to_disk() --- saving to %s", fname); 1038 if (!(fout = fopen(fname, "w"))) { 1039 log_OS_error("WMTD - Cannot openout mountlist"); 1040 return (1); 1041 } 1042 for (i = 0; i < mountlist->entries; i++) { 1043 fprintf(fout, 1044 "%-15s %-15s %-15s %-15lld %-15s\n", 1045 mountlist->el[i].device, mountlist->el[i].mountpoint, 1046 mountlist->el[i].format, mountlist->el[i].size, 1047 mountlist->el[i].label); 1048 } 1049 paranoid_fclose(fout); 1050 return (0); 1051 } 1156 1052 1157 1053 … … 1161 1057 * @param mountlist The mountlist to sort. 1162 1058 */ 1163 void 1164 sort_mountlist_by_device( struct mountlist_itself *mountlist) 1165 { 1166 int diff; 1167 int lino = -999; 1168 1169 assert(mountlist!=NULL); 1170 1171 while (lino < mountlist->entries) 1172 { 1173 for(lino = 1; lino < mountlist->entries; lino++) 1174 { 1175 diff = strcmp_inc_numbers(mountlist->el[lino-1].device,mountlist->el[lino].device); 1176 if (diff > 0) 1177 { 1178 swap_mountlist_entries( mountlist, lino - 1, lino); 1179 break; 1180 } 1181 } 1182 } 1183 } 1059 void sort_mountlist_by_device(struct mountlist_itself *mountlist) 1060 { 1061 int diff; 1062 int lino = -999; 1063 1064 assert(mountlist != NULL); 1065 1066 while (lino < mountlist->entries) { 1067 for (lino = 1; lino < mountlist->entries; lino++) { 1068 diff = 1069 strcmp_inc_numbers(mountlist->el[lino - 1].device, 1070 mountlist->el[lino].device); 1071 if (diff > 0) { 1072 swap_mountlist_entries(mountlist, lino - 1, lino); 1073 break; 1074 } 1075 } 1076 } 1077 } 1078 1184 1079 1185 1080 /** … … 1189 1084 * @param reverse If TRUE, then do a reverse sort. 1190 1085 */ 1191 void 1192 sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist, bool reverse)1193 { 1194 int diff; 1195 int lino = -999;1196 1197 assert(mountlist!=NULL); 1198 1199 while(lino < mountlist->entries) 1200 1201 for(lino = 1; lino < mountlist->entries; lino++) 1202 {1203 diff = strcmp( mountlist->el[lino-1].mountpoint,mountlist->el[lino].mountpoint);1204 if ((diff >0 && !reverse) || ((diff <0 && reverse)))1205 1206 1207 1208 1209 }1210 1086 void 1087 sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist, 1088 bool reverse) 1089 { 1090 int diff; 1091 int lino = -999; 1092 1093 assert(mountlist != NULL); 1094 1095 while (lino < mountlist->entries) { 1096 for (lino = 1; lino < mountlist->entries; lino++) { 1097 diff = 1098 strcmp(mountlist->el[lino - 1].mountpoint, 1099 mountlist->el[lino].mountpoint); 1100 if ((diff > 0 && !reverse) || ((diff < 0 && reverse))) { 1101 swap_mountlist_entries(mountlist, lino - 1, lino); 1102 break; 1103 } 1104 } 1105 } 1211 1106 } 1212 1107 … … 1218 1113 * @param b The index number of the second entry. 1219 1114 */ 1220 void 1115 void 1221 1116 swap_mountlist_entries(struct mountlist_itself *mountlist, int a, int b) 1222 1117 { 1223 /*@ mallocs ****/1224 char device[64];1225 char mountpoint[256];1226 char format[64];1227 1228 1229 1230 assert(mountlist!=NULL);1231 assert(a>=0);1232 assert(b>=0);1233 1234 strcpy(device,mountlist->el[a].device);1235 strcpy(mountpoint,mountlist->el[a].mountpoint);1236 strcpy(format,mountlist->el[a].format);1237 1238 size=mountlist->el[a].size;1239 1240 strcpy(mountlist->el[a].device,mountlist->el[b].device);1241 strcpy(mountlist->el[a].mountpoint,mountlist->el[b].mountpoint);1242 strcpy(mountlist->el[a].format,mountlist->el[b].format);1243 1244 mountlist->el[a].size=mountlist->el[b].size;1245 1246 strcpy(mountlist->el[b].device,device);1247 strcpy(mountlist->el[b].mountpoint,mountpoint);1248 strcpy(mountlist->el[b].format,format);1249 1250 mountlist->el[b].size=size;1118 /*@ mallocs *** */ 1119 char *device; 1120 char *mountpoint; 1121 char *format; 1122 1123 long long size; 1124 1125 assert(mountlist != NULL); 1126 assert(a >= 0); 1127 assert(b >= 0); 1128 1129 asprintf(&device, mountlist->el[a].device); 1130 asprintf(&mountpoint, mountlist->el[a].mountpoint); 1131 asprintf(&format, mountlist->el[a].format); 1132 1133 size = mountlist->el[a].size; 1134 1135 strcpy(mountlist->el[a].device, mountlist->el[b].device); 1136 strcpy(mountlist->el[a].mountpoint, mountlist->el[b].mountpoint); 1137 strcpy(mountlist->el[a].format, mountlist->el[b].format); 1138 1139 mountlist->el[a].size = mountlist->el[b].size; 1140 1141 strcpy(mountlist->el[b].device, device); 1142 strcpy(mountlist->el[b].mountpoint, mountpoint); 1143 strcpy(mountlist->el[b].format, format); 1144 1145 mountlist->el[b].size = size; 1251 1146 } 1252 1147 -
trunk/mondo/mondo/common/libmondo-verify.c
r30 r48 1 /*************************************************************************** 2 libmondo-verify.c - description 3 ----------------- 4 5 begin: Fri Apr 19 16:40:35 EDT 2002 6 copyright : (C) 2002 Mondo Hugo Rabson 7 email : Hugo Rabson <hugorabson@msn.com> 8 edited by : by Stan Benoit 4/2002 9 email : troff@nakedsoul.org 10 cvsid : $Id: libmondo-verify.c,v 1.9 2004/06/21 20:20:36 hugo Exp $ 11 ***************************************************************************/ 12 13 /*************************************************************************** 14 * * 15 * This program is free software; you can redistribute it and/or modify * 16 * it under the terms of the GNU General Public License as published by * 17 * the Free Software Foundation; either version 2 of the License, or * 18 * (at your option) any later version. * 19 * * 20 ***************************************************************************/ 21 /* mondo-verify 22 23 24 07/07 25 - added star verify support 26 27 04/04/2004 28 - added star support 29 30 10/23/2003 31 - changed "ISO #n" to "<media descriptor> #n" 32 33 10/01 34 - working on biggiefile verification (CDs) 35 36 09/16 37 - fixed bug in CD biggie verif'n 38 39 09/15 40 - state explicitly that we do not verify disk images 41 42 09/13 43 - working on verify_all_slices_on_CD() 44 45 09/01 46 - write list of changed biggiefiles (streaming only) to changed.files 47 48 05/05 49 - exclude /dev/ * from list of changed files 50 - add Joshua Oreman's FreeBSD patches 51 52 04/24/2003 53 - added lots of assert()'s and log_OS_error()'s 54 55 09/01 - 09/30/2002 56 - run_program_and_log_output() now takes boolean operator to specify 57 whether it will log its activities in the event of _success_ 58 - eject_device() added 59 - cleaned up 'changed file' feedback a little bit 60 61 08/01 - 08/31 62 - make sure to prefix bkpinfo->restore_path to local biggiefile fname when 63 comparing it to the archived copy of biggiefile; otherwise, biggiefile 64 not found & checksum missing & so on 65 - exclude "incheckentry xwait()" from changed.files 66 - cleaned up some log_it() calls 67 68 07/01 - 07/31 69 - renamed libmondo-verify.c 70 - say 'bigfile' not 'biggiefile' 71 - exclude /dev/ * from changed.files 72 73 01/01 - 06/30 74 - remove /tmp/changed.files.* dead files 75 - don't pclose() tape after calling closein_tape(): the latter does it already 76 - fixed bug in verify_cd_image()'s CD-mounting code 77 - don't write to screen "old cksum.. curr cksum.." 78 - changed the gawks to awks for the benefit of Debian 79 - handles files >2GB in size 80 - fixed bug in /tmp/changed.files-generator 81 - re-enabled a lot of CD-verification code 82 - afioballs are saved in %s/tmpfs/ now (%s=tmpdir) 83 - changed some labels to make them more user-friendly 84 - don't chdir() anywhere before verifying stuff 85 - changed files are now detected by verify_tape_backup() and listed in 86 /tmp/changed.files 87 - replaced &> with > .. 2> 88 - still implementing improved tape support 89 90 91 Started late Dec, 2001 92 93 ----------------------------------------------------------------------------- 1 /* $Id$ */ 2 /* 3 copyright : (C) 2002 Mondo Hugo Rabson <hugorabson@msn.com> 4 edited by : by Stan Benoit 4/2002 troff@nakedsoul.org 94 5 */ 95 6 … … 113 24 114 25 /*@unused@*/ 115 //static char cvsid[] = "$Id : libmondo-verify.c,v 1.9 2004/06/21 20:20:36 hugo Exp$";116 117 char *vfy_tball_fname 26 //static char cvsid[] = "$Id$"; 27 28 char *vfy_tball_fname(struct s_bkpinfo *, char *, int); 118 29 119 30 … … 136 47 */ 137 48 long 138 generate_list_of_changed_files 139 char *ignorefiles_fname, char *stderr_fname)49 generate_list_of_changed_files(char *changedfiles_fname, 50 char *ignorefiles_fname, char *stderr_fname) 140 51 { 141 /*@ buffer ********************************************************** */142 52 /*@ buffer ********************************************************** */ 53 char *command; 143 54 char *afio_found_changes; 144 55 145 /*@ int **************************************************************/ 146 int res = 0; 147 148 /*@ long *************************************************************/ 149 long afio_diffs = 0; 150 151 command = malloc(2000); 152 afio_found_changes = malloc(500); 153 assert_string_is_neither_NULL_nor_zerolength(changedfiles_fname); 154 assert_string_is_neither_NULL_nor_zerolength(ignorefiles_fname); 155 assert_string_is_neither_NULL_nor_zerolength(stderr_fname); 156 157 sprintf (afio_found_changes, "%s.afio", ignorefiles_fname); 158 paranoid_system ("sync"); 159 56 /*@ int ************************************************************* */ 57 int res = 0; 58 59 /*@ long ************************************************************ */ 60 long afio_diffs = 0; 61 62 assert_string_is_neither_NULL_nor_zerolength(changedfiles_fname); 63 assert_string_is_neither_NULL_nor_zerolength(ignorefiles_fname); 64 assert_string_is_neither_NULL_nor_zerolength(stderr_fname); 65 66 asprintf(&afio_found_changes, "%s.afio", ignorefiles_fname); 67 paranoid_system("sync"); 68 160 69 /* sprintf (command, 161 70 "cat %s | grep \"afio: \" | awk '{j=substr($0,8); i=index(j,\": \");printf \"/%%s\\n\",substr(j,1,i-2);}' | sort | uniq | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"/dev/.*\" > %s", 162 71 stderr_fname, afio_found_changes); 163 72 */ 164 165 166 sprintf (command,167 168 169 log_msg(2, command);170 res = system(command);171 if (res) 172 173 log_msg(2, "Warning - failed to think");174 175 176 177 sprintf (command,178 179 180 log_msg(2, command);181 res = system(command);182 if (res) 183 184 log_msg(2, "Warning - failed to think");185 73 74 log_msg(1, "Now scanning log file for 'afio: ' stuff"); 75 asprintf(&command, 76 "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> %s", 77 stderr_fname, afio_found_changes); 78 log_msg(2, command); 79 res = system(command); 80 paranoid_free(command); 81 if (res) { 82 log_msg(2, "Warning - failed to think"); 83 } 84 85 log_msg(1, "Now scanning log file for 'star: ' stuff"); 86 asprintf(&command, 87 "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> %s", 88 stderr_fname, afio_found_changes); 89 log_msg(2, command); 90 res = system(command); 91 paranoid_free(command); 92 if (res) { 93 log_msg(2, "Warning - failed to think"); 94 } 186 95 // exclude_nonexistent_files (afio_found_changes); 187 afio_diffs = count_lines_in_file(afio_found_changes);188 sprintf (command,189 190 191 192 log_msg(2, command);193 paranoid_system(command);194 195 196 96 afio_diffs = count_lines_in_file(afio_found_changes); 97 asprintf(&command, 98 "cat %s %s %s | sort | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s", 99 ignorefiles_fname, afio_found_changes, afio_found_changes, 100 changedfiles_fname); 101 log_msg(2, command); 102 paranoid_system(command); 103 paranoid_free(command); 104 paranoid_free(afio_found_changes); 105 return (afio_diffs); 197 106 } 198 107 … … 209 118 * @return The number of sets containing differences (0 for success). 210 119 */ 211 int 212 verify_afioballs_on_CD (struct s_bkpinfo *bkpinfo, char *mountpoint) 120 int verify_afioballs_on_CD(struct s_bkpinfo *bkpinfo, char *mountpoint) 213 121 { 214 122 215 /*@ buffers ********************************************************* */216 217 218 /*@ int ************************************************************* */219 123 /*@ buffers ********************************************************* */ 124 char *tmp; 125 126 /*@ int ************************************************************* */ 127 int set_number = 0; 220 128 int retval = 0; 221 129 int total_sets = 0; 222 130 int percentage = 0; 223 131 224 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 225 assert(bkpinfo!=NULL); 226 malloc_string(tmp); 227 228 for (set_number = 0; 229 set_number < 9999 230 && 231 !does_file_exist (vfy_tball_fname (bkpinfo, mountpoint, set_number)); 232 set_number++); 233 if (!does_file_exist (vfy_tball_fname (bkpinfo, mountpoint, set_number))) 234 { 235 return (0); 236 } 237 238 if (g_last_afioball_number != set_number - 1) 239 { 240 if (set_number==0) 241 { 242 log_msg(1, "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more"); 243 } 244 else 245 { 246 retval++; 247 sprintf (tmp, "Warning - missing set(s) between %d and %d\n", 248 g_last_afioball_number, set_number - 1); 249 log_to_screen (tmp); 250 } 251 } 252 sprintf (tmp, "Verifying %s #%d's tarballs", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 253 open_evalcall_form (tmp); 254 255 for (total_sets = set_number; 256 does_file_exist (vfy_tball_fname (bkpinfo, mountpoint, total_sets)); 257 total_sets++) { log_msg(1, "total_sets = %d", total_sets); } 258 for (; does_file_exist (vfy_tball_fname (bkpinfo, mountpoint, set_number)); 259 set_number++) 260 { 261 percentage = 262 (set_number - g_last_afioball_number) * 100 / (total_sets - 263 g_last_afioball_number); 264 update_evalcall_form (percentage); 265 log_msg(1, "set = %d", set_number); 266 retval += 267 verify_an_afioball_from_CD (bkpinfo, 268 vfy_tball_fname (bkpinfo, mountpoint, 269 set_number)); 270 } 271 g_last_afioball_number = set_number - 1; 272 close_evalcall_form (); 273 paranoid_free(tmp); 274 return (retval); 132 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 133 assert(bkpinfo != NULL); 134 135 for (set_number = 0; 136 set_number < 9999 137 && 138 !does_file_exist(vfy_tball_fname 139 (bkpinfo, mountpoint, set_number)); 140 set_number++); 141 if (!does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, set_number))) { 142 return (0); 143 } 144 145 if (g_last_afioball_number != set_number - 1) { 146 if (set_number == 0) { 147 log_msg(1, 148 "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more"); 149 } else { 150 retval++; 151 asprintf(&tmp, "Warning - missing set(s) between %d and %d\n", 152 g_last_afioball_number, set_number - 1); 153 log_to_screen(tmp); 154 paranoid_free(tmp); 155 } 156 } 157 asprintf(&tmp, "Verifying %s #%d's tarballs", 158 media_descriptor_string(bkpinfo->backup_media_type), 159 g_current_media_number); 160 open_evalcall_form(tmp); 161 paranoid_free(tmp); 162 163 for (total_sets = set_number; 164 does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, total_sets)); 165 total_sets++) { 166 log_msg(1, "total_sets = %d", total_sets); 167 } 168 for (; 169 does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, set_number)); 170 set_number++) { 171 percentage = 172 (set_number - g_last_afioball_number) * 100 / (total_sets - 173 g_last_afioball_number); 174 update_evalcall_form(percentage); 175 log_msg(1, "set = %d", set_number); 176 retval += 177 verify_an_afioball_from_CD(bkpinfo, 178 vfy_tball_fname(bkpinfo, mountpoint, 179 set_number)); 180 } 181 g_last_afioball_number = set_number - 1; 182 close_evalcall_form(); 183 return (retval); 275 184 } 185 276 186 277 187 /** … … 286 196 * @return The number of differences (0 for perfect biggiefiles). 287 197 */ 288 int 289 verify_all_slices_on_CD (struct s_bkpinfo *bkpinfo, char *mtpt) 198 int verify_all_slices_on_CD(struct s_bkpinfo *bkpinfo, char *mtpt) 290 199 { 291 200 292 /*@ buffer ********************************************************** */293 294 201 /*@ buffer ********************************************************** */ 202 char *tmp; 203 char *mountpoint; 295 204 // char ca, cb; 296 297 298 static char *bufblkA=NULL;299 static char *bufblkB=NULL;300 const long maxbufsize=65536L;301 long currsizA=0;302 long currsizB=0;303 304 305 /*@ long ************************************************************ */306 307 308 309 310 static FILE*forig=NULL;311 312 313 314 FILE*pin;315 FILE*fin;316 int retval=0;205 char *command; 206 char *sz_exe; 207 static char *bufblkA = NULL; 208 static char *bufblkB = NULL; 209 const long maxbufsize = 65536L; 210 long currsizA = 0; 211 long currsizB = 0; 212 long j; 213 214 /*@ long ************************************************************ */ 215 long bigfile_num = 0; 216 long slice_num = -1; 217 int res; 218 219 static FILE *forig = NULL; 220 static struct s_filename_and_lstat_info biggiestruct; 221 static long last_bigfile_num = -1; 222 static long last_slice_num = -1; 223 FILE *pin; 224 FILE *fin; 225 int retval = 0; 317 226 // long long outlen; 318 227 319 malloc_string(tmp); 320 malloc_string(mountpoint); 321 malloc_string(command); 322 malloc_string(sz_exe); 323 if (!bufblkA) { if (!(bufblkA = malloc(maxbufsize))) { fatal_error("Cannot malloc bufblkA"); } } 324 if (!bufblkB) { if (!(bufblkB = malloc(maxbufsize))) { fatal_error("Cannot malloc bufblkB"); } } 325 326 assert(bkpinfo!=NULL); 327 assert_string_is_neither_NULL_nor_zerolength(mtpt); 328 329 if (bkpinfo->compression_level>0) 330 { 331 if (bkpinfo->use_lzo) 332 { strcpy(sz_exe, "lzop"); } 333 else 334 { strcpy(sz_exe, "bzip2"); } 335 } 336 else 337 { sz_exe[0] = '\0'; } 338 339 iamhere("before vsbf"); 340 sprintf (tmp, "Verifying %s#%d's big files", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 341 open_evalcall_form (tmp); 342 iamhere("after vsbf"); 343 sprintf (mountpoint, "%s/archives", mtpt); 344 if (last_bigfile_num == -1) 345 { 346 bigfile_num = 0; 347 slice_num = 0; 348 } 349 else if (slice_num == 0) 350 { 351 bigfile_num = last_bigfile_num + 1; 352 slice_num = 0; 353 } 354 else 355 { 356 bigfile_num = last_bigfile_num; 357 slice_num = last_slice_num + 1; 358 } 359 while (does_file_exist 360 (slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix)) 361 || 362 does_file_exist 363 (slice_fname(bigfile_num, slice_num, mountpoint, ""))) 364 { 228 malloc_string(sz_exe); 229 if (!bufblkA) { 230 if (!(bufblkA = malloc(maxbufsize))) { 231 fatal_error("Cannot malloc bufblkA"); 232 } 233 } 234 if (!bufblkB) { 235 if (!(bufblkB = malloc(maxbufsize))) { 236 fatal_error("Cannot malloc bufblkB"); 237 } 238 } 239 240 assert(bkpinfo != NULL); 241 assert_string_is_neither_NULL_nor_zerolength(mtpt); 242 243 if (bkpinfo->compression_level > 0) { 244 if (bkpinfo->use_lzo) { 245 asprintf(&sz_exe, "lzop"); 246 } else { 247 asprintf(&sz_exe, "bzip2"); 248 } 249 } else { 250 asprintf(&sz_exe, ""); 251 } 252 253 iamhere("before vsbf"); 254 asprintf(&tmp, "Verifying %s#%d's big files", 255 media_descriptor_string(bkpinfo->backup_media_type), 256 g_current_media_number); 257 open_evalcall_form(tmp); 258 paranoid_free(tmp); 259 iamhere("after vsbf"); 260 asprintf(&mountpoint, "%s/archives", mtpt); 261 if (last_bigfile_num == -1) { 262 bigfile_num = 0; 263 slice_num = 0; 264 } else if (slice_num == 0) { 265 bigfile_num = last_bigfile_num + 1; 266 slice_num = 0; 267 } else { 268 bigfile_num = last_bigfile_num; 269 slice_num = last_slice_num + 1; 270 } 271 while (does_file_exist 272 (slice_fname 273 (bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix)) 274 || 275 does_file_exist(slice_fname 276 (bigfile_num, slice_num, mountpoint, ""))) { 365 277 // handle slices until end of CD 366 if (slice_num == 0) 367 { 368 log_msg (2, "ISO=%d bigfile=%ld --START--", g_current_media_number, bigfile_num); 369 if ( !(fin = fopen( slice_fname( bigfile_num, slice_num, mountpoint, ""), "r" ) ) ) 370 { log_msg(2, "Cannot open bigfile's info file"); } 371 else 372 { 373 if ( fread((void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) 374 { log_msg(2, "Unable to get biggiestruct"); } 375 paranoid_fclose(fin); 376 } 377 sprintf( tmp, "%s/%s", bkpinfo->restore_path, biggiestruct.filename ); 378 log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp); 379 if (!(forig = fopen(tmp, "r"))) { log_msg(2, "Failed to open bigfile. Darn."); retval++; } 380 slice_num++; 381 } 382 else if (does_file_exist 383 (slice_fname (bigfile_num, slice_num, mountpoint, ""))) 384 { 385 log_msg (2, "ISO=%d bigfile=%ld ---END---", 386 g_current_media_number, bigfile_num); 387 bigfile_num++; 388 paranoid_fclose(forig); 389 slice_num = 0; 390 } 391 else 392 { 393 log_msg (2, "ISO=%d bigfile=%ld slice=%ld \r", 394 g_current_media_number, bigfile_num, slice_num); 395 if (bkpinfo->compression_level > 0) 396 { sprintf(command, "cat %s | %s -dc 2>> %s", slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix), sz_exe, MONDO_LOGFILE); } 397 else 398 { sprintf(command, "cat %s", slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix)); } 399 if ((pin = popen(command,"r"))) 400 { 401 res=0; 402 while(!feof(pin)) 403 { 404 currsizA = fread(bufblkA, 1, maxbufsize, pin); 405 if (currsizA<=0) { break; } 406 currsizB = fread(bufblkB, 1, currsizA, forig); 407 if (currsizA != currsizB) { res++; } 408 else 409 { 410 for(j=0; j<currsizA && bufblkA[j]==bufblkB[j]; j++); 411 if (j<currsizA) { res++;} 412 } 413 } 414 paranoid_pclose(pin); 415 if (res && !strncmp(biggiestruct.filename," /dev/", 5)) 416 { 417 log_msg(3, "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via partimagehack, not dd.", biggiestruct.filename); 418 log_msg(3, "If you really want verification for %s, please contact the devteam and offer an incentive.", biggiestruct.filename); 419 res=0; 420 } 421 if (res) 422 { 423 log_msg(0, "afio: \"%s\": Corrupt biggie file, says libmondo-archive.c", biggiestruct.filename); 424 retval++; 425 } 426 } 427 slice_num++; 428 } 429 } 430 last_bigfile_num = bigfile_num; 431 last_slice_num = slice_num - 1; 432 if (last_slice_num < 0) 433 { 434 last_bigfile_num--; 435 } 436 close_evalcall_form (); 437 if (bufblkA) { paranoid_free(bufblkA); } 438 if (bufblkB) { paranoid_free(bufblkB); } 439 paranoid_free(tmp); 440 paranoid_free(command); 441 paranoid_free(sz_exe); 442 paranoid_free(mountpoint); 443 return (0); 278 if (slice_num == 0) { 279 log_msg(2, "ISO=%d bigfile=%ld --START--", 280 g_current_media_number, bigfile_num); 281 if (! 282 (fin = 283 fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""), 284 "r"))) { 285 log_msg(2, "Cannot open bigfile's info file"); 286 } else { 287 if (fread 288 ((void *) &biggiestruct, 1, sizeof(biggiestruct), 289 fin) < sizeof(biggiestruct)) { 290 log_msg(2, "Unable to get biggiestruct"); 291 } 292 paranoid_fclose(fin); 293 } 294 asprintf(&tmp, "%s/%s", bkpinfo->restore_path, 295 biggiestruct.filename); 296 log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp); 297 if (!(forig = fopen(tmp, "r"))) { 298 log_msg(2, "Failed to open bigfile. Darn."); 299 retval++; 300 } 301 paranoid_free(tmp); 302 303 slice_num++; 304 } else if (does_file_exist 305 (slice_fname(bigfile_num, slice_num, mountpoint, ""))) { 306 log_msg(2, "ISO=%d bigfile=%ld ---END---", 307 g_current_media_number, bigfile_num); 308 bigfile_num++; 309 paranoid_fclose(forig); 310 slice_num = 0; 311 } else { 312 log_msg(2, "ISO=%d bigfile=%ld slice=%ld \r", 313 g_current_media_number, bigfile_num, slice_num); 314 if (bkpinfo->compression_level > 0) { 315 asprintf(&command, "cat %s | %s -dc 2>> %s", 316 slice_fname(bigfile_num, slice_num, mountpoint, 317 bkpinfo->zip_suffix), sz_exe, 318 MONDO_LOGFILE); 319 } else { 320 asprintf(&command, "cat %s", 321 slice_fname(bigfile_num, slice_num, mountpoint, 322 bkpinfo->zip_suffix)); 323 } 324 if ((pin = popen(command, "r"))) { 325 res = 0; 326 while (!feof(pin)) { 327 currsizA = fread(bufblkA, 1, maxbufsize, pin); 328 if (currsizA <= 0) { 329 break; 330 } 331 currsizB = fread(bufblkB, 1, currsizA, forig); 332 if (currsizA != currsizB) { 333 res++; 334 } else { 335 for (j = 0; 336 j < currsizA && bufblkA[j] == bufblkB[j]; 337 j++); 338 if (j < currsizA) { 339 res++; 340 } 341 } 342 } 343 paranoid_pclose(pin); 344 if (res && !strncmp(biggiestruct.filename, " /dev/", 5)) { 345 log_msg(3, 346 "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via partimagehack, not dd.", 347 biggiestruct.filename); 348 log_msg(3, 349 "If you really want verification for %s, please contact the devteam and offer an incentive.", 350 biggiestruct.filename); 351 res = 0; 352 } 353 if (res) { 354 log_msg(0, 355 "afio: \"%s\": Corrupt biggie file, says libmondo-archive.c", 356 biggiestruct.filename); 357 retval++; 358 } 359 } 360 paranoid_free(command); 361 slice_num++; 362 } 363 } 364 paranoid_free(mountpoint); 365 paranoid_free(sz_exe); 366 367 last_bigfile_num = bigfile_num; 368 last_slice_num = slice_num - 1; 369 if (last_slice_num < 0) { 370 last_bigfile_num--; 371 } 372 close_evalcall_form(); 373 if (bufblkA) { 374 paranoid_free(bufblkA); 375 } 376 if (bufblkB) { 377 paranoid_free(bufblkB); 378 } 379 return (0); 444 380 } 445 446 447 448 449 381 450 382 … … 460 392 * @return 0, always. 461 393 */ 462 int 463 verify_a_tarball (struct s_bkpinfo *bkpinfo, char *tarball_fname) 394 int verify_a_tarball(struct s_bkpinfo *bkpinfo, char *tarball_fname) 464 395 { 465 /*@ buffers ********************************************************* */466 396 /*@ buffers ********************************************************* */ 397 char *command; 467 398 char *outlog; 468 char *tmp; 469 // char *p; 470 471 /*@ pointers ********************************************************/ 472 FILE *pin; 473 474 /*@ long ************************************************************/ 475 long diffs = 0; 476 /* getcwd(old_pwd,MAX_STR_LEN-1); */ 477 478 479 command = malloc(2000); 480 malloc_string(outlog); 481 malloc_string(tmp); 482 assert(bkpinfo!=NULL); 483 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 484 485 log_it("Verifying fileset '%s'", tarball_fname); 486 /* chdir("/"); */ 487 sprintf (outlog, "%s/afio.log", bkpinfo->tmpdir); 488 /* if programmer forgot to say which compression thingy to use then find out */ 489 if (strstr (tarball_fname, ".lzo") && strcmp (bkpinfo->zip_suffix, "lzo")) 490 { 491 log_msg (2, "OK, I'm going to start using lzop."); 492 strcpy (bkpinfo->zip_exe, "lzop"); 493 strcpy (bkpinfo->zip_suffix, "lzo"); 494 bkpinfo->use_lzo = TRUE; 495 } 496 if (strstr (tarball_fname, ".bz2") && strcmp (bkpinfo->zip_suffix, "bz2")) 497 { 498 log_msg (2, "OK, I'm going to start using bzip2."); 499 strcpy (bkpinfo->zip_exe, "bzip2"); 500 strcpy (bkpinfo->zip_suffix, "bz2"); 501 bkpinfo->use_lzo = FALSE; 502 } 503 unlink(outlog); 504 if (strstr(tarball_fname, ".star")) 505 { 506 bkpinfo->use_star = TRUE; 507 if (strstr(tarball_fname, ".bz2")) 508 sprintf (command, "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", 509 tarball_fname, 510 (strstr(tarball_fname, ".bz2"))?"-bz":" ", 511 outlog, outlog); 512 } 513 else 514 { 515 bkpinfo->use_star = FALSE; 516 sprintf (command, "afio -r -P %s -Z %s >> %s 2>> %s", 517 bkpinfo->zip_exe, tarball_fname, outlog, outlog); 518 } 519 log_msg(6, "command=%s", command); 520 paranoid_system (command); 521 if (length_of_file(outlog) < 10) 522 { 523 sprintf (command, "cat %s >> %s", outlog, MONDO_LOGFILE); 524 } 525 else 526 { 527 sprintf (command, "cat %s | cut -d':' -f%d | sort | uniq", outlog, 528 (bkpinfo->use_star)?1:2); 529 pin = popen (command, "r"); 530 if (pin) 531 { 532 for (fgets (tmp, MAX_STR_LEN, pin); !feof (pin); 533 fgets (tmp, MAX_STR_LEN, pin)) 534 { 535 if (bkpinfo->use_star) 536 { 537 if (!strstr(tmp, "diffopts=")) 538 { 539 while( strlen(tmp)>0 && tmp[strlen(tmp)-1] < 32) 540 { tmp[strlen(tmp)-1] = '\0'; } 541 if (strchr(tmp, '/') ) 542 { 543 if (!diffs) { log_msg (0, "'%s' - differences found", tarball_fname); } 544 log_msg (0,"star: /%s", strip_afio_output_line (tmp)); 545 diffs++; 399 char *tmp = NULL; 400 // char *p; 401 402 /*@ pointers ******************************************************* */ 403 FILE *pin; 404 405 int n = 0; 406 407 /*@ long *********************************************************** */ 408 long diffs = 0; 409 /* getcwd(old_pwd,MAX_STR_LEN-1); */ 410 411 assert(bkpinfo != NULL); 412 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 413 414 log_it("Verifying fileset '%s'", tarball_fname); 415 416 /* chdir("/"); */ 417 asprintf(&outlog, "%s/afio.log", bkpinfo->tmpdir); 418 419 /* if programmer forgot to say which compression thingy to use then find out */ 420 if (strstr(tarball_fname, ".lzo") 421 && strcmp(bkpinfo->zip_suffix, "lzo")) { 422 log_msg(2, "OK, I'm going to start using lzop."); 423 strcpy(bkpinfo->zip_exe, "lzop"); 424 strcpy(bkpinfo->zip_suffix, "lzo"); 425 bkpinfo->use_lzo = TRUE; 426 } 427 if (strstr(tarball_fname, ".bz2") 428 && strcmp(bkpinfo->zip_suffix, "bz2")) { 429 log_msg(2, "OK, I'm going to start using bzip2."); 430 strcpy(bkpinfo->zip_exe, "bzip2"); 431 strcpy(bkpinfo->zip_suffix, "bz2"); 432 bkpinfo->use_lzo = FALSE; 433 } 434 unlink(outlog); 435 if (strstr(tarball_fname, ".star")) { 436 bkpinfo->use_star = TRUE; 437 if (strstr(tarball_fname, ".bz2")) 438 asprintf(&command, 439 "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", 440 tarball_fname, 441 (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, 442 outlog); 443 } else { 444 bkpinfo->use_star = FALSE; 445 asprintf(&command, "afio -r -P %s -Z %s >> %s 2>> %s", 446 bkpinfo->zip_exe, tarball_fname, outlog, outlog); 447 } 448 log_msg(6, "command=%s", command); 449 paranoid_system(command); 450 paranoid_free(command); 451 452 if (length_of_file(outlog) < 10) { 453 asprintf(&command, "cat %s >> %s", outlog, MONDO_LOGFILE); 454 } else { 455 asprintf(&command, "cat %s | cut -d':' -f%d | sort | uniq", outlog, 456 (bkpinfo->use_star) ? 1 : 2); 457 pin = popen(command, "r"); 458 if (pin) { 459 for (getline(&tmp, &n, pin); !feof(pin); 460 fgets(&tmp, &n, pin)) { 461 if (bkpinfo->use_star) { 462 if (!strstr(tmp, "diffopts=")) { 463 while (strlen(tmp) > 0 464 && tmp[strlen(tmp) - 1] < 32) { 465 tmp[strlen(tmp) - 1] = '\0'; 466 } 467 if (strchr(tmp, '/')) { 468 if (!diffs) { 469 log_msg(0, "'%s' - differences found", 470 tarball_fname); 471 } 472 log_msg(0, "star: /%s", 473 strip_afio_output_line(tmp)); 474 diffs++; 475 } 476 } 477 } else { 478 if (!diffs) { 479 log_msg(0, "'%s' - differences found", 480 tarball_fname); 481 } 482 log_msg(0, "afio: /%s", strip_afio_output_line(tmp)); 483 diffs++; 484 } 546 485 } 547 } 548 } 549 else 550 { 551 if (!diffs) { log_msg (0, "'%s' - differences found", tarball_fname); } 552 log_msg (0,"afio: /%s", strip_afio_output_line (tmp)); 553 diffs++; 554 } 555 } 556 paranoid_pclose (pin); 557 } 558 else 559 { 560 log_OS_error(command); 561 } 562 } 563 /* chdir(old_pwd); */ 564 // sprintf (tmp, "cat %s | uniq -u >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE); 565 // paranoid_system (tmp); 566 // unlink ("/tmp/mondo-verify.err"); 567 paranoid_free(command); 568 paranoid_free(outlog); 569 paranoid_free(tmp); 570 return (0); 486 paranoid_pclose(pin); 487 paranoid_free(tmp); 488 } else { 489 log_OS_error(command); 490 } 491 } 492 paranoid_free(outlog); 493 paranoid_free(command); 494 495 /* chdir(old_pwd); */ 496 // sprintf (tmp, "cat %s | uniq -u >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE); 497 // paranoid_system (tmp); 498 // unlink ("/tmp/mondo-verify.err"); 499 return (0); 571 500 } 572 573 574 575 576 501 577 502 … … 586 511 */ 587 512 int 588 verify_an_afioball_from_CD 513 verify_an_afioball_from_CD(struct s_bkpinfo *bkpinfo, char *tarball_fname) 589 514 { 590 515 591 /*@ int **************************************************************/ 592 int res = 0; 593 594 assert(bkpinfo!=NULL); 595 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 596 597 log_msg (1, "Verifying %s", tarball_fname); 598 if (!does_file_exist (tarball_fname)) 599 { 600 fatal_error ("Cannot verify nonexistent afioball"); 601 } 602 res = verify_a_tarball (bkpinfo, tarball_fname); 603 return (res); 516 /*@ int ************************************************************* */ 517 int res = 0; 518 519 assert(bkpinfo != NULL); 520 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 521 522 log_msg(1, "Verifying %s", tarball_fname); 523 if (!does_file_exist(tarball_fname)) { 524 fatal_error("Cannot verify nonexistent afioball"); 525 } 526 res = verify_a_tarball(bkpinfo, tarball_fname); 527 return (res); 604 528 } 605 529 … … 615 539 */ 616 540 int 617 verify_an_afioball_from_stream 618 541 verify_an_afioball_from_stream(struct s_bkpinfo *bkpinfo, char *orig_fname, 542 long long size) 619 543 { 620 544 621 /*@ int ************************************************************** */622 545 /*@ int ************************************************************** */ 546 int retval = 0; 623 547 int res = 0; 624 548 625 /*@ buffers ********************************************************** */626 549 /*@ buffers ********************************************************** */ 550 char *tmp; 627 551 char *tarball_fname; 628 552 629 /*@ pointers ********************************************************* */630 char 631 632 malloc_string(tmp);633 malloc_string(tarball_fname);634 assert(bkpinfo!=NULL); 635 assert_string_is_neither_NULL_nor_zerolength(orig_fname);636 637 p = strrchr (orig_fname, '/');638 if (!p) 639 { 640 p = orig_fname; 641 } 642 else 643 { 644 p++; 645 } 646 sprintf (tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 647 paranoid_system (tmp); 648 sprintf (tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);649 sprintf (tmp, "Temporarily copying file from tape to '%s'", tarball_fname); 650 /* log_it(tmp); */ 651 read_file_from_stream_to_file (bkpinfo, tarball_fname, size); 652 res = verify_a_tarball (bkpinfo, tarball_fname);653 if (res) 654 655 sprintf (tmp, "Afioball '%s' no longer matches your live filesystem",656 657 log_msg(0, tmp);658 retval++;659 } 660 unlink (tarball_fname); 661 paranoid_free(tmp);662 663 553 /*@ pointers ********************************************************* */ 554 char *p; 555 556 assert(bkpinfo != NULL); 557 assert_string_is_neither_NULL_nor_zerolength(orig_fname); 558 559 p = strrchr(orig_fname, '/'); 560 if (!p) { 561 p = orig_fname; 562 } else { 563 p++; 564 } 565 asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 566 paranoid_system(tmp); 567 paranoid_free(tmp); 568 569 asprintf(&tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p); 570 /* BERLIOS : useless 571 asprintf(&tmp, "Temporarily copying file from tape to '%s'", 572 tarball_fname); 573 log_it(tmp); 574 paranoid_free(tmp); 575 */ 576 read_file_from_stream_to_file(bkpinfo, tarball_fname, size); 577 res = verify_a_tarball(bkpinfo, tarball_fname); 578 if (res) { 579 asprintf(&tmp, 580 "Afioball '%s' no longer matches your live filesystem", p); 581 log_msg(0, tmp); 582 paranoid_free(tmp); 583 retval++; 584 } 585 unlink(tarball_fname); 586 paranoid_free(tarball_fname); 587 return (retval); 664 588 } 665 589 … … 673 597 */ 674 598 int 675 verify_a_biggiefile_from_stream (struct s_bkpinfo *bkpinfo, char *biggie_fname,676 599 verify_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, 600 char *biggie_fname, long long size) 677 601 { 678 602 679 /*@ int ************************************************************* */680 603 /*@ int ************************************************************* */ 604 int retval = 0; 681 605 int res = 0; 682 606 int current_slice_number = 0; 683 607 int ctrl_chr = '\0'; 684 608 685 /*@ char *************************************************************/609 /*@ char ************************************************************ */ 686 610 char *test_file; 687 611 char *biggie_cksum; … … 689 613 char *tmp; 690 614 char *slice_fnam; 691 692 /*@ pointers ******************************************************** */615 616 /*@ pointers ******************************************************** */ 693 617 char *p; 694 618 695 /*@ long long ******************************************************* */696 697 698 malloc_string(test_file);699 malloc_string(biggie_cksum);700 malloc_string(orig_cksum);701 malloc_string(tmp); 702 malloc_string(slice_fnam);703 assert(bkpinfo!=NULL); 704 assert_string_is_neither_NULL_nor_zerolength(biggie_fname);705 706 p = strrchr (biggie_fname, '/');707 if (!p) 708 { 709 p = biggie_fname; 710 } 711 else 712 { 713 p++; 714 } 715 sprintf (test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); 716 sprintf (tmp, 717 "Temporarily copying biggiefile %s's slices from tape to '%s'", p,718 test_file);719 /* log_it(tmp); */ 720 for (res = read_header_block_from_stream (&slice_siz, slice_fnam, &ctrl_chr);721 ctrl_chr != BLK_STOP_A_BIGGIE; 722 res = read_header_block_from_stream (&slice_siz, slice_fnam, &ctrl_chr)) 723 { 724 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) 725 {726 wrong_marker (BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);727 }728 res = read_file_from_stream_to_file (bkpinfo, test_file, slice_siz); 729 unlink (test_file);730 res = read_header_block_from_stream (&slice_siz, slice_fnam, &ctrl_chr);731 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) 732 {733 log_msg (2, "test_file = %s", test_file); 734 wrong_marker (BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);735 }736 current_slice_number++; 737 retval += res; 738 } 739 strcpy (biggie_cksum, slice_fnam); 740 if (biggie_cksum[0] != '\0') 741 { 742 strcpy (orig_cksum, calc_checksum_of_file (biggie_fname));743 if (strcmp (biggie_cksum, orig_cksum)) 744 { 745 sprintf (tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,746 orig_cksum);747 log_msg (2,tmp);748 sprintf (tmp, "%s has changed on live filesystem", biggie_fname);749 log_to_screen (tmp); 750 sprintf(tmp, "echo \"%s\" >> /tmp/biggies.changed", biggie_fname);751 system(tmp);752 }753 } 754 paranoid_free(test_file); 755 paranoid_free(biggie_cksum);756 paranoid_free(orig_cksum); 757 paranoid_free(tmp);758 paranoid_free(slice_fnam); 759 619 /*@ long long ******************************************************* */ 620 long long slice_siz; 621 622 malloc_string(slice_fnam); 623 assert(bkpinfo != NULL); 624 assert_string_is_neither_NULL_nor_zerolength(biggie_fname); 625 626 p = strrchr(biggie_fname, '/'); 627 if (!p) { 628 p = biggie_fname; 629 } else { 630 p++; 631 } 632 asprintf(&test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); 633 /* BERLIOS: useless 634 asprintf(&tmp, 635 "Temporarily copying biggiefile %s's slices from tape to '%s'", 636 p, test_file); 637 log_it(tmp); 638 paranoid_free(tmp); 639 */ 640 for (res = read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 641 ctrl_chr != BLK_STOP_A_BIGGIE; 642 res = read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr)) { 643 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 644 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 645 } 646 res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz); 647 unlink(test_file); 648 res = read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 649 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 650 log_msg(2, "test_file = %s", test_file); 651 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 652 } 653 current_slice_number++; 654 retval += res; 655 } 656 paranoid_free(test_file); 657 658 asprintf(&biggie_cksum, slice_fnam); 659 paranoid_free(slice_fnam); 660 661 if (biggie_cksum[0] != '\0') { 662 asprintf(&orig_cksum, calc_checksum_of_file(biggie_fname)); 663 if (strcmp(biggie_cksum, orig_cksum)) { 664 asprintf(&tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum, 665 orig_cksum); 666 log_msg(2, tmp); 667 paranoid_free(tmp); 668 669 asprintf(&tmp, "%s has changed on live filesystem", 670 biggie_fname); 671 log_to_screen(tmp); 672 paranoid_free(tmp); 673 674 asprintf(&tmp, "echo \"%s\" >> /tmp/biggies.changed", 675 biggie_fname); 676 system(tmp); 677 paranoid_free(tmp); 678 } 679 paranoid_free(orig_cksum); 680 } 681 paranoid_free(biggie_cksum); 682 683 return (retval); 760 684 } 761 685 … … 769 693 * @return 0 for success (even if there are differences); nonzero for a tape error. 770 694 */ 771 int 772 verify_afioballs_from_stream (struct s_bkpinfo *bkpinfo) 695 int verify_afioballs_from_stream(struct s_bkpinfo *bkpinfo) 773 696 { 774 /*@ int ********************************************************** */775 697 /*@ int ********************************************************** */ 698 int retval = 0; 776 699 int res = 0; 777 700 long current_afioball_number = 0; … … 779 702 int total_afioballs = 0; 780 703 781 /*@ buffers ***************************************************** */782 704 /*@ buffers ***************************************************** */ 705 char *tmp; 783 706 char *fname; 784 char *curr_xattr_list_fname; 785 char *curr_acl_list_fname; 786 787 /*@ long long ****************************************************/ 788 long long size = 0; 789 790 assert(bkpinfo!=NULL); 791 malloc_string(tmp); 792 malloc_string(fname); 793 malloc_string(curr_xattr_list_fname); 794 malloc_string(curr_acl_list_fname); 795 796 sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 797 sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 798 log_to_screen ("Verifying regular archives on tape"); 799 total_afioballs = get_last_filelist_number (bkpinfo) + 1; 800 open_progress_form ("Verifying filesystem", 801 "I am verifying archives against your live filesystem now.", 802 "Please wait. This may take a couple of hours.", "", 803 total_afioballs); 804 res = read_header_block_from_stream (&size, fname, &ctrl_chr); 805 if (ctrl_chr != BLK_START_AFIOBALLS) 806 { 807 iamhere("YOU SHOULD NOT GET HERE"); 808 iamhere("Grabbing the EXAT files"); 809 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) 810 { 811 res = read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr, curr_xattr_list_fname, curr_acl_list_fname); 812 } 813 } 814 if (ctrl_chr != BLK_START_AFIOBALLS) 815 { wrong_marker (BLK_START_AFIOBALLS, ctrl_chr); } 816 817 for (res = read_header_block_from_stream (&size, fname, &ctrl_chr); 818 ctrl_chr != BLK_STOP_AFIOBALLS; 819 res = read_header_block_from_stream (&size, fname, &ctrl_chr)) 820 { 821 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, current_afioball_number); 822 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, current_afioball_number); 823 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) 824 { 825 iamhere("Reading EXAT files from tape"); 826 res = read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr, curr_xattr_list_fname, curr_acl_list_fname); 827 } 828 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) 829 { 830 wrong_marker (BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 831 } 832 sprintf (tmp, "Verifying fileset #%ld", current_afioball_number); 833 /*log_it(tmp); */ 834 update_progress_form (tmp); 835 res = verify_an_afioball_from_stream (bkpinfo, fname, size); 836 if (res) 837 { 838 sprintf (tmp, "Afioball %ld differs from live filesystem", 839 current_afioball_number); 840 log_to_screen (tmp); 841 } 842 retval += res; 843 current_afioball_number++; 844 g_current_progress++; 845 res = read_header_block_from_stream (&size, fname, &ctrl_chr); 846 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) 847 { 848 wrong_marker (BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 849 } 850 } 851 log_msg (1, "All done with afioballs"); 852 close_progress_form (); 853 paranoid_free(tmp); 854 paranoid_free(fname); 855 paranoid_free(curr_xattr_list_fname); 856 paranoid_free(curr_acl_list_fname); 857 return (retval); 707 char *curr_xattr_list_fname; 708 char *curr_acl_list_fname; 709 710 /*@ long long *************************************************** */ 711 long long size = 0; 712 713 assert(bkpinfo != NULL); 714 malloc_string(fname); 715 716 asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, 717 bkpinfo->tmpdir); 718 asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ, 719 bkpinfo->tmpdir); 720 log_to_screen("Verifying regular archives on tape"); 721 total_afioballs = get_last_filelist_number(bkpinfo) + 1; 722 open_progress_form("Verifying filesystem", 723 "I am verifying archives against your live filesystem now.", 724 "Please wait. This may take a couple of hours.", "", 725 total_afioballs); 726 res = read_header_block_from_stream(&size, fname, &ctrl_chr); 727 if (ctrl_chr != BLK_START_AFIOBALLS) { 728 iamhere("YOU SHOULD NOT GET HERE"); 729 iamhere("Grabbing the EXAT files"); 730 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 731 res = 732 read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr, 733 curr_xattr_list_fname, 734 curr_acl_list_fname); 735 } 736 } 737 if (ctrl_chr != BLK_START_AFIOBALLS) { 738 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr); 739 } 740 paranoid_free(curr_xattr_list_fname); 741 paranoid_free(curr_acl_list_fname); 742 743 for (res = read_header_block_from_stream(&size, fname, &ctrl_chr); 744 ctrl_chr != BLK_STOP_AFIOBALLS; 745 res = read_header_block_from_stream(&size, fname, &ctrl_chr)) { 746 asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, 747 bkpinfo->tmpdir, current_afioball_number); 748 asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, 749 bkpinfo->tmpdir, current_afioball_number); 750 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 751 iamhere("Reading EXAT files from tape"); 752 res = 753 read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr, 754 curr_xattr_list_fname, 755 curr_acl_list_fname); 756 } 757 paranoid_free(curr_xattr_list_fname); 758 paranoid_free(curr_acl_list_fname); 759 760 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 761 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 762 } 763 asprintf(&tmp, "Verifying fileset #%ld", current_afioball_number); 764 /*log_it(tmp); */ 765 update_progress_form(tmp); 766 paranoid_free(tmp); 767 768 res = verify_an_afioball_from_stream(bkpinfo, fname, size); 769 if (res) { 770 asprintf(&tmp, "Afioball %ld differs from live filesystem", 771 current_afioball_number); 772 log_to_screen(tmp); 773 paranoid_free(tmp); 774 } 775 retval += res; 776 current_afioball_number++; 777 g_current_progress++; 778 res = read_header_block_from_stream(&size, fname, &ctrl_chr); 779 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 780 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 781 } 782 } 783 log_msg(1, "All done with afioballs"); 784 close_progress_form(); 785 paranoid_free(fname); 786 return (retval); 858 787 } 788 859 789 860 790 /** … … 866 796 * @return 0 for success (even if there are differences); nonzero for a tape error. 867 797 */ 868 int 869 verify_biggiefiles_from_stream (struct s_bkpinfo *bkpinfo) 798 int verify_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo) 870 799 { 871 800 872 /*@ int ************************************************************ */873 801 /*@ int ************************************************************ */ 802 int retval = 0; 874 803 int res = 0; 875 804 int ctrl_chr = 0; 876 805 877 /*@ long *********************************************************** */878 806 /*@ long *********************************************************** */ 807 long noof_biggiefiles = 0; 879 808 long current_biggiefile_number = 0; 880 809 881 /*@ buffers ******************************************************** */882 810 /*@ buffers ******************************************************** */ 811 char *tmp; 883 812 char *orig_fname, *logical_fname; 884 813 char *comment; 885 814 char *curr_xattr_list_fname; 886 815 char *curr_acl_list_fname; 887 /*@ pointers ******************************************************* */816 /*@ pointers ******************************************************* */ 888 817 char *p; 889 818 890 /*@ long long size **************************************************/ 891 long long size = 0; 892 893 assert(bkpinfo!=NULL); 894 malloc_string(tmp); 895 malloc_string(orig_fname); 896 malloc_string(logical_fname); 897 malloc_string(comment); 898 malloc_string(curr_xattr_list_fname); 899 malloc_string(curr_acl_list_fname); 900 901 sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 902 sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 903 sprintf (comment, "Verifying all bigfiles."); 904 log_to_screen (comment); 905 sprintf (tmp, "%s/biggielist.txt", bkpinfo->tmpdir); 906 // noof_biggiefiles = count_lines_in_file (tmp); // pointless 907 res = read_header_block_from_stream (&size, orig_fname, &ctrl_chr); 908 if (ctrl_chr != BLK_START_BIGGIEFILES) 909 { 910 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) 911 { 912 iamhere("Grabbing the EXAT biggiefiles"); 913 res = read_EXAT_files_from_tape(bkpinfo, &size, orig_fname, &ctrl_chr, curr_xattr_list_fname, curr_acl_list_fname); 914 } 915 } 916 if (ctrl_chr != BLK_START_BIGGIEFILES) 917 { 918 wrong_marker (BLK_START_BIGGIEFILES, ctrl_chr); 919 } 920 noof_biggiefiles = (long)size; 921 log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles); 922 open_progress_form ("Verifying big files", comment, 923 "Please wait. This may take some time.", "", 924 noof_biggiefiles); 925 for (res = read_header_block_from_stream (&size, orig_fname, &ctrl_chr); 926 ctrl_chr != BLK_STOP_BIGGIEFILES; 927 res = read_header_block_from_stream (&size, orig_fname, &ctrl_chr)) 928 { 929 if (ctrl_chr != BLK_START_A_NORMBIGGIE && ctrl_chr != BLK_START_A_PIHBIGGIE) 819 /*@ long long size ************************************************* */ 820 long long size = 0; 821 822 assert(bkpinfo != NULL); 823 malloc_string(orig_fname); 824 825 asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, 826 bkpinfo->tmpdir); 827 asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ, 828 bkpinfo->tmpdir); 829 asprintf(&comment, "Verifying all bigfiles."); 830 log_to_screen(comment); 831 /* 832 asprintf(&tmp, "%s/biggielist.txt", bkpinfo->tmpdir); 833 noof_biggiefiles = count_lines_in_file (tmp); // pointless 834 paranoid_free(tmp); 835 */ 836 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); 837 if (ctrl_chr != BLK_START_BIGGIEFILES) { 838 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 839 iamhere("Grabbing the EXAT biggiefiles"); 840 res = 841 read_EXAT_files_from_tape(bkpinfo, &size, orig_fname, 842 &ctrl_chr, curr_xattr_list_fname, 843 curr_acl_list_fname); 844 } 845 } 846 paranoid_free(curr_xattr_list_fname); 847 paranoid_free(curr_acl_list_fname); 848 849 if (ctrl_chr != BLK_START_BIGGIEFILES) { 850 wrong_marker(BLK_START_BIGGIEFILES, ctrl_chr); 851 } 852 noof_biggiefiles = (long) size; 853 log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles); 854 open_progress_form("Verifying big files", comment, 855 "Please wait. This may take some time.", "", 856 noof_biggiefiles); 857 paranoid_free(comment); 858 859 for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); 860 ctrl_chr != BLK_STOP_BIGGIEFILES; 861 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr)) 930 862 { 931 wrong_marker (BLK_START_A_NORMBIGGIE, ctrl_chr); 932 } 933 p = strrchr (orig_fname, '/'); 934 if (!p) 935 { 936 p = orig_fname; 937 } 938 else 939 { 940 p++; 941 } 942 sprintf (comment, "Verifying bigfile #%ld (%ld K)", 943 current_biggiefile_number, (long) size >> 10); 944 update_progress_form (comment); 945 sprintf( logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname); 946 res = verify_a_biggiefile_from_stream (bkpinfo, logical_fname, size); 947 retval += res; 948 current_biggiefile_number++; 949 g_current_progress++; 950 } 951 close_progress_form (); 952 paranoid_free(orig_fname); 953 paranoid_free(logical_fname); 954 paranoid_free(curr_xattr_list_fname); 955 paranoid_free(curr_acl_list_fname); 956 paranoid_free(comment); 957 paranoid_free(tmp); 958 return (retval); 863 if (ctrl_chr != BLK_START_A_NORMBIGGIE 864 && ctrl_chr != BLK_START_A_PIHBIGGIE) { 865 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr); 866 } 867 p = strrchr(orig_fname, '/'); 868 if (!p) { 869 p = orig_fname; 870 } else { 871 p++; 872 } 873 asprintf(&comment, "Verifying bigfile #%ld (%ld K)", 874 current_biggiefile_number, (long) size >> 10); 875 update_progress_form(comment); 876 paranoid_free(comment); 877 878 asprintf(&logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname); 879 res = verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size); 880 paranoid_free(logical_fname); 881 retval += res; 882 current_biggiefile_number++; 883 g_current_progress++; 884 } 885 close_progress_form(); 886 paranoid_free(orig_fname); 887 return (retval); 959 888 } 960 889 … … 976 905 * @ingroup verifyGroup 977 906 */ 978 int 979 verify_cd_image (struct s_bkpinfo *bkpinfo) 907 int verify_cd_image(struct s_bkpinfo *bkpinfo) 980 908 { 981 909 982 /*@ int ************************************************************ */983 984 985 /*@ buffers ******************************************************** */986 910 /*@ int ************************************************************ */ 911 int retval = 0; 912 913 /*@ buffers ******************************************************** */ 914 char *mountpoint; 987 915 char *command; 988 916 char *tmp; 989 917 char *fname; 990 918 #ifdef __FreeBSD__ 991 919 char mdd[32]; 992 920 char *mddevice = mdd; 993 int ret = 0; int vndev = 2; 921 int ret = 0; 922 int vndev = 2; 994 923 #else 995 924 //skip 996 925 #endif 997 926 998 command = malloc(2000); 999 malloc_string(mountpoint); 1000 malloc_string(tmp); 1001 malloc_string(fname); 1002 1003 assert(bkpinfo!=NULL); 1004 1005 sprintf (mountpoint, "%s/cdrom", bkpinfo->tmpdir); 1006 sprintf (fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, 1007 bkpinfo->nfs_remote_dir, g_current_media_number); 1008 1009 mkdir (mountpoint, 1777); 1010 sync (); 1011 if (!does_file_exist (fname)) 1012 { 1013 sprintf (tmp, 1014 "%s not found; assuming you backed up to CD; verifying CD...", 1015 fname); 1016 log_msg (2, tmp); 1017 if (bkpinfo->manual_cd_tray) 1018 { 1019 popup_and_OK ("Please push CD tray closed."); 1020 } 1021 if (find_and_mount_actual_cd (bkpinfo, mountpoint)) 1022 { 1023 log_to_screen ("failed to mount actual CD"); 1024 return (1); 1025 } 1026 } 1027 else 1028 { 1029 sprintf (tmp, "%s found; verifying ISO...", fname); 927 assert(bkpinfo != NULL); 928 929 asprintf(&mountpoint, "%s/cdrom", bkpinfo->tmpdir); 930 asprintf(&fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, 931 bkpinfo->nfs_remote_dir, g_current_media_number); 932 933 mkdir(mountpoint, 1777); 934 sync(); 935 if (!does_file_exist(fname)) { 936 asprintf(&tmp, 937 "%s not found; assuming you backed up to CD; verifying CD...", 938 fname); 939 log_msg(2, tmp); 940 paranoid_free(tmp); 941 942 if (bkpinfo->manual_cd_tray) { 943 popup_and_OK("Please push CD tray closed."); 944 } 945 if (find_and_mount_actual_cd(bkpinfo, mountpoint)) { 946 log_to_screen("failed to mount actual CD"); 947 return (1); 948 } 949 } else { 950 asprintf(&tmp, "%s found; verifying ISO...", fname); 951 log_to_screen(tmp); 952 paranoid_free(tmp); 1030 953 #ifdef __FreeBSD__ 1031 ret = 0; 1032 vndev = 2; 1033 mddevice = make_vn (fname); 1034 if (ret) 1035 { 1036 sprintf (tmp, "make_vn of %s failed; unable to verify ISO\n", fname); 1037 log_to_screen (tmp); 1038 return (1); 1039 } 1040 sprintf (command, "mount_cd9660 %s %s", mddevice, mountpoint); 954 ret = 0; 955 vndev = 2; 956 mddevice = make_vn(fname); 957 if (ret) { 958 asprintf(&tmp, "make_vn of %s failed; unable to verify ISO\n", 959 fname); 960 log_to_screen(tmp); 961 paranoid_free(tmp); 962 return (1); 963 } 964 asprintf(&command, "mount_cd9660 %s %s", mddevice, mountpoint); 1041 965 #else 1042 sprintf (command, "mount -o loop,ro -t iso9660 %s %s", fname,1043 966 asprintf(&command, "mount -o loop,ro -t iso9660 %s %s", fname, 967 mountpoint); 1044 968 #endif 1045 if (run_program_and_log_output(command, FALSE)) 1046 { 1047 sprintf (tmp, "%s failed; unable to mount ISO image\n", command); 1048 log_to_screen (tmp); 1049 return (1); 1050 } 1051 } 1052 log_msg (2, "OK, I've mounted the ISO/CD\n"); 1053 sprintf (tmp, "%s/archives/NOT-THE-LAST", mountpoint); 1054 if (!does_file_exist (tmp)) 1055 { 1056 log_msg 1057 (2, "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE."); 1058 bkpinfo->verify_data = FALSE; 969 if (run_program_and_log_output(command, FALSE)) { 970 asprintf(&tmp, "%s failed; unable to mount ISO image\n", 971 command); 972 log_to_screen(tmp); 973 paranoid_free(tmp); 974 return (1); 975 } 976 paranoid_free(command); 977 } 978 log_msg(2, "OK, I've mounted the ISO/CD\n"); 979 asprintf(&tmp, "%s/archives/NOT-THE-LAST", mountpoint); 980 if (!does_file_exist(tmp)) { 981 log_msg 982 (2, 983 "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE."); 984 bkpinfo->verify_data = FALSE; 1059 985 /* 1060 986 (a) It's an easy way to tell the calling subroutine that we've finished & … … 1062 988 from running after the per-CD verifier has run too. 1063 989 */ 1064 } 1065 verify_afioballs_on_CD (bkpinfo, mountpoint); 1066 iamhere("before verify_all_slices"); 1067 verify_all_slices_on_CD (bkpinfo, mountpoint); 990 } 991 paranoid_free(tmp); 992 993 verify_afioballs_on_CD(bkpinfo, mountpoint); 994 iamhere("before verify_all_slices"); 995 verify_all_slices_on_CD(bkpinfo, mountpoint); 1068 996 1069 997 #ifdef __FreeBSD__ 1070 ret=0; 1071 sprintf (command, "umount %s", mountpoint); 1072 ret += system (command); 1073 ret += kick_vn (mddevice); 1074 if (ret) 998 ret = 0; 999 asprintf(&command, "umount %s", mountpoint); 1000 ret += system(command); 1001 1002 ret += kick_vn(mddevice); 1003 if (ret) 1075 1004 #else 1076 sprintf (command, "umount %s", mountpoint); 1077 if (system (command)) 1005 asprintf(&command, "umount %s", mountpoint); 1006 1007 if (system(command)) 1078 1008 #endif 1079 {1080 sprintf (tmp, "%s failed; unable to unmount ISO image\n", command);1081 log_to_screen (tmp);1082 retval++;1083 }1084 else1085 {1086 log_msg (2, "OK, I've unmounted the ISO file\n");1087 }1088 if (!does_file_exist (fname))1089 {1090 sprintf(command, "umount %s", bkpinfo->media_device);1091 run_program_and_log_output(command, 2);1092 if (!bkpinfo->please_dont_eject && eject_device(bkpinfo->media_device))1093 1009 { 1094 log_msg (2, "Failed to eject CD-ROM drive"); 1095 } 1096 } 1097 paranoid_free(command); 1098 paranoid_free(mountpoint); 1099 paranoid_free(tmp); 1100 paranoid_free(fname); 1101 return (retval); 1010 asprintf(&tmp, "%s failed; unable to unmount ISO image\n", command); 1011 log_to_screen(tmp); 1012 paranoid_free(tmp); 1013 retval++; 1014 } else { 1015 log_msg(2, "OK, I've unmounted the ISO file\n"); 1016 } 1017 paranoid_free(command); 1018 paranoid_free(mountpoint); 1019 1020 if (!does_file_exist(fname)) { 1021 asprintf(&command, "umount %s", bkpinfo->media_device); 1022 run_program_and_log_output(command, 2); 1023 paranoid_free(command); 1024 1025 if (!bkpinfo->please_dont_eject 1026 && eject_device(bkpinfo->media_device)) { 1027 log_msg(2, "Failed to eject CD-ROM drive"); 1028 } 1029 } 1030 paranoid_free(fname); 1031 return (retval); 1102 1032 } 1033 1103 1034 1104 1035 /** … … 1109 1040 * @ingroup verifyGroup 1110 1041 */ 1111 int 1112 verify_tape_backups (struct s_bkpinfo *bkpinfo) 1042 int verify_tape_backups(struct s_bkpinfo *bkpinfo) 1113 1043 { 1114 1044 1115 /*@ int *************************************************************/ 1116 int retval = 0; 1117 1118 /*@ buffers *********************************************************/ 1119 char tmp[MAX_STR_LEN]; 1120 char changed_files_fname[MAX_STR_LEN]; 1121 1122 /*@ long ************************************************************/ 1123 long diffs = 0; 1124 1125 assert(bkpinfo!=NULL); 1126 1127 log_msg (3, "verify_tape_backups --- starting"); 1128 log_to_screen ("Verifying backups"); 1129 openin_tape (bkpinfo); 1130 /* verify archives themselves */ 1131 retval += verify_afioballs_from_stream (bkpinfo); 1132 retval += verify_biggiefiles_from_stream (bkpinfo); 1133 /* find the final blocks */ 1134 paranoid_system ("sync"); 1135 sleep (2); 1136 closein_tape (bkpinfo); 1137 /* close tape; exit */ 1138 // fclose(g_tape_stream); <-- not needed; is handled by closein_tape() 1139 paranoid_system("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null"); 1140 sprintf (changed_files_fname, "/tmp/changed.files.%d", (int)(random()%32767)); 1141 sprintf (tmp, 1142 "cat %s | grep -x \"%s:.*\" | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"dev/.*\" > %s", 1143 MONDO_LOGFILE, (bkpinfo->use_star)?"star":"afio", changed_files_fname); 1144 log_msg (2, "Running command to derive list of changed files"); 1145 log_msg (2, tmp); 1146 if (system (tmp)) 1147 { 1148 if (does_file_exist(changed_files_fname) && length_of_file(changed_files_fname)>2) 1149 { log_to_screen("Warning - unable to check logfile to derive list of changed files"); } 1150 else 1151 { log_to_screen("No differences found. Therefore, no 'changed.files' text file."); } 1152 } 1153 sprintf(tmp, "cat /tmp/biggies.changed >> %s", changed_files_fname); 1154 paranoid_system(tmp); 1155 1156 diffs = count_lines_in_file (changed_files_fname); 1157 if (diffs > 0) 1158 { 1159 sprintf (tmp, "cp -f %s %s", changed_files_fname, "/tmp/changed.files"); 1160 run_program_and_log_output(tmp, FALSE); 1161 sprintf (tmp, 1162 "%ld files differed from live filesystem; type less %s or less %s to see", 1163 diffs, changed_files_fname, "/tmp/changed.files"); 1164 log_msg (0, tmp); 1165 log_to_screen ("See /tmp/changed.files for a list of nonmatching files."); 1166 log_to_screen ("The files probably changed on filesystem, not on backup media."); 1167 // retval++; 1168 } 1169 return (retval); 1045 /*@ int ************************************************************ */ 1046 int retval = 0; 1047 1048 /*@ buffers ******************************************************** */ 1049 char *tmp; 1050 char *changed_files_fname; 1051 1052 /*@ long *********************************************************** */ 1053 long diffs = 0; 1054 1055 assert(bkpinfo != NULL); 1056 1057 log_msg(3, "verify_tape_backups --- starting"); 1058 log_to_screen("Verifying backups"); 1059 openin_tape(bkpinfo); 1060 1061 /* verify archives themselves */ 1062 retval += verify_afioballs_from_stream(bkpinfo); 1063 retval += verify_biggiefiles_from_stream(bkpinfo); 1064 1065 /* find the final blocks */ 1066 paranoid_system("sync"); 1067 sleep(2); 1068 closein_tape(bkpinfo); 1069 1070 /* close tape; exit */ 1071 // fclose(g_tape_stream); <-- not needed; is handled by closein_tape() 1072 paranoid_system 1073 ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null"); 1074 asprintf(&changed_files_fname, "/tmp/changed.files.%d", 1075 (int) (random() % 32767)); 1076 asprintf(&tmp, 1077 "cat %s | grep -x \"%s:.*\" | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"dev/.*\" > %s", 1078 MONDO_LOGFILE, (bkpinfo->use_star) ? "star" : "afio", 1079 changed_files_fname); 1080 log_msg(2, "Running command to derive list of changed files"); 1081 log_msg(2, tmp); 1082 if (system(tmp)) { 1083 if (does_file_exist(changed_files_fname) 1084 && length_of_file(changed_files_fname) > 2) { 1085 log_to_screen 1086 ("Warning - unable to check logfile to derive list of changed files"); 1087 } else { 1088 log_to_screen 1089 ("No differences found. Therefore, no 'changed.files' text file."); 1090 } 1091 } 1092 paranoid_free(tmp); 1093 1094 asprintf(&tmp, "cat /tmp/biggies.changed >> %s", changed_files_fname); 1095 paranoid_system(tmp); 1096 paranoid_free(tmp); 1097 1098 diffs = count_lines_in_file(changed_files_fname); 1099 if (diffs > 0) { 1100 asprintf(&tmp, "cp -f %s %s", changed_files_fname, 1101 "/tmp/changed.files"); 1102 run_program_and_log_output(tmp, FALSE); 1103 paranoid_free(tmp); 1104 1105 asprintf(&tmp, 1106 "%ld files differed from live filesystem; type less %s or less %s to see", 1107 diffs, changed_files_fname, "/tmp/changed.files"); 1108 log_msg(0, tmp); 1109 paranoid_free(tmp); 1110 1111 log_to_screen 1112 ("See /tmp/changed.files for a list of nonmatching files."); 1113 log_to_screen 1114 ("The files probably changed on filesystem, not on backup media."); 1115 // retval++; 1116 } 1117 paranoid_free(changed_files_fname); 1118 return (retval); 1170 1119 } 1171 1172 1120 1173 1121 … … 1181 1129 * @ingroup stringGroup 1182 1130 */ 1183 char * 1184 vfy_tball_fname (struct s_bkpinfo *bkpinfo, char *mountpoint,int setno)1131 char *vfy_tball_fname(struct s_bkpinfo *bkpinfo, char *mountpoint, 1132 int setno) 1185 1133 { 1186 /*@ buffers ******************************************************* */1187 static char output[MAX_STR_LEN];1188 1189 assert(bkpinfo!=NULL);1190 1191 sprintf (output, "%s/archives/%d.star.%s", mountpoint, setno,1192 1193 if (!does_file_exist(output)) 1194 { 1195 sprintf (output, "%s/archives/%d.afio.%s", mountpoint, setno,1196 1197 1198 1134 /*@ buffers ******************************************************* */ 1135 static char *output; 1136 1137 assert(bkpinfo != NULL); 1138 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 1139 asprintf(&output, "%s/archives/%d.star.%s", mountpoint, setno, 1140 bkpinfo->zip_suffix); 1141 if (!does_file_exist(output)) { 1142 paranoid_free(output); 1143 asprintf(&output, "%s/archives/%d.afio.%s", mountpoint, setno, 1144 bkpinfo->zip_suffix); 1145 } 1146 return (output); 1199 1147 }
Note:
See TracChangeset
for help on using the changeset viewer.