- Timestamp:
- Sep 30, 2009, 4:44:40 AM (16 years ago)
- Location:
- branches/2.2.10
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mindi/deplist.d/base.conf
r2409 r2444 32 32 33 33 /usr/bin/bzip2 34 # is a link => No additional place 34 35 /usr/bin/bunzip2 35 36 /usr/bin/lzop 37 /usr/bin/lzma 36 38 39 /bin/bash 37 40 /bin/date 38 41 /sbin/ctrlaltdel -
branches/2.2.10/mindi/deplist.d/minimal.conf
r2410 r2444 7 7 8 8 # Base Unix commands 9 /bin/bash10 9 /bin/mt 11 10 /bin/awk … … 16 15 /bin/df 17 16 /usr/bin/loadkeys 17 /sbin/pidof 18 18 19 19 # Compression 20 /bin/gunzip21 20 /bin/gzip 22 21 … … 34 33 /sbin/mount.fuse 35 34 /usr/bin/fusermount 35 /usr/bin/ssh 36 # Required by ssh as dlopened 37 /usr/lib/libnss_compat.so 38 /usr/lib64/libnss_compat.so 39 /usr/lib/libnss_files.so 40 /usr/lib64/libnss_files.so 41 /etc/ssh 36 42 /usr/bin/ulockmgr_server 37 43 /sbin/mount.cifs … … 58 64 /sbin/udev 59 65 /sbin/udevstart 66 /sbin/create_static_dev_nodes 60 67 /etc/init.d/functions 61 68 -
branches/2.2.10/mindi/deplist.d/net.conf
r2410 r2444 6 6 # SSH support 7 7 /usr/sbin/sshd 8 /usr/bin/ssh9 8 /usr/bin/scp 10 9 -
branches/2.2.10/mindi/mindi
r2428 r2444 19 19 KERVER=$KERVERRUN 20 20 21 ADDITIONAL_BOOT_PARAMS="devfs=nomount noresume selinux=0 barrier=off" 21 # In case of problem with udev you can try to add udevdebug 22 ADDITIONAL_BOOT_PARAMS="devfs=nomount noresume selinux=0 barrier=off udevtimeout=10" 22 23 23 24 MINDI_REV=PBREV … … 471 472 [ "$r" -ne "0" ] && LogAll "$incoming not found" 472 473 res=$(($res+$r)) 473 # echo "'$incoming' generates filelist '$filelist'" >> $LOGFILE474 # LogFile "'$incoming' generates filelist '$filelist'" 474 475 for fname in $filelist ; do 475 476 [ "$fname" != "" ] && echo "$fname" >> $tempfile … … 611 612 612 613 # Check kernel filesystem capabilites for accessing initrd image 614 # Could be ext2 FS (old mode) or initramfs (new mode) 613 615 # 614 616 # Interface definition: … … 646 648 if [ $? -eq 0 ]; then 647 649 lvScanRes=`gzip -cd $lvKernelImage | strings | grep -E "$lcMagicCramfs|$lcMagicExt2fs|$lcMagicExt3fs|$lcMagicInitfs"` 648 else 649 # Since 2.6.30 kernel can use lzma and bzip2 in addition to gzip for initramfs compression 650 # get offet of gzip magic "1f8b0800" in file (or 1f8b9e ??) 651 lvOffset=`od -vA n -t x1 $lvKernelImage | tr -d '[:space:]' | awk '{ print match($0, "1f8b0800")}'` 652 if [ $lvOffset -eq 0 ]; then 653 # get offet of bzip2 magic "425a" in file 654 lvOffset=`od -vA n -t x1 $lvKernelImage | tr -d '[:space:]' | awk '{ print match($0, "425a")}'` 655 if [ $lvOffset -eq 0 ]; then 656 # get offet of lzma magic "5d00" in file 657 lvOffset=`od -vA n -t x1 $lvKernelImage | tr -d '[:space:]' | awk '{ print match($0, "5d00")}'` 658 if [ $lvOffset -eq 0 ]; then 659 Die "No magic compression pattern found in file $lvKernelImage. Terminating." 660 else 661 comp="lzma" 662 fi 663 else 664 comp="bzip2" 665 fi 650 651 # determine which filesystem to use for initrd image: ext2|3fs, gzip'ed cpio (initramfs) or cramfs 652 if [ `echo $lvScanRes | grep -Ec "$lcMagicExt2fs"` -eq 1 ]; then 653 lvUseFilesystem="ext2fs" 654 elif [ `echo $lvScanRes | grep -Ec "$lcMagicExt3fs"` -eq 1 ]; then 655 lvUseFilesystem="ext3fs" 656 elif [ `echo $lvScanRes | grep -Ec "$lcMagicInitfs"` -eq 1 ]; then 657 lvUseFilesystem="initramfs" 658 elif [ `echo $lvScanRes | grep -Ec "$lcMagicCramfs"` -eq 1 ]; then 659 lvUseFilesystem="cramfs" 666 660 else 667 comp="gzip" 668 fi 669 670 lvOffset=`expr $lvOffset / 2` 671 LogFile " GetInitrdFilesystemToUse(): $comp magic found in $lvKernelImage at lvOffset $lvOffset.\n" 672 673 # scan kernel image for initrd filessystem support 674 lvScanRes=`dd ibs=1 skip=$lvOffset if=$lvKernelImage obs=1M 2>/dev/null | $comp -dc 2> /dev/null | strings | grep -E "$lcMagicCramfs|$lcMagicExt2fs|$lcMagicExt3fs|$lcMagicInitfs"` 675 fi 676 677 # determine which filesystem to use for initrd image: ext2fs, gzip'ed cpio (initramfs ) or cramfs 678 if [ `echo $lvScanRes | grep -Ec "$lcMagicExt2fs"` -eq 1 ]; then 679 lvUseFilesystem="ext2fs" 680 elif [ `echo $lvScanRes | grep -Ec "$lcMagicExt3fs"` -eq 1 ]; then 681 lvUseFilesystem="ext3fs" 682 elif [ `echo $lvScanRes | grep -Ec "$lcMagicInitfs"` -eq 1 ]; then 661 lvUseFilesystem="UNSUPPORTED" 662 fi 663 664 else 665 # In that case, we are after 2.6.30 and use the supported initramfs 683 666 lvUseFilesystem="initramfs" 684 elif [ `echo $lvScanRes | grep -Ec "$lcMagicCramfs"` -eq 1 ]; then 685 lvUseFilesystem="cramfs" 686 else 687 lvUseFilesystem="UNSUPPORTED" 688 fi 689 667 fi 690 668 # say what we are using 691 LogFile " GetInitrdFilesystemToUse(): Filesytem to use for init rdis $lvUseFilesystem.\n"669 LogFile " GetInitrdFilesystemToUse(): Filesytem to use for initial ramdisk is $lvUseFilesystem.\n" 692 670 693 671 # return file system to use … … 734 712 if [ -e "/vmfs/volumes" ]; then 735 713 # For VMWare ESX 3 get the device names of these volumes 736 vdf -P | grep -E '/vmfs/volumes' | awk'{print $1}'714 vdf -P | grep -E '/vmfs/volumes' | $AWK '{print $1}' 737 715 fi 738 716 return … … 1297 1275 else 1298 1276 if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then 1299 LogFile "Stupid bastard..."1277 LogFile "vfat should be used instead of dos/msdos as a partition format" 1300 1278 partition_format="vfat" 1301 1279 fi … … 1306 1284 } 1307 1285 1286 CheckMountlist() { 1287 local file=$1 1288 # Coherency verification 1289 ML0=`cat $file | wc -l` 1290 ML1=`$AWK '{print $1}' $file | sort -u | wc -l` 1291 ML2=`$AWK '{print $2}' $file | sort -u | wc -l` 1292 if [ "$ML0" -ne "$ML1" ]; then 1293 LogFile "--------------------------------------------" 1294 echo "WARNING: Duplicate device entry in mountlist" | tee -a $LOGFILE 1295 LogFile "--------------------------------------------" 1296 fi 1297 if [ "$ML0" -ne "$ML2" ]; then 1298 LogFile "--------------------------------------------" 1299 echo "WARNING: Duplicate mountpoint entry in mountlist" | tee -a $LOGFILE 1300 LogFile "------------------------------------------------" 1301 fi 1302 } 1308 1303 1309 1304 MakeSureNumberIsInteger() { … … 1822 1817 touch $mpincfile 1823 1818 if [ -a $MODPROBE_CONF ]; then 1824 includes=$( awk'/^[ \t]*include[ \t]+/ {if(NF>=2){print $2}}' $MODPROBE_CONF|sort -u)1819 includes=$($AWK '/^[ \t]*include[ \t]+/ {if(NF>=2){print $2}}' $MODPROBE_CONF|sort -u) 1825 1820 if [ -n "$includes" ]; then 1826 1821 for include in $includes … … 1930 1925 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1` 1931 1926 MakeMountlist $MINDI_TMP/mountlist.txt 1927 CheckMountlist $MINDI_TMP/mountlist.txt 1932 1928 mkdir -p $bigdir/tmp 1933 1929 cp -f $MINDI_TMP/mountlist.txt $bigdir/tmp/mountlist.txt 2>> $LOGFILE || Die "Cannot copy mountlist.txt from $MINDI_TMP to data disk" … … 1943 1939 fi 1944 1940 cat $bigdir/tmp/mountlist.txt >> $LOGFILE 1941 LogFile "-----------------------------------" 1942 1943 LogFile -en "$FILES_IN_FILELIST" > $bigdir/FILES-IN-FILELIST 1945 1944 echo -en "$LAST_FILELIST_NUMBER" > $bigdir/LAST-FILELIST-NUMBER 2>> $LOGFILE 1946 1945 if [ _"$MONDO_SHARE" != _"" ]; then … … 1968 1967 while [ "$incoming" != "" ]; do 1969 1968 # We take the full path name of the dyn. lib. we want 1970 incoming=`echo "$incoming" | awk'{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'`1969 incoming=`echo "$incoming" | $AWK '{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'` 1971 1970 for f in $incoming ; do 1972 1971 # echo modified file name if one of the parent dir is a link … … 2236 2235 # We want to use the real mount and all the supported variants (nfs, cifs, ...) 2237 2236 rm -f bin/mount $MINDI_TMP/busy.lis 2238 mountlis=`grep -E "mount|fuse|ssh" $DEPLIST_FILE $DEPLIST_DIR/* | cut -d: -f2`2239 for f in $MINDI_LIB/rootfs/bin/busybox $mountlis ; do2240 if [ -f $f ]; then2241 LocateDeps $f >> $MINDI_TMP/busy.lis2242 fi2237 mountlis=`grep -E "mount|fuse|ssh" $DEPLIST_FILE $DEPLIST_DIR/* | grep -v " *#.*" | cut -d: -f2 | sort -u` 2238 LocateDeps $MINDI_LIB/rootfs/bin/busybox $mountlis >> $MINDI_TMP/busy.lis 2239 # Special for libs 2240 for f in `grep -E "libnss" $DEPLIST_FILE $DEPLIST_DIR/* | grep -v " *#.*" | cut -d: -f2`; do 2241 echo "`ReadAllLink $f`" >> $MINDI_TMP/busy.lis 2243 2242 done 2243 # Initial / are trucated by tar 2244 2244 tar cf - $mountlis `sort -u $MINDI_TMP/busy.lis` 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Problem in mount analysis" $MINDI_TMP/$$.log 2245 2245 rm -f $MINDI_TMP/busy.lis 2246 2246 fi 2247 2248 # Copy of files mandatory for ssh to automate mount if sshfs is used 2249 mkdir $mountpoint/.ssh 2250 cp -rp ~root/.ssh/*.pub ~root/.ssh/config ~root/.ssh/known* $mountpoint/.ssh 2> /dev/null 2251 echo > $mountpoint/tmp/myssh << EOF 2252 ssh -o StrictHostKeyChecking=no $* 2253 EOF 2254 chmod 755 $mountpoint/tmp/myssh 2247 2255 2248 2256 # Copy of files mandatory for ld.so … … 2396 2404 mkdir -p $mountpoint/proc 2397 2405 echo "$BOOT_SIZE" > $mountpoint/tmp/$BOOT_SIZE.siz 2406 2407 LogFile "---------------------------" 2408 LogFile "Content of initial ramdisk:" 2409 LogFile "---------------------------" 2410 (cd $mountpoint ; ls -Rla ) >> $LOGFILE 2411 LogFile "---------------------------" 2412 2398 2413 # Determine what filesystem to use for initrd image 2399 2414 LogFile "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd." … … 2596 2611 LogFile "-------------" 2597 2612 lsmod >> $LOGFILE 2598 MODULES="`cat /proc/modules | awk'{print $1}'`"2613 MODULES="`cat /proc/modules | $AWK '{print $1}'`" 2599 2614 if [ -x /usr/sbin/esxcfg-module ]; then 2600 2615 LogFile "-------------" … … 2604 2619 LogFile "-------------" 2605 2620 /usr/sbin/esxcfg-module -l >> $LOGFILE 2606 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | awk'{print $1}'`"2621 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | $AWK '{print $1}'`" 2607 2622 fi 2608 2623 LogFile "FORCE_MODS:" … … 2669 2684 elif [ "$1" = "--locatedeps" ] ; then 2670 2685 [ ! "$2" ] && Die "Please specify the binary to look at" 2671 LocateDeps $ 22686 LocateDeps $* 2672 2687 # Avoids logfile content for mondo 2673 2688 export MONDO_SHARE="" … … 2682 2697 [ ! "$2" ] && Die "Please specify the output file" 2683 2698 MakeMountlist $2 2699 CheckMountlist $2 2684 2700 # Avoids logfile content for mondo 2685 2701 export MONDO_SHARE="" … … 2818 2834 MakeMondoConfigFile $MINDI_TMP/mondo-restore.cfg 2819 2835 MakeMountlist $MINDI_TMP/mountlist.txt 2836 CheckMountlist $MINDI_TMP/mountlist.txt 2820 2837 mkdir -p $MINDI_TMP/small-all/tmp 2821 2838 cd $MINDI_TMP/small-all -
branches/2.2.10/mindi/rootfs/etc/passwd
r2428 r2444 1 root::0:0::/:/bin/bash 1 2 halt:x:7:0:halt:/sbin:/sbin/halt 2 operator:x:11:0:operator:/root:/bin/bash 3 root::0:0::/root:/bin/bash 3 operator:x:11:0:operator:/:/bin/bash 4 4 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown 5 5 sync:x:5:0:sync:/sbin:/bin/sync … … 8 8 daemon:x:2:2:daemon:/sbin: 9 9 adm:x:3:4:adm:/var/adm: 10 lp:x:4:7:lp:/var/spool/lpd:11 mail:x:8:12:mail:/var/spool/mail:12 postmaster:x:14:12:postmaster:/var/spool/mail:/bin/bash13 news:x:9:13:news:/usr/lib/news:14 uucp:x:10:14:uucp:/var/spool/uucppublic:15 10 man:x:13:15:man:/usr/man: 16 11 guest:x:405:100:guest:/dev/null:/dev/null -
branches/2.2.10/mindi/rootfs/etc/udev-links.conf
r1804 r2444 56 56 57 57 M null c 1 3 58 M fuse c 10 229 -
branches/2.2.10/mindi/rootfs/sbin/init
r2382 r2444 301 301 fi 302 302 # Depending on udevd version it gives back the hand or not :-( 303 if [ ! "`ps | grep udevd`" ]; then 303 ps | grep udevd 2> /dev/null 1> /dev/null 304 if [ $? -ne 0 ]; then 304 305 /sbin/udevd --daemon & 306 echo "Waiting for udev to start..." 305 307 sleep 5 306 308 fi … … 309 311 /sbin/udevtrigger 310 312 fi 313 echo "Waiting for udev to discover..." 311 314 create_dev_makedev 312 315 # Newer version use udevadm for that 313 if [ -x /sbin/udevadm ]; then 314 /sbin/udevadm settle --timeout=10 315 elif [ -x /sbin/udevsettle ]; then 316 /sbin/udevsettle 316 if [ -x /sbin/udevsettle ]; then 317 /sbin/udevsettle --timeout=10 318 elif [ -x /sbin/udevadm ]; then 319 /sbin/udevadm trigger 320 /sbin/udevadm settle --timeout=10 317 321 fi 318 322 # It seems we need to have more static devs on some distro were -
branches/2.2.10/mindi/rootfs/sbin/start-netfs
r2382 r2444 81 81 if [ "$proto" = "sshfs" ]; then 82 82 LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..." 83 sshfs -o ro $netfsmount /tmp/isodir 83 # We need a correct console for ssh 84 ln -sf /dev/console /dev/tty 85 sshfs -o ro,StrictHostKeyChecking=no $netfsmount /tmp/isodir 84 86 elif [ "$proto" != "" ]; then 85 87 LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..." -
branches/2.2.10/mondo/src/common/libmondo-cli.c
r2428 r2444 488 488 *p = '\0'; 489 489 } 490 mr_asprintf(tmp1, "mount | grep -E \"^ %s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);490 mr_asprintf(tmp1, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, bkpinfo->netfs_mount); 491 491 mr_free(bkpinfo->isodir); 492 492 bkpinfo->isodir = call_program_and_get_last_line_of_output(tmp1); … … 506 506 retval++; 507 507 } else { 508 mr_asprintf(tmp1, "mount | grep -E \"^ %s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);508 mr_asprintf(tmp1, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, bkpinfo->netfs_mount); 509 509 mr_free(bkpinfo->isodir); 510 510 bkpinfo->isodir = call_program_and_get_last_line_of_output(tmp1); … … 517 517 } 518 518 } 519 log_msg(3, "proto = %s", bkpinfo->netfs_proto); 519 520 log_msg(3, "mount = %s", bkpinfo->netfs_mount); 521 if (bkpinfo->netfs_user) { 522 log_msg(3, "user = %s", bkpinfo->netfs_user); 523 } 520 524 log_msg(3, "isodir= %s", bkpinfo->isodir); 521 525 } -
branches/2.2.10/mondo/src/common/libmondo-devices.c
r2428 r2444 1404 1404 1405 1405 /** 1406 * @addtogroup utilityGroup 1407 * @{ 1408 */ 1409 /** 1410 * Get a space-separated list of NETFS devices and mounts. 1411 * @return The list created. 1412 * @note The return value points to static data that will be overwritten with each call. 1413 */ 1414 char *list_of_NETFS_devices_and_mounts(void) 1415 { 1416 char *exclude_these_devices = NULL; 1417 char *exclude_these_directories = NULL; 1418 static char result_sz[1024]; 1419 1420 mr_asprintf(exclude_these_directories,"%s",list_of_NETFS_mounts_only()); 1421 exclude_these_devices = call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|sshfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"); 1422 snprintf(result_sz, 1023, "%s %s", exclude_these_directories, exclude_these_devices); 1423 mr_free(exclude_these_devices); 1424 mr_free(exclude_these_directories); 1425 return (result_sz); 1426 } 1427 1428 1429 1430 1431 /** 1432 * Get a space-separated list of NETFS mounts. 1433 * @return The list created. 1434 * @note The return value points to static data that will be overwritten with each call. 1435 * @bug Even though we only want the mounts, the devices are still checked. 1436 */ 1437 char *list_of_NETFS_mounts_only(void) 1438 { 1439 char *exclude_these_directories = NULL; 1440 static char result_sz[512]; 1441 1442 exclude_these_directories = call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"); 1443 snprintf(result_sz, 511, "%s", exclude_these_directories); 1444 mr_free(exclude_these_directories); 1445 return (result_sz); 1446 } 1447 1448 /* @} - end of utilityGroup */ 1449 1450 1451 1452 1453 1454 /** 1455 * Create a randomly-named FIFO. The format is @p stub "." [random] [random] where 1456 * [random] is a random number between 1 and 32767. 1457 * @param store_name_here Where to store the new filename. 1458 * @param stub A random number will be appended to this to make the FIFO's name. 1459 * @ingroup deviceGroup 1460 */ 1461 void make_fifo(char *store_name_here, char *stub) 1462 { 1463 char *tmp = NULL; 1464 1465 assert_string_is_neither_NULL_nor_zerolength(stub); 1466 1467 sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768), 1468 (int) (random() % 32768)); 1469 make_hole_for_file(store_name_here); 1470 mkfifo(store_name_here, S_IRWXU | S_IRWXG); 1471 mr_asprintf(tmp, "chmod 770 %s", store_name_here); 1472 paranoid_system(tmp); 1473 mr_free(tmp); 1474 } 1475 1476 1477 1478 1479 1480 1481 /** 1482 * Set the tmpdir and scratchdir to reside on the partition with the most free space. 1483 * Automatically excludes DOS, NTFS, SMB, and NFS filesystems. 1484 * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir and @c bkpinfo->scratchdir will be set. 1485 * @ingroup utilityGroup 1486 */ 1487 void sensibly_set_scratchdir() 1488 { 1489 char *tmp = NULL; 1490 char *command = NULL; 1491 char *sz = NULL; 1492 1493 #ifdef __FreeBSD__ 1494 tmp = call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"); 1495 #else 1496 tmp = call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x fuse.sshfs -x vfat -x ntfs -x ntfs-3g -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"); 1497 #endif 1498 1499 if (tmp[0] != '/') { 1500 mr_asprintf(sz, "%s", tmp); 1501 mr_free(tmp); 1502 mr_asprintf(tmp, "/%s", sz); 1503 mr_free(sz); 1504 } 1505 if (!tmp[0]) { 1506 fatal_error("I couldn't figure out the scratchdir!"); 1507 } 1508 1509 /* Cleaning a potential previous scratchdir */ 1510 if (bkpinfo->scratchdir) { 1511 mr_asprintf(command, "rm -Rf %s", bkpinfo->scratchdir); 1512 paranoid_system(command); 1513 mr_free(command); 1514 } 1515 mr_free(bkpinfo->scratchdir); 1516 1517 mr_asprintf(bkpinfo->scratchdir , "%s/mondo.scratch.%d", tmp, (int) (random() % 32768)); 1518 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 1519 1520 /* Cleaning potential previous scratchdir */ 1521 mr_asprintf(command, "rm -Rf %s/mondo.scratch.*", tmp); 1522 mr_free(tmp); 1523 1524 paranoid_system(command); 1525 mr_free(command); 1526 } 1527 1528 1529 1530 1531 1532 1533 /** 1534 * @addtogroup deviceGroup 1535 * @{ 1536 */ 1537 /** 1538 * If we can read @p dev, set @return output to it. 1539 * If @p dev cannot be read, set @p output to NULL. 1540 * @param dev The device to check for. 1541 * @return output Set to @p dev if @p dev exists, NULL otherwise. 1542 */ 1543 char *set_dev_to_this_if_rx_OK(char *dev) 1544 { 1545 char *command = NULL; 1546 char *output = NULL; 1547 1548 if (!dev || dev[0] == '\0') { 1549 return(NULL); 1550 } 1551 log_msg(10, "Injecting %s", dev); 1552 inject_device(dev); 1553 if (!does_file_exist(dev)) { 1554 log_msg(10, "%s doesn't exist. Returning FALSE.", dev); 1555 return(NULL); 1556 } 1557 mr_asprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev); 1558 if (!run_program_and_log_output(command, FALSE) 1559 && !run_program_and_log_output(command, FALSE)) { 1560 mr_asprintf(output, "%s", dev); 1561 log_msg(4, "Found it - %s", dev); 1406 * Creates a singly linked list of all of the non-NETFS mounted file systems. 1407 * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold 1408 * the list of mounted file systems. 1409 * @return None. 1410 */ 1411 static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr) 1412 { 1413 assert (DSFptr); 1414 if (DSF_Head == NULL) { 1415 DSF_Head = DSFptr; 1562 1416 } else { 1563 log_msg(4, "It's not %s", dev); 1564 } 1565 mr_free(command); 1566 return(output); 1567 } 1568 1569 1570 1571 1572 1573 /** 1574 * Find out what number CD is in the drive. 1575 * @param bkpinfo The backup information structure. The @c bkpinfo->media_device field is the only one used. 1576 * @return The current CD number, or -1 if it could not be found. 1577 * @note If the CD is not mounted, it will be mounted 1578 * (and remain mounted after this function returns). 1579 */ 1580 int what_number_cd_is_this() 1581 { 1582 int cd_number = -1; 1583 char *mountdev = NULL; 1584 char *tmp = NULL; 1585 1586 assert(bkpinfo != NULL); 1587 // log_it("Asking what_number_cd_is_this"); 1588 if (g_ISO_restore_mode) { 1589 mr_asprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'"); 1590 mountdev = call_program_and_get_last_line_of_output(tmp); 1591 mr_strcat(mountdev, "/archives/THIS-CD-NUMBER"); 1592 mr_free(tmp); 1593 1594 tmp = last_line_of_file(mountdev); 1595 cd_number = atoi(tmp); 1596 mr_free(tmp); 1597 mr_free(mountdev); 1598 return (cd_number); 1599 } 1600 1601 if (bkpinfo->media_device) { 1602 mr_asprintf(mountdev, "%s", bkpinfo->media_device); 1603 } 1604 if (!mountdev) { 1605 log_it("(what_number_cd_is_this) Warning - media_device unknown. Finding out..."); 1606 mr_free(bkpinfo->media_device); 1607 bkpinfo->media_device = find_cdrom_device(FALSE); 1608 mr_asprintf(mountdev, "%s", bkpinfo->media_device); 1609 } 1610 if (!is_this_device_mounted(MNT_CDROM)) { 1611 if (bkpinfo->backup_media_type == usb) { 1612 mount_USB_here(mountdev, MNT_CDROM); 1613 } else { 1614 mount_CDROM_here(mountdev, MNT_CDROM); 1615 } 1616 } 1617 mr_free(mountdev); 1618 1619 tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"); 1620 cd_number = atoi(tmp); 1621 mr_free(tmp); 1622 return (cd_number); 1623 } 1624 1625 1626 1627 1628 1629 1630 1631 /** 1632 * Find out what device is mounted as root (/). 1633 * @return Root device. 1634 * @note The returned string points to static storage and will be overwritten with every call. 1635 * @bug A bit of a misnomer; it's actually finding out the root device. 1636 * The mountpoint (where it's mounted) will obviously be '/'. 1637 */ 1638 char *where_is_root_mounted() { 1639 /*@ buffers **************** */ 1640 char *output = NULL; 1641 1642 1643 #ifdef __FreeBSD__ 1644 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1"); 1645 #else 1646 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | sed 's/[0-9]//' | sed 's/[0-9]//'"); 1647 if (strstr(output, "/dev/cciss/")) { 1648 mr_free(output); 1649 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | cut -dp -f1"); 1650 } 1651 if (strstr(output, "/dev/md")) { 1652 mr_free(output); 1653 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1"); 1654 } 1655 #endif 1656 1657 return (output); 1658 } 1659 1660 1661 /** 1662 * Find out which boot loader is in use. 1663 * @param which_device Device to look for the boot loader on. 1664 * @return 'L' for LILO, 'E'for ELILO, 'G' for GRUB, 'B' or 'D' for FreeBSD boot loaders, or 'U' for Unknown. 1665 * @note Under Linux, all drives are examined, not just @p which_device. 1666 */ 1667 #ifdef __FreeBSD__ 1668 char which_boot_loader(char *which_device) { 1669 int count_lilos = 0; 1670 int count_grubs = 0; 1671 int count_boot0s = 0; 1672 int count_dangerouslydedicated = 0; 1673 1674 log_it("looking at drive %s's MBR", which_device); 1675 if (does_string_exist_in_boot_block(which_device, "GRUB")) { 1676 count_grubs++; 1677 } 1678 if (does_string_exist_in_boot_block(which_device, "LILO")) { 1679 count_lilos++; 1680 } 1681 if (does_string_exist_in_boot_block(which_device, "Drive")) { 1682 count_boot0s++; 1683 } 1684 if (does_string_exist_in_first_N_blocks(which_device, "FreeBSD/i386", 17)) { 1685 count_dangerouslydedicated++; 1686 } 1687 log_it("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n", 1688 count_grubs, count_lilos, count_elilos, count_boot0s, 1689 count_dangerouslydedicated); 1690 1691 if (count_grubs && !count_lilos) { 1692 return ('G'); 1693 } else if (count_lilos && !count_grubs) { 1694 return ('L'); 1695 } else if (count_grubs == 1 && count_lilos == 1) { 1696 log_it("I'll bet you used to use LILO but switched to GRUB..."); 1697 return ('G'); 1698 } else if (count_boot0s == 1) { 1699 return ('B'); 1700 } else if (count_dangerouslydedicated) { 1701 return ('D'); 1702 } else { 1703 log_it("Unknown boot loader"); 1704 return ('U'); 1705 } 1706 } 1707 1708 #else 1709 1710 char which_boot_loader(char *which_device) { 1711 /*@ buffer ***************************************************** */ 1712 char *list_drives_cmd = NULL; 1713 char *tmp = NULL; 1714 char *current_drive = NULL; 1715 1716 /*@ pointers *************************************************** */ 1717 FILE *pdrives = NULL; 1718 1719 /*@ int ******************************************************** */ 1720 int count_lilos = 0; 1721 int count_grubs = 0; 1722 1723 /*@ end vars *************************************************** */ 1724 1725 1726 #ifdef __IA64__ 1727 /* No choice for it */ 1728 return ('E'); 1729 #endif 1730 1731 tmp = where_is_root_mounted(); 1732 mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", tmp); 1733 mr_free(tmp); 1734 log_it("list_drives_cmd = %s", list_drives_cmd); 1735 1736 pdrives = popen(list_drives_cmd, "r"); 1737 mr_free(list_drives_cmd); 1738 1739 if (!pdrives) { 1740 log_OS_error("Unable to open list of drives"); 1741 return ('\0'); 1742 } 1743 1744 for (mr_getline(current_drive, pdrives); !feof(pdrives); mr_getline(current_drive, pdrives)) { 1745 mr_strip_spaces(current_drive); 1746 log_it("looking at drive %s's MBR", current_drive); 1747 if (does_string_exist_in_boot_block(current_drive, "GRUB")) { 1748 count_grubs++; 1749 /* BERLIOS : removed as I don't think it's mandatory here 1750 mr_free(which_device); 1751 mr_asprintf(which_device, "%s", current_drive); 1752 */ 1753 mr_free(current_drive); 1417 DSF_Tail->next = DSFptr; 1418 } 1419 DSFptr->next = NULL; 1420 DSF_Tail = DSFptr; 1421 } 1422 1423 /** 1424 * Find the structure, in the singly linked list of all of the non-NETFS 1425 * mounted file systems, that contains the specified device. 1426 * @param device The device to find 1427 * @return NULL if it didn't find the device, a pointer to the 1428 * structure if it did. 1429 */ 1430 static MOUNTED_FS_STRUCT *find_device_in_list (char *device) 1431 { 1432 MOUNTED_FS_STRUCT *DSFptr = NULL; 1433 1434 DSFptr = DSF_Head; 1435 while (DSFptr != NULL) { 1436 if (!strcmp(DSFptr->device, device)) { 1754 1437 break; 1755 1438 } 1756 if (does_string_exist_in_boot_block(current_drive, "LILO")) { 1757 count_lilos++; 1758 /* BERLIOS : removed as I don't think it's mandatory here 1759 mr_free(which_device); 1760 mr_asprintf(which_device, "%s", current_drive); 1761 */ 1762 mr_free(current_drive); 1439 DSFptr = DSFptr->next; 1440 } 1441 return (DSFptr); 1442 } 1443 1444 /** 1445 * Find the structure, in the singly linked list of all of the non-NETFS 1446 * mounted file systems, that contains the specified mount point. 1447 * @param mount_point The mount point to find 1448 * @return NULL is it didn't find the mount point, a pointer to the 1449 * structure if it did. 1450 */ 1451 static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point) 1452 { 1453 MOUNTED_FS_STRUCT *DSFptr = NULL; 1454 1455 DSFptr = DSF_Head; 1456 while (DSFptr != NULL) { 1457 if (!strcmp(DSFptr->mount_point, mount_point)) { 1763 1458 break; 1764 1459 } 1765 mr_free(current_drive); 1766 } 1767 mr_free(current_drive); 1768 1769 if (pclose(pdrives)) { 1770 log_OS_error("Cannot pclose pdrives"); 1771 } 1772 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos); 1773 if (count_grubs && !count_lilos) { 1774 return ('G'); 1775 } else if (count_lilos && !count_grubs) { 1776 return ('L'); 1777 } else if (count_grubs == 1 && count_lilos == 1) { 1778 log_it("I'll bet you used to use LILO but switched to GRUB..."); 1779 return ('G'); 1780 } else { 1781 // We need to look on each partition then 1782 mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep -E \"^/dev/\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/"); 1783 log_it("list_drives_cmd = %s", list_drives_cmd); 1784 1785 if (!(pdrives = popen(list_drives_cmd, "r"))) { 1786 log_OS_error("Unable to open list of drives"); 1787 mr_free(list_drives_cmd); 1788 return ('\0'); 1789 } 1790 mr_free(list_drives_cmd); 1791 1792 for (mr_getline(current_drive, pdrives); !feof(pdrives); mr_getline(current_drive, pdrives)) { 1793 mr_strip_spaces(current_drive); 1794 log_it("looking at partition %s's BR", current_drive); 1795 if (does_string_exist_in_boot_block(current_drive, "GRUB")) { 1796 count_grubs++; 1797 /* BERLIOS : removed as I don't think it's mandatory here 1798 mr_free(which_device); 1799 mr_asprintf(which_device, "%s", current_drive); 1800 */ 1801 mr_free(current_drive); 1802 break; 1803 } 1804 if (does_string_exist_in_boot_block(current_drive, "LILO")) { 1805 count_lilos++; 1806 /* BERLIOS : removed as I don't think it's mandatory here 1807 mr_free(which_device); 1808 mr_asprintf(which_device, "%s", current_drive); 1809 */ 1810 mr_free(current_drive); 1811 break; 1812 } 1813 mr_free(current_drive); 1814 } 1815 mr_free(current_drive); 1816 1817 if (pclose(pdrives)) { 1818 log_OS_error("Cannot pclose pdrives"); 1819 } 1820 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos); 1821 if (count_grubs && !count_lilos) { 1822 return ('G'); 1823 } else if (count_lilos && !count_grubs) { 1824 return ('L'); 1825 } else if (count_grubs == 1 && count_lilos == 1) { 1826 log_it("I'll bet you used to use LILO but switched to GRUB..."); 1827 return ('G'); 1828 } else { 1829 log_it("Unknown boot loader"); 1830 return ('U'); 1831 } 1832 } 1833 } 1834 #endif 1835 1836 1837 1838 1839 /** 1840 * Write zeroes over the first 16K of @p device. 1841 * @param device The device to zero. 1842 * @return 0 for success, 1 for failure. 1843 */ 1844 int zero_out_a_device(char *device) 1845 { 1846 FILE *fout; 1847 int i; 1848 1849 assert_string_is_neither_NULL_nor_zerolength(device); 1850 1851 log_it("Zeroing drive %s", device); 1852 if (!(fout = fopen(device, "w"))) { 1853 log_OS_error("Unable to open/write to device"); 1854 return (1); 1855 } 1856 for (i = 0; i < 16384; i++) { 1857 fputc('\0', fout); 1858 } 1859 paranoid_fclose(fout); 1860 log_it("Device successfully zeroed."); 1861 return (0); 1862 } 1863 1864 /** 1865 * Return the device pointed to by @p incoming. 1866 * @param incoming The device to resolve symlinks for. 1867 * @return The path to the real device file. 1868 * @note The returned string points to static storage that will be overwritten with each call. 1869 * @bug Won't work with file v4.0; needs to be written in C. 1870 */ 1871 char *resolve_softlinks_to_get_to_actual_device_file(char *incoming) 1872 { 1873 char *output; 1874 char *command = NULL; 1875 char *curr_fname; 1876 char *scratch = NULL; 1877 char *tmp = NULL; 1878 char *p; 1879 1880 struct stat statbuf; 1881 malloc_string(curr_fname); 1882 if (!does_file_exist(incoming)) { 1883 log_it("resolve_softlinks_to_get_to_actual_device_file --- device not found"); 1884 mr_asprintf(output, "%s", incoming); 1885 } else { 1886 strcpy(curr_fname, incoming); 1887 lstat(curr_fname, &statbuf); 1888 while (S_ISLNK(statbuf.st_mode)) { 1889 log_msg(1, "curr_fname = %s", curr_fname); 1890 mr_asprintf(command, "file %s", curr_fname); 1891 tmp = call_program_and_get_last_line_of_output(command); 1892 mr_free(command); 1893 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; p--); 1894 p++; 1895 mr_asprintf(scratch, "%s", p); 1896 for (p = scratch; *p != '\0' && *p != '\''; p++); 1897 *p = '\0'; 1898 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch); 1899 mr_free(tmp); 1900 1901 if (scratch[0] == '/') { 1902 strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink 1903 } else { // copy over the basename cos it's a relative softlink 1904 p = curr_fname + strlen(curr_fname); 1905 while (p != curr_fname && *p != '/') { 1906 p--; 1907 } 1908 if (*p == '/') { 1909 p++; 1910 } 1911 strcpy(p, scratch); 1912 } 1913 mr_free(scratch); 1914 lstat(curr_fname, &statbuf); 1915 } 1916 mr_asprintf(output, "%s", curr_fname); 1917 log_it("resolved %s to %s", incoming, output); 1918 } 1919 paranoid_free(curr_fname); 1920 return (output); 1921 } 1922 1923 /* @} - end of deviceGroup */ 1924 1925 /** 1926 * Return the type of partition format (GPT or MBR) 1927 */ 1928 char *which_partition_format(const char *drive) 1929 { 1930 char *output; 1931 char *tmp = NULL; 1932 char *command = NULL; 1933 char *fdisk = NULL; 1934 #ifdef __IA64__ 1935 struct stat buf; 1936 #endif 1937 mr_asprintf(fdisk, "/sbin/parted2fdisk"); 1938 mr_asprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive); 1939 mr_free(fdisk); 1940 1941 tmp = call_program_and_get_last_line_of_output(command); 1942 mr_free(command); 1943 1944 if (strstr(tmp, "GPT") == NULL) { 1945 mr_asprintf(output, "MBR"); 1946 } else { 1947 mr_asprintf(output, "GPT"); 1948 } 1949 mr_free(tmp); 1950 1951 log_msg(0, "Found %s partition table format type", output); 1952 return (output); 1460 DSFptr = DSFptr->next; 1461 } 1462 return (DSFptr); 1953 1463 } 1954 1464 … … 1971 1481 } 1972 1482 1973 /**1974 * Creates a singly linked list of all of the non-NETFS mounted file systems.1975 * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold1976 * the list of mounted file systems.1977 * @return None.1978 */1979 static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr)1980 {1981 assert (DSFptr);1982 if (DSF_Head == NULL) {1983 DSF_Head = DSFptr;1984 } else {1985 DSF_Tail->next = DSFptr;1986 }1987 DSFptr->next = NULL;1988 DSF_Tail = DSFptr;1989 }1990 1991 /**1992 * Find the structure, in the singly linked list of all of the non-NETFS1993 * mounted file systems, that contains the specified device.1994 * @param device The device to find1995 * @return NULL if it didn't find the device, a pointer to the1996 * structure if it did.1997 */1998 static MOUNTED_FS_STRUCT *find_device_in_list (char *device)1999 {2000 MOUNTED_FS_STRUCT *DSFptr = NULL;2001 2002 DSFptr = DSF_Head;2003 while (DSFptr != NULL) {2004 if (!strcmp(DSFptr->device, device)) {2005 break;2006 }2007 DSFptr = DSFptr->next;2008 }2009 return (DSFptr);2010 }2011 2012 /**2013 * Find the structure, in the singly linked list of all of the non-NETFS2014 * mounted file systems, that contains the specified mount point.2015 * @param mount_point The mount point to find2016 * @return NULL is it didn't find the mount point, a pointer to the2017 * structure if it did.2018 */2019 static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point)2020 {2021 MOUNTED_FS_STRUCT *DSFptr = NULL;2022 2023 DSFptr = DSF_Head;2024 while (DSFptr != NULL) {2025 if (!strcmp(DSFptr->mount_point, mount_point)) {2026 break;2027 }2028 DSFptr = DSFptr->next;2029 }2030 return (DSFptr);2031 }2032 1483 2033 1484 /** … … 2041 1492 int i = 0; 2042 1493 int mount_cnt = 0; 1494 int lastpos = 0; 2043 1495 char *mounted_file_system = NULL; 2044 1496 char *command = NULL; … … 2071 1523 2072 1524 log_msg (5, "mounted_file_system: %s", mounted_file_system); 2073 if ((token = strtok(mounted_file_system, token_chars)) == NULL) {1525 if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) { 2074 1526 log_msg (4, "Could not get the list of mounted file systems"); 2075 1527 mr_free(mounted_file_system); … … 2088 1540 strcpy(DSFptr->device, token); 2089 1541 mr_free(token); 2090 if ((token = strtok(NULL, token_chars)) == NULL) {1542 if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) { 2091 1543 log_msg (5, "Ran out of entries on the mounted file systems list"); 2092 1544 mr_free(mounted_file_system); … … 2097 1549 strcpy(DSFptr->mount_point, token); 2098 1550 mr_free(token); 2099 token = strtok(NULL, token_chars);1551 token = mr_strtok(mounted_file_system, token_chars, &lastpos); 2100 1552 } 2101 1553 mr_free(mounted_file_system); … … 2125 1577 char *command = NULL; 2126 1578 char *partition_list = NULL; 2127 char partitions[64][MAX_STR_LEN];1579 char *partitions[64]; 2128 1580 char *mount_list = NULL; 2129 1581 char *token = NULL; 1582 char *ndsf = NULL; 2130 1583 char token_chars[] =" \t\r\f\a\0"; 2131 1584 MOUNTED_FS_STRUCT *DSFptr = NULL; … … 2145 1598 /* Verify that the dsf exists */ 2146 1599 mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf); 2147 log_msg(5, " Executing: %s", command);1600 log_msg(5, " Executing: %s", command); 2148 1601 tmp = call_program_and_get_last_line_of_output(command); 2149 1602 mr_free(command); … … 2174 1627 partition_list = call_program_and_get_last_line_of_output(command); 2175 1628 mr_free(command); 1629 2176 1630 log_msg(4, "Partition list for %s: %s", dsf, partition_list); 2177 1631 if (!strlen(partition_list)) { 2178 1632 /* There were no partitions on the disk */ 2179 log_msg(4, "Cannot find any partitions on device special file %s", dsf); 2180 return (-2); 2181 } 2182 2183 /* Fill the partition list */ 2184 i = 0; 2185 lastpos = 0; 2186 while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) { 2187 log_msg (5, "Found partition: %s", token); 2188 strcpy(partitions[i++], token); 2189 mr_free(token); 2190 } 2191 paranoid_free(partition_list); 1633 log_msg(4, "No partitions on device special file %s", dsf); 1634 log_msg(4, "I guess it's a partiion itself"); 1635 mr_asprintf(partitions[0], "%s", dsf); 1636 ndsf = truncate_to_drive_name(dsf); 1637 } else { 1638 /* Fill the partition list */ 1639 i = 0; 1640 lastpos = 0; 1641 while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) { 1642 log_msg (5, "Found partition: %s", token); 1643 partitions[i++] = token; 1644 } 1645 mr_asprintf(ndsf, "%s", dsf); 1646 } 1647 mr_free(partition_list); 2192 1648 1649 /* For the rest ndsf is the new dsf to deal with */ 2193 1650 /******** 2194 1651 * At this point, we have a list of all of the partitions on the dsf. Now try to … … 2223 1680 log_msg(4, "Processing partition: %s", partitions[i]); 2224 1681 /* See if it's swap. If it is, ignore it. */ 2225 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", dsf, partitions[i]);1682 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]); 2226 1683 log_msg(4, " Running: %s", command); 2227 1684 tmp = call_program_and_get_last_line_of_output(command); … … 2236 1693 continue; 2237 1694 } 1695 2238 1696 /* It's not swap. See if we can find the mount point from the mount command. */ 2239 1697 mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]); … … 2241 1699 mr_free(command); 2242 1700 2243 c = strlen(tmp); 2244 mr_free(tmp); 2245 if (c) { 1701 if (strlen(tmp)) { 2246 1702 log_msg(4, " %s is mounted: %s", partitions[i], tmp); 2247 1703 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) { 2248 1704 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp); 1705 mr_free(tmp); 2249 1706 return (1); 2250 1707 } 2251 1708 DSFptr->check = 1; 1709 mr_free(tmp); 2252 1710 continue; 2253 1711 } 1712 mr_free(tmp); 2254 1713 2255 1714 /* It's not swap and it's not mounted. See if it's LVM */ … … 2257 1716 2258 1717 /* Get the partition ID; 8e for LVM */ 2259 mr_asprintf(command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);1718 mr_asprintf(command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", ndsf, partitions[i]); 2260 1719 log_msg(4, " Running: %s", command); 2261 1720 tmp = call_program_and_get_last_line_of_output(command); 2262 1721 mr_free(command); 2263 1722 2264 c = strlen(tmp); 2265 mr_free(tmp); 2266 if (c) { 1723 if (strlen(tmp)) { 2267 1724 log_msg(4, " Partition ID: %s", tmp); 2268 1725 if (!strcasecmp(tmp, "8e")) { … … 2289 1746 if ((DSFptr = find_mount_point_in_list(token)) == NULL) { 2290 1747 log_msg (4, "Can't find mount point %s in mounted file systems list", token); 1748 mr_free(tmp); 1749 mr_free(VG); 2291 1750 mr_free(token); 2292 mr_free(VG);2293 1751 return (1); 2294 1752 } … … 2301 1759 *******/ 2302 1760 mr_free(mount_list); 1761 2303 1762 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 2304 1763 log_msg (5, "Running: %s", command); … … 2311 1770 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG); 2312 1771 log_msg (5, "Running: %s", command); 1772 mr_free(tmp); 2313 1773 2314 1774 tmp = call_program_and_get_last_line_of_output(command); 2315 paranoid_free(command); 1775 mr_free(command); 1776 2316 1777 log_msg(4, "Number of Software raid device: %s", tmp); 2317 1778 c = atoi(tmp); … … 2322 1783 if ((DSFptr = find_device_in_list(token)) == NULL) { 2323 1784 log_msg (4, "Can't find device %s in mounted file systems list", token); 1785 mr_free(VG); 2324 1786 mr_free(token); 2325 1787 return (1); … … 2333 1795 } else { 2334 1796 log_msg (4, "Error finding Volume Group for partition %s", partitions[i]); 1797 mr_free(tmp); 2335 1798 return (1); 2336 1799 } 1800 mr_free(tmp); 1801 mr_free(VG); 2337 1802 continue; 2338 1803 } … … 2340 1805 log_msg (4, "Error finding partition type for the partition %s", partitions[i]); 2341 1806 } 2342 paranoid_free(tmp); 1807 mr_free(tmp); 1808 2343 1809 /******** 2344 1810 * It's not swap, mounted, or LVM. See if it's used in a software raid device. … … 2350 1816 mr_free(command); 2351 1817 2352 c = strlen(tmp); 2353 mr_free(tmp); 2354 if (!c) { 1818 if (!strlen(tmp)) { 2355 1819 log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]); 1820 mr_free(tmp); 2356 1821 continue; 2357 1822 } 2358 1823 log_msg (5, " UUID: %s", tmp); 1824 2359 1825 /* Get the Software raid device list */ 2360 1826 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); … … 2362 1828 mount_list = call_program_and_get_last_line_of_output(command); 2363 1829 mr_free(command); 2364 1830 :w! 2365 1831 log_msg(4, " Software raid device list: %s", mount_list); 2366 1832 /* Loop through the software raid device list to see if we can find the partition */ … … 2369 1835 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp); 2370 1836 log_msg(4, " Running: %s", command); 1837 mr_free(tmp); 1838 2371 1839 tmp = call_program_and_get_last_line_of_output(command); 2372 1840 mr_free(command); 1841 2373 1842 c = atoi(tmp); 2374 1843 mr_free(tmp); … … 2387 1856 mr_free(token); 2388 1857 } 2389 } 2390 mr_free(partition_list); 2391 mr_free(mount_list); 1858 mr_free(tmp); 1859 mr_free(mount_list); 1860 mr_free(partitions[i]); 1861 } 2392 1862 2393 1863 /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */ … … 2408 1878 while (DSFptr != NULL) { 2409 1879 if (DSFptr->check) { 2410 log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);1880 log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, ndsf); 2411 1881 strcat(*included_dsf_list, DSFptr->mount_point); 2412 1882 strcat(*included_dsf_list, " "); 2413 1883 } else { 2414 log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);1884 log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, ndsf); 2415 1885 strcat(*excluded_dsf_list, DSFptr->mount_point); 2416 1886 strcat(*excluded_dsf_list, " "); … … 2418 1888 DSFptr = DSFptr->next; 2419 1889 } 1890 mr_free(ndsf); 1891 2420 1892 log_msg (5, "included_dsf_list: %s", *included_dsf_list); 2421 1893 log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list); … … 2496 1968 2497 1969 1970 /** 1971 * @addtogroup utilityGroup 1972 * @{ 1973 */ 1974 /** 1975 * Get a space-separated list of NETFS devices and mounts. 1976 * @return The list created. 1977 * @note The return value points to static data that will be overwritten with each call. 1978 */ 1979 char *list_of_NETFS_devices_and_mounts(void) 1980 { 1981 char *exclude_these_devices = NULL; 1982 char *exclude_these_directories = NULL; 1983 static char result_sz[1024]; 1984 1985 mr_asprintf(exclude_these_directories,"%s",list_of_NETFS_mounts_only()); 1986 exclude_these_devices = call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|sshfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"); 1987 snprintf(result_sz, 1023, "%s %s", exclude_these_directories, exclude_these_devices); 1988 mr_free(exclude_these_devices); 1989 mr_free(exclude_these_directories); 1990 return (result_sz); 1991 } 1992 1993 1994 1995 1996 /** 1997 * Get a space-separated list of NETFS mounts. 1998 * @return The list created. 1999 * @note The return value points to static data that will be overwritten with each call. 2000 * @bug Even though we only want the mounts, the devices are still checked. 2001 */ 2002 char *list_of_NETFS_mounts_only(void) 2003 { 2004 char *exclude_these_directories = NULL; 2005 static char result_sz[512]; 2006 2007 exclude_these_directories = call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"); 2008 snprintf(result_sz, 511, "%s", exclude_these_directories); 2009 mr_free(exclude_these_directories); 2010 return (result_sz); 2011 } 2012 2013 /* @} - end of utilityGroup */ 2014 2015 2016 2017 2018 2019 /** 2020 * Create a randomly-named FIFO. The format is @p stub "." [random] [random] where 2021 * [random] is a random number between 1 and 32767. 2022 * @param store_name_here Where to store the new filename. 2023 * @param stub A random number will be appended to this to make the FIFO's name. 2024 * @ingroup deviceGroup 2025 */ 2026 void make_fifo(char *store_name_here, char *stub) 2027 { 2028 char *tmp = NULL; 2029 2030 assert_string_is_neither_NULL_nor_zerolength(stub); 2031 2032 sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768), 2033 (int) (random() % 32768)); 2034 make_hole_for_file(store_name_here); 2035 mkfifo(store_name_here, S_IRWXU | S_IRWXG); 2036 mr_asprintf(tmp, "chmod 770 %s", store_name_here); 2037 paranoid_system(tmp); 2038 mr_free(tmp); 2039 } 2040 2041 2042 2043 2044 2045 2046 /** 2047 * Set the tmpdir and scratchdir to reside on the partition with the most free space. 2048 * Automatically excludes DOS, NTFS, SMB, and NFS filesystems. 2049 * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir and @c bkpinfo->scratchdir will be set. 2050 * @ingroup utilityGroup 2051 */ 2052 void sensibly_set_scratchdir() 2053 { 2054 char *tmp = NULL; 2055 char *command = NULL; 2056 char *sz = NULL; 2057 2058 #ifdef __FreeBSD__ 2059 tmp = call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"); 2060 #else 2061 tmp = call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x fuse.sshfs -x fuse -x vfat -x ntfs -x ntfs-3g -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"); 2062 #endif 2063 2064 if (tmp[0] != '/') { 2065 mr_asprintf(sz, "%s", tmp); 2066 mr_free(tmp); 2067 mr_asprintf(tmp, "/%s", sz); 2068 mr_free(sz); 2069 } 2070 if (!tmp[0]) { 2071 fatal_error("I couldn't figure out the scratchdir!"); 2072 } 2073 2074 /* Cleaning a potential previous scratchdir */ 2075 if (bkpinfo->scratchdir) { 2076 mr_asprintf(command, "rm -Rf %s", bkpinfo->scratchdir); 2077 paranoid_system(command); 2078 mr_free(command); 2079 } 2080 mr_free(bkpinfo->scratchdir); 2081 2082 mr_asprintf(bkpinfo->scratchdir , "%s/mondo.scratch.%d", tmp, (int) (random() % 32768)); 2083 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 2084 2085 /* Cleaning potential previous scratchdir */ 2086 mr_asprintf(command, "rm -Rf %s/mondo.scratch.*", tmp); 2087 mr_free(tmp); 2088 2089 paranoid_system(command); 2090 mr_free(command); 2091 } 2092 2093 2094 2095 2096 2097 2098 /** 2099 * @addtogroup deviceGroup 2100 * @{ 2101 */ 2102 /** 2103 * If we can read @p dev, set @return output to it. 2104 * If @p dev cannot be read, set @p output to NULL. 2105 * @param dev The device to check for. 2106 * @return output Set to @p dev if @p dev exists, NULL otherwise. 2107 */ 2108 char *set_dev_to_this_if_rx_OK(char *dev) 2109 { 2110 char *command = NULL; 2111 char *output = NULL; 2112 2113 if (!dev || dev[0] == '\0') { 2114 return(NULL); 2115 } 2116 log_msg(10, "Injecting %s", dev); 2117 inject_device(dev); 2118 if (!does_file_exist(dev)) { 2119 log_msg(10, "%s doesn't exist. Returning FALSE.", dev); 2120 return(NULL); 2121 } 2122 mr_asprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev); 2123 if (!run_program_and_log_output(command, FALSE) 2124 && !run_program_and_log_output(command, FALSE)) { 2125 mr_asprintf(output, "%s", dev); 2126 log_msg(4, "Found it - %s", dev); 2127 } else { 2128 log_msg(4, "It's not %s", dev); 2129 } 2130 mr_free(command); 2131 return(output); 2132 } 2133 2134 2135 2136 2137 2138 /** 2139 * Find out what number CD is in the drive. 2140 * @param bkpinfo The backup information structure. The @c bkpinfo->media_device field is the only one used. 2141 * @return The current CD number, or -1 if it could not be found. 2142 * @note If the CD is not mounted, it will be mounted 2143 * (and remain mounted after this function returns). 2144 */ 2145 int what_number_cd_is_this() 2146 { 2147 int cd_number = -1; 2148 char *mountdev = NULL; 2149 char *tmp = NULL; 2150 2151 assert(bkpinfo != NULL); 2152 // log_it("Asking what_number_cd_is_this"); 2153 if (g_ISO_restore_mode) { 2154 mr_asprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2155 mountdev = call_program_and_get_last_line_of_output(tmp); 2156 mr_strcat(mountdev, "/archives/THIS-CD-NUMBER"); 2157 mr_free(tmp); 2158 2159 tmp = last_line_of_file(mountdev); 2160 cd_number = atoi(tmp); 2161 mr_free(tmp); 2162 mr_free(mountdev); 2163 return (cd_number); 2164 } 2165 2166 if (bkpinfo->media_device) { 2167 mr_asprintf(mountdev, "%s", bkpinfo->media_device); 2168 } 2169 if (!mountdev) { 2170 log_it("(what_number_cd_is_this) Warning - media_device unknown. Finding out..."); 2171 mr_free(bkpinfo->media_device); 2172 bkpinfo->media_device = find_cdrom_device(FALSE); 2173 mr_asprintf(mountdev, "%s", bkpinfo->media_device); 2174 } 2175 if (!is_this_device_mounted(MNT_CDROM)) { 2176 if (bkpinfo->backup_media_type == usb) { 2177 mount_USB_here(mountdev, MNT_CDROM); 2178 } else { 2179 mount_CDROM_here(mountdev, MNT_CDROM); 2180 } 2181 } 2182 mr_free(mountdev); 2183 2184 tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"); 2185 cd_number = atoi(tmp); 2186 mr_free(tmp); 2187 return (cd_number); 2188 } 2189 2190 2191 2192 2193 2194 2195 2196 /** 2197 * Find out what device is mounted as root (/). 2198 * @return Root device. 2199 * @note The returned string points to static storage and will be overwritten with every call. 2200 * @bug A bit of a misnomer; it's actually finding out the root device. 2201 * The mountpoint (where it's mounted) will obviously be '/'. 2202 */ 2203 char *where_is_root_mounted() { 2204 /*@ buffers **************** */ 2205 char *output = NULL; 2206 2207 2208 #ifdef __FreeBSD__ 2209 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1"); 2210 #else 2211 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | sed 's/[0-9]//' | sed 's/[0-9]//'"); 2212 if (strstr(output, "/dev/cciss/")) { 2213 mr_free(output); 2214 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | cut -dp -f1"); 2215 } 2216 if (strstr(output, "/dev/md")) { 2217 mr_free(output); 2218 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1"); 2219 } 2220 #endif 2221 2222 return (output); 2223 } 2224 2225 2226 /** 2227 * Find out which boot loader is in use. 2228 * @param which_device Device to look for the boot loader on. 2229 * @return 'L' for LILO, 'E'for ELILO, 'G' for GRUB, 'B' or 'D' for FreeBSD boot loaders, or 'U' for Unknown. 2230 * @note Under Linux, all drives are examined, not just @p which_device. 2231 */ 2232 #ifdef __FreeBSD__ 2233 char which_boot_loader(char *which_device) { 2234 int count_lilos = 0; 2235 int count_grubs = 0; 2236 int count_boot0s = 0; 2237 int count_dangerouslydedicated = 0; 2238 2239 log_it("looking at drive %s's MBR", which_device); 2240 if (does_string_exist_in_boot_block(which_device, "GRUB")) { 2241 count_grubs++; 2242 } 2243 if (does_string_exist_in_boot_block(which_device, "LILO")) { 2244 count_lilos++; 2245 } 2246 if (does_string_exist_in_boot_block(which_device, "Drive")) { 2247 count_boot0s++; 2248 } 2249 if (does_string_exist_in_first_N_blocks(which_device, "FreeBSD/i386", 17)) { 2250 count_dangerouslydedicated++; 2251 } 2252 log_it("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n", 2253 count_grubs, count_lilos, count_elilos, count_boot0s, 2254 count_dangerouslydedicated); 2255 2256 if (count_grubs && !count_lilos) { 2257 return ('G'); 2258 } else if (count_lilos && !count_grubs) { 2259 return ('L'); 2260 } else if (count_grubs == 1 && count_lilos == 1) { 2261 log_it("I'll bet you used to use LILO but switched to GRUB..."); 2262 return ('G'); 2263 } else if (count_boot0s == 1) { 2264 return ('B'); 2265 } else if (count_dangerouslydedicated) { 2266 return ('D'); 2267 } else { 2268 log_it("Unknown boot loader"); 2269 return ('U'); 2270 } 2271 } 2272 2273 #else 2274 2275 char which_boot_loader(char *which_device) { 2276 /*@ buffer ***************************************************** */ 2277 char *list_drives_cmd = NULL; 2278 char *tmp = NULL; 2279 char *current_drive = NULL; 2280 2281 /*@ pointers *************************************************** */ 2282 FILE *pdrives = NULL; 2283 2284 /*@ int ******************************************************** */ 2285 int count_lilos = 0; 2286 int count_grubs = 0; 2287 2288 /*@ end vars *************************************************** */ 2289 2290 2291 #ifdef __IA64__ 2292 /* No choice for it */ 2293 return ('E'); 2294 #endif 2295 2296 tmp = where_is_root_mounted(); 2297 mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", tmp); 2298 mr_free(tmp); 2299 log_it("list_drives_cmd = %s", list_drives_cmd); 2300 2301 pdrives = popen(list_drives_cmd, "r"); 2302 mr_free(list_drives_cmd); 2303 2304 if (!pdrives) { 2305 log_OS_error("Unable to open list of drives"); 2306 return ('\0'); 2307 } 2308 2309 for (mr_getline(current_drive, pdrives); !feof(pdrives); mr_getline(current_drive, pdrives)) { 2310 mr_strip_spaces(current_drive); 2311 log_it("looking at drive %s's MBR", current_drive); 2312 if (does_string_exist_in_boot_block(current_drive, "GRUB")) { 2313 count_grubs++; 2314 /* BERLIOS : removed as I don't think it's mandatory here 2315 mr_free(which_device); 2316 mr_asprintf(which_device, "%s", current_drive); 2317 */ 2318 mr_free(current_drive); 2319 break; 2320 } 2321 if (does_string_exist_in_boot_block(current_drive, "LILO")) { 2322 count_lilos++; 2323 /* BERLIOS : removed as I don't think it's mandatory here 2324 mr_free(which_device); 2325 mr_asprintf(which_device, "%s", current_drive); 2326 */ 2327 mr_free(current_drive); 2328 break; 2329 } 2330 mr_free(current_drive); 2331 } 2332 mr_free(current_drive); 2333 2334 if (pclose(pdrives)) { 2335 log_OS_error("Cannot pclose pdrives"); 2336 } 2337 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos); 2338 if (count_grubs && !count_lilos) { 2339 return ('G'); 2340 } else if (count_lilos && !count_grubs) { 2341 return ('L'); 2342 } else if (count_grubs == 1 && count_lilos == 1) { 2343 log_it("I'll bet you used to use LILO but switched to GRUB..."); 2344 return ('G'); 2345 } else { 2346 // We need to look on each partition then 2347 mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep -E \"^/dev/\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/"); 2348 log_it("list_drives_cmd = %s", list_drives_cmd); 2349 2350 if (!(pdrives = popen(list_drives_cmd, "r"))) { 2351 log_OS_error("Unable to open list of drives"); 2352 mr_free(list_drives_cmd); 2353 return ('\0'); 2354 } 2355 mr_free(list_drives_cmd); 2356 2357 for (mr_getline(current_drive, pdrives); !feof(pdrives); mr_getline(current_drive, pdrives)) { 2358 mr_strip_spaces(current_drive); 2359 log_it("looking at partition %s's BR", current_drive); 2360 if (does_string_exist_in_boot_block(current_drive, "GRUB")) { 2361 count_grubs++; 2362 /* BERLIOS : removed as I don't think it's mandatory here 2363 mr_free(which_device); 2364 mr_asprintf(which_device, "%s", current_drive); 2365 */ 2366 mr_free(current_drive); 2367 break; 2368 } 2369 if (does_string_exist_in_boot_block(current_drive, "LILO")) { 2370 count_lilos++; 2371 /* BERLIOS : removed as I don't think it's mandatory here 2372 mr_free(which_device); 2373 mr_asprintf(which_device, "%s", current_drive); 2374 */ 2375 mr_free(current_drive); 2376 break; 2377 } 2378 mr_free(current_drive); 2379 } 2380 mr_free(current_drive); 2381 2382 if (pclose(pdrives)) { 2383 log_OS_error("Cannot pclose pdrives"); 2384 } 2385 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos); 2386 if (count_grubs && !count_lilos) { 2387 return ('G'); 2388 } else if (count_lilos && !count_grubs) { 2389 return ('L'); 2390 } else if (count_grubs == 1 && count_lilos == 1) { 2391 log_it("I'll bet you used to use LILO but switched to GRUB..."); 2392 return ('G'); 2393 } else { 2394 log_it("Unknown boot loader"); 2395 return ('U'); 2396 } 2397 } 2398 } 2399 #endif 2400 2401 2402 2403 2404 /** 2405 * Write zeroes over the first 16K of @p device. 2406 * @param device The device to zero. 2407 * @return 0 for success, 1 for failure. 2408 */ 2409 int zero_out_a_device(char *device) 2410 { 2411 FILE *fout; 2412 int i; 2413 2414 assert_string_is_neither_NULL_nor_zerolength(device); 2415 2416 log_it("Zeroing drive %s", device); 2417 if (!(fout = fopen(device, "w"))) { 2418 log_OS_error("Unable to open/write to device"); 2419 return (1); 2420 } 2421 for (i = 0; i < 16384; i++) { 2422 fputc('\0', fout); 2423 } 2424 paranoid_fclose(fout); 2425 log_it("Device successfully zeroed."); 2426 return (0); 2427 } 2428 2429 /** 2430 * Return the device pointed to by @p incoming. 2431 * @param incoming The device to resolve symlinks for. 2432 * @return The path to the real device file. 2433 * @note The returned string points to static storage that will be overwritten with each call. 2434 * @bug Won't work with file v4.0; needs to be written in C. 2435 */ 2436 char *resolve_softlinks_to_get_to_actual_device_file(char *incoming) 2437 { 2438 char *output; 2439 char *command = NULL; 2440 char *curr_fname; 2441 char *scratch = NULL; 2442 char *tmp = NULL; 2443 char *p; 2444 2445 struct stat statbuf; 2446 malloc_string(curr_fname); 2447 if (!does_file_exist(incoming)) { 2448 log_it("resolve_softlinks_to_get_to_actual_device_file --- device not found"); 2449 mr_asprintf(output, "%s", incoming); 2450 } else { 2451 strcpy(curr_fname, incoming); 2452 lstat(curr_fname, &statbuf); 2453 while (S_ISLNK(statbuf.st_mode)) { 2454 log_msg(1, "curr_fname = %s", curr_fname); 2455 mr_asprintf(command, "file %s", curr_fname); 2456 tmp = call_program_and_get_last_line_of_output(command); 2457 mr_free(command); 2458 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; p--); 2459 p++; 2460 mr_asprintf(scratch, "%s", p); 2461 for (p = scratch; *p != '\0' && *p != '\''; p++); 2462 *p = '\0'; 2463 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch); 2464 mr_free(tmp); 2465 2466 if (scratch[0] == '/') { 2467 strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink 2468 } else { // copy over the basename cos it's a relative softlink 2469 p = curr_fname + strlen(curr_fname); 2470 while (p != curr_fname && *p != '/') { 2471 p--; 2472 } 2473 if (*p == '/') { 2474 p++; 2475 } 2476 strcpy(p, scratch); 2477 } 2478 mr_free(scratch); 2479 lstat(curr_fname, &statbuf); 2480 } 2481 mr_asprintf(output, "%s", curr_fname); 2482 log_it("resolved %s to %s", incoming, output); 2483 } 2484 paranoid_free(curr_fname); 2485 return (output); 2486 } 2487 2488 /* @} - end of deviceGroup */ 2489 2490 /** 2491 * Return the type of partition format (GPT or MBR) 2492 */ 2493 char *which_partition_format(const char *drive) 2494 { 2495 char *output; 2496 char *tmp = NULL; 2497 char *command = NULL; 2498 char *fdisk = NULL; 2499 #ifdef __IA64__ 2500 struct stat buf; 2501 #endif 2502 mr_asprintf(fdisk, "/sbin/parted2fdisk"); 2503 mr_asprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive); 2504 mr_free(fdisk); 2505 2506 tmp = call_program_and_get_last_line_of_output(command); 2507 mr_free(command); 2508 2509 if (strstr(tmp, "GPT") == NULL) { 2510 mr_asprintf(output, "MBR"); 2511 } else { 2512 mr_asprintf(output, "GPT"); 2513 } 2514 mr_free(tmp); 2515 2516 log_msg(0, "Found %s partition table format type", output); 2517 return (output); 2518 } 2498 2519 2499 2520 /** -
branches/2.2.10/mondo/src/common/libmondo-filelist.c
r2420 r2444 29 29 30 30 31 extern ssize_t getline(char **lineptr, size_t * n, FILE * stream);32 31 extern char *MONDO_LOGFILE; 33 32 … … 1347 1346 /* dir is needed when we pass it to the shell */ 1348 1347 dir = mr_stresc(dir1, "`$\\\"(){}'[]&*?|!#~", '\\'); 1349 p = strrchr(dir , '/');1348 p = strrchr(dir1, '/'); 1350 1349 if (p) { 1351 1350 if (!strcmp(p, "/.") || !strcmp(p, "/..")) { … … 1428 1427 mr_free(tmp); 1429 1428 } else if (strstr(skip_these, new_with_spaces)) { 1429 log_msg(10, "Found dir ***%s**** excluded", dir1); 1430 1430 fprintf(fout, "%s\n", dir1); // if excluded dir then print dir ONLY 1431 1431 } else { 1432 log_msg(10, "Found dir ***%s**** parsed", dir1); 1432 1433 fprintf(fout, "%s\n", dir1); 1433 1434 while ((dit = readdir(dip)) != NULL) { … … 1442 1443 if (strstr(skip_these, new_with_spaces)) { 1443 1444 fprintf(fout, "%s\n", new); 1445 log_msg(10, "Found child dir ***%s**** excluded", new); 1444 1446 mr_free(new_with_spaces); 1445 1447 } else { … … 1448 1450 if (!S_ISLNK(statbuf.st_mode) 1449 1451 && S_ISDIR(statbuf.st_mode)) { 1452 log_msg(10, "Found child dir ***%s**** parsed", new); 1450 1453 open_and_list_dir(new, skip_these, fout, time_of_last_full_backup); 1451 1454 } else { 1452 1455 if (time_of_last_full_backup == 0 || time_of_last_full_backup < statbuf.st_ctime) { 1456 log_msg(10, "Found child file ***%s**** parsed", new); 1453 1457 fprintf(fout, "%s\n", new); 1454 1458 if ((counter++) > 128) { -
branches/2.2.10/mondo/src/common/libmondo-tools.c
r2428 r2444 742 742 } 743 743 744 if (path != NULL) { 745 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", path); 746 } else if (getenv("TMPDIR")) { 744 /* Always take in account env first */ 745 if (getenv("TMPDIR")) { 747 746 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR")); 748 747 } else if (getenv("TMP")) { 749 748 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP")); 749 } else if (path != NULL) { 750 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", path); 750 751 } else { 751 752 mr_asprintf(tmp, "/tmp/mondo.tmp.XXXXXX");
Note:
See TracChangeset
for help on using the changeset viewer.