Changeset 300


Ignore:
Timestamp:
Jan 11, 2006, 2:20:38 PM (14 years ago)
Author:
bcornec
Message:

merge -r295:299 $SVN_M/branches/2.06

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/mindi/analyze-my-lvm

    r276 r300  
    3636
    3737Die() {
    38     echo "$1" >> /dev/stderr
    39     exit 1
     38    echo "$1" >> /dev/stderr
     39    exit 1
    4040}
    4141
     
    4343
    4444GetValueFromField() {
    45     local res
    46     sed s/'    '/~/ "$1" | tr -s ' ' ' ' | sed s/'~ '/'~'/ | grep -i "$2~" | cut -d'~' -f2,3,4,5 | tr '~' ' ' | gawk '{ if ($2=="MB") {printf "%sm",$1;} else if ($2=="KB") {printf "%sk",$1;} else if ($2=="GB") {printf "%sg",$1;} else {print $0;};}'
     45    local res
     46    sed s/'    '/~/ "$1" | tr -s ' ' ' ' | sed s/'~ '/'~'/ | grep -i "$2~" | cut -d'~' -f2,3,4,5 | tr '~' ' ' | gawk '{ if ($2=="MB") {printf "%sm",$1;} else if ($2=="KB") {printf "%sk",$1;} else if ($2=="GB") {printf "%sg",$1;} else {print $0;};}'
    4747}
    4848
    4949
    5050GetLastBit() {
    51     local i res
    52     i=20
    53     res=""
    54     while [ ! "$res" ] ; do
    55     i=$(($i-1))
    56     res=`echo "$1" | cut -d'/' -f$i`
    57     done
    58     echo "$res"
     51    local i res
     52    i=20
     53    res=""
     54    while [ ! "$res" ] ; do
     55        i=$(($i-1))
     56        res=`echo "$1" | cut -d'/' -f$i`
     57    done
     58    echo "$res"
    5959}
    6060
    6161
    6262ProcessLogicalVolume() {
    63     local LV_full_string fname logical_volume volume_group device
    64     LV_full_string=$1
    65     [ ! -e "$1" ] && Die "Cannot find LV file $1"
    66     volume_group=`echo "$LV_full_string" | cut -d'/' -f3`
    67     logical_volume=`echo "$LV_full_string" | cut -d'/' -f4`
    68     if [ $lvmversion = 2 ]; then
    69     device=$LV_full_string
    70     params=`GenerateLvcreateParameters $device`
    71     echo "# lvm lvcreate$params -n $logical_volume $volume_group"
    72     else
    73     fname=/proc/lvm/VGs/$volume_group/LVs/$logical_volume
    74     if [ ! -e "$fname" ] ; then
    75         echo "Warning - cannot find $volume_group's $logical_volume LV file"
    76     else
    77         device=`GetValueFromField $fname "name:"`
    78         params=`GenerateLvcreateParameters $device`
    79         echo "# lvcreate$params -n $logical_volume $volume_group"
    80     fi
    81     fi
     63    local LV_full_string fname logical_volume volume_group device
     64    LV_full_string=$1
     65    [ ! -e "$1" ] && Die "Cannot find LV file $1"
     66    volume_group=`echo "$LV_full_string" | cut -d'/' -f3`
     67    logical_volume=`echo "$LV_full_string" | cut -d'/' -f4`
     68    if [ $lvmversion = 2 ]; then
     69        device=$LV_full_string
     70        params=`GenerateLvcreateParameters $device`
     71    else
     72        fname=/proc/lvm/VGs/$volume_group/LVs/$logical_volume
     73        if [ ! -e "$fname" ] ; then
     74            echo "Warning - cannot find $volume_group's $logical_volume LV file"
     75        else
     76            device=`GetValueFromField $fname "name:"`
     77            params=`GenerateLvcreateParameters $device`
     78        fi
     79    fi
     80    echo "# $LVMCMD lvcreate$params -n $logical_volume $volume_group"
    8281}
    8382
    8483
    8584GenerateLvcreateParameters() {
    86     local device stripes stripesize device fname allocation output readahead
    87     fname=/tmp/PLF.$$.txt
    88     device=$1
    89     output=""
    90     if [ $lvmversion = 2 ]; then
    91     lvm lvdisplay $device > $fname
    92     else
    93     lvdisplay $device > $fname
    94     fi
    95     stripes=`GetValueFromField $fname "Stripes"`
    96     stripesize=`GetValueFromField $fname "Stripe size (MByte)"`m
    97     [ "$stripesize" = "m" ] && stripesize=`GetValueFromField $fname "Stripe size (KByte)"`k
    98     [ "$stripesize" = "k" ] && stripesize=""
    99     allocation=`GetValueFromField $fname "LV Size"`
    100     [ ! "`echo "$allocation" | grep "[k,m,g]"`" ] && allocation="$allocation"m
    101     if echo "$allocation" | grep -x ".*g" > /dev/null 2> /dev/null ; then
    102     val=`echo "$allocation" | sed s/g//`
    103     allocation=`echo "$val" | awk '{c=$1; printf "%d", c*1024;}'`m
    104     fi
    105     readahead=`GetValueFromField $fname "Read ahead sectors"`
    106     rm -f $fname
    107     [ "$stripes" ]    && output="$output -i $stripes"
    108     [ "$stripesize" ] && output="$output -I $stripesize"
    109     [ "$allocation" ] && output="$output -L $allocation"
    110     [ "$readahead" ]  && output="$output -r $readahead"
    111     echo "$output"
     85    local device stripes stripesize device fname allocation output readahead
     86    fname=/tmp/PLF.$$.txt
     87    device=$1
     88    output=""
     89    $LVMCMD lvdisplay $device > $fname
     90    stripes=`GetValueFromField $fname "Stripes"`
     91    stripesize=`GetValueFromField $fname "Stripe size (MByte)"`m
     92    [ "$stripesize" = "m" ] && stripesize=`GetValueFromField $fname "Stripe size (KByte)"`k
     93    [ "$stripesize" = "k" ] && stripesize=""
     94    allocation=`GetValueFromField $fname "LV Size"`
     95    [ ! "`echo "$allocation" | grep "[k,m,g]"`" ] && allocation="$allocation"m
     96    if echo "$allocation" | grep -x ".*g" > /dev/null 2> /dev/null ; then
     97        val=`echo "$allocation" | sed s/g//`
     98        allocation=`echo "$val" | awk '{c=$1; printf "%d", c*1024;}'`m
     99    fi
     100    readahead=`GetValueFromField $fname "Read ahead sectors"`
     101    rm -f $fname
     102    [ "$stripes" ]    && output="$output -i $stripes"
     103    [ "$stripesize" ] && output="$output -I $stripesize"
     104    [ "$allocation" ] && output="$output -L $allocation"
     105    [ "$readahead" ]  && output="$output -r $readahead"
     106    echo "$output"
    112107}
    113108
     
    115110
    116111GenerateVgcreateParameters() {
    117     local current_VG device fname incoming VG_info_file max_logical_volumes max_physical_volumes physical_extent_size output blanklines
    118     current_VG=$1
    119     VG_info_file=/tmp/$$.vg-info.txt
    120     if [ $lvmversion = 2 ]; then
    121     lvm vgdisplay $current_VG > $VG_info_file
    122     else
    123     vgdisplay $current_VG > $VG_info_file
    124     fi
    125     max_logical_volumes=`GetValueFromField "$VG_info_file" "MAX LV"`
    126     [ $max_logical_volumes -ge 256 ] && max_logical_volumes=255
    127     max_physical_volumes=`GetValueFromField "$VG_info_file" "MAX PV"`
    128     [ $max_physical_volumes -ge 256 ] && max_physical_volumes=255
    129     physical_extent_size=`GetValueFromField "$VG_info_file" "PE Size"`
    130     output=""
    131     [ "$max_logical_volumes" ]  && output="$output -l $max_logical_volumes"
    132     [ "$max_physical_volumes" ] && output="$output -p $max_physical_volumes"
    133     [ "$physical_extent_size" ] && output="$output -s $physical_extent_size"
    134     echo "$output"
    135     rm -f $VG_info_file
     112    local current_VG device fname incoming VG_info_file max_logical_volumes max_physical_volumes physical_extent_size output blanklines
     113    current_VG=$1
     114    VG_info_file=/tmp/$$.vg-info.txt
     115    $LVMCMD vgdisplay $current_VG > $VG_info_file
     116    max_logical_volumes=`GetValueFromField "$VG_info_file" "MAX LV"`
     117    [ $max_logical_volumes -ge 256 ] && max_logical_volumes=255
     118    max_physical_volumes=`GetValueFromField "$VG_info_file" "MAX PV"`
     119    [ $max_physical_volumes -ge 256 ] && max_physical_volumes=255
     120    physical_extent_size=`GetValueFromField "$VG_info_file" "PE Size"`
     121    output=""
     122    [ "$max_logical_volumes" ]  && output="$output -l $max_logical_volumes"
     123    [ "$max_physical_volumes" ] && output="$output -p $max_physical_volumes"
     124    [ "$physical_extent_size" ] && output="$output -s $physical_extent_size"
     125    echo "$output"
     126    rm -f $VG_info_file
    136127}
    137128
     
    141132
    142133ProcessVolumeGroup() {
    143     local current_VG physical_volumes i list_of_devices VG_params
    144     current_VG=$1
    145     if [ $lvmversion = 2 ]; then
    146     VG_params=`GenerateVgcreateParameters $current_VG`
    147     list_of_devices=`lvm pvs | grep "$current_VG" | awk '{print $1}'`
    148     echo "# lvm vgcreate $current_VG$VG_params $list_of_devices"
    149     echo "# lvm vgchange -a y $current_VG"
    150     else
    151     info_file=/proc/lvm/VGs/$current_VG/group
    152     physical_volumes=`ls /proc/lvm/VGs/$current_VG/PVs`
    153     VG_params=`GenerateVgcreateParameters $current_VG`
    154     list_of_devices=""
    155     for i in $physical_volumes ; do
    156         fname=/proc/lvm/VGs/$current_VG/PVs/$i
    157         device=`GetValueFromField $fname "name:"`
    158         list_of_devices="$list_of_devices $device"
    159     done
    160     echo "# vgcreate $current_VG$VG_params$list_of_devices"
    161     echo "# vgchange -a y $current_VG"
    162     fi
     134    local current_VG physical_volumes i list_of_devices VG_params
     135    current_VG=$1
     136    if [ $lvmversion = 2 ]; then
     137        VG_params=`GenerateVgcreateParameters $current_VG`
     138        list_of_devices=`$LVMCMD pvs | grep "$current_VG" | awk '{print $1}'`
     139    else
     140        info_file=/proc/lvm/VGs/$current_VG/group
     141        physical_volumes=`ls /proc/lvm/VGs/$current_VG/PVs`
     142        VG_params=`GenerateVgcreateParameters $current_VG`
     143        list_of_devices=""
     144        for i in $physical_volumes ; do
     145            fname=/proc/lvm/VGs/$current_VG/PVs/$i
     146            device=`GetValueFromField $fname "name:"`
     147            list_of_devices="$list_of_devices $device"
     148        done
     149    fi
     150    echo "# $LVMCMD vgcreate $current_VG$VG_params $list_of_devices"
     151    echo "# $LVMCMD vgchange -a y $current_VG"
    163152}
    164153
     
    166155
    167156ListAllPhysicalVolumes() {
    168     if [ $lvmversion = 2 ]; then
    169     lvm pvscan 2> /dev/null | grep 'PV' | awk '{print $2}'
    170     else
    171     pvscan 2> /dev/null | grep '"' | cut -d'"' -f2
    172     fi
     157    if [ $lvmversion = 2 ]; then
     158        $LVMCMD pvscan 2> /dev/null | grep 'PV' | awk '{print $2}'
     159    else
     160        pvscan 2> /dev/null | grep '"' | cut -d'"' -f2
     161    fi
    173162}
    174163
    175164
    176165ListAllVolumeGroups() {
    177     if [ $lvmversion = 2 ]; then
    178         lvm vgdisplay 2> /dev/null | awk '/^ *VG Name/ {print $3;}'
    179     else
    180         vgdisplay 2> /dev/null | awk '/^VG Name/ {print $3;}'
    181     fi
     166    $LVMCMD vgdisplay 2> /dev/null | awk '/^ *VG Name/ {print $3;}'
    182167}
    183168
    184169
    185170ListLvmDrivesAndPartitions() {
    186     if [ $lvmversion = 2 ]; then
    187     lvm vgdisplay -v |grep "PV Name" | awk '{print $3}'
    188     else
    189     vgdisplay -v |grep "PV Name" | awk '{print $4}'
    190     fi
     171    $LVMCMD vgdisplay -v |grep "PV Name" | awk '{print $3}'
    191172}
    192173
     
    194175
    195176PrettifyList() {
    196     local i
    197     echo -en "$1"
    198     for i in $2 ; do
    199     echo -en "$i "
    200     done
    201     echo ""
     177    local i
     178    echo -en "$1"
     179    for i in $2 ; do
     180        echo -en "$i "
     181    done
     182    echo ""
    202183}
    203184
    204185
    205186ListAllLogicalVolumes() {
    206     if [ $lvmversion = 2 ]; then
    207     lvm lvscan | grep "'" | cut -d"'" -f2
    208     else
    209     lvscan | grep '"' | cut -d'"' -f2
    210     fi
     187    if [ $lvmversion = 2 ]; then
     188        $LVMCMD lvscan | grep "'" | cut -d"'" -f2
     189    else
     190        lvscan | grep '"' | cut -d'"' -f2
     191    fi
    211192}
    212193
     
    214195
    215196WriteShutdownScript() {
    216     local i
    217     echo ""
    218     echo "Finally, to shut down and delete the volumes, do this:-"
    219     if [ $lvmversion = 2 ]; then
     197    local i
     198    echo ""
     199    echo "Finally, to shut down and delete the volumes, do this:-"
    220200    for i in `ListAllLogicalVolumes` ; do
    221         echo "(lvm lvremove -f $i)"
     201        echo "($LVMCMD lvremove -f $i)"
    222202    done
    223203    for i in `ListAllVolumeGroups` ; do
    224         echo "(lvm vgchange -a n $i)"
     204        echo "($LVMCMD vgchange -a n $i)"
    225205    done
    226206    for i in `ListAllVolumeGroups` ; do
    227         echo "(lvm vgremove $i)"
    228     done
    229     echo "(rmmod dm-mod & rmmod dm_mod & )"
    230     else
    231     for i in `ListAllLogicalVolumes` ; do
    232         echo "(lvremove -f $i)"
    233     done
    234     for i in `ListAllVolumeGroups` ; do
    235         echo "(vgchange -a n $i)"
    236     done
    237     for i in `ListAllVolumeGroups` ; do
    238         echo "(vgremove $i)"
    239     done
    240     echo "(rmmod lvm-mod)"
    241     fi
     207        echo "($LVMCMD vgremove $i)"
     208    done
     209    if [ $lvmversion = 2 ]; then
     210        echo "(rmmod dm-mod & rmmod dm_mod & )"
     211    else
     212        echo "(rmmod lvm-mod)"
     213    fi
    242214}
    243215
     
    247219which lvmdiskscan 2>/dev/null 2>&1 || Die "Cannot find lvmdiskscan. Are you sure you're using LVM?"
    248220if [ -e "/proc/lvm/global" ] && [ "`tr -s '\t' ' ' < /proc/lvm/global | grep "0 VGs 0 PVs 0 LVs"`" != "" ] ; then
    249     exit 0
    250 fi
    251 
    252 # Sq-Mod ... V1 has different output. --version is not legal but version
    253 # gets displayed so I guess it's ok... This should work for both.
    254 
    255 #lvmversion=`lvmdiskscan --version | grep "LVM version:" | cut -d: -f2 | cut -d. -f1 | sed -e 's/ //g'`
    256 
    257 lvmversion=`lvmdiskscan --help |
     221    exit 0
     222fi
     223
     224lvmversion=`lvmdiskscan --help 2>&1 |
    258225  grep -E "Logical Volume Manager|LVM version:" |
    259226  cut -d: -f2 | cut -d. -f1 |
     
    262229
    263230if which lvm 2>/dev/null; then
    264     version=`lvm version | grep "LVM version" | awk '{print $3}'`
    265     i="`echo "$version" | cut -d'.' -f1`"
    266     echo "i=$i"
    267     if [ "$i" -ge "2" ] ; then
    268 #    if [ $version >= "2.00" ]; then
    269     lvmversion=2
    270     fi
     231    version=`lvm version | grep "LVM version" | awk '{print $3}'`
     232    i="`echo "$version" | cut -d'.' -f1`"
     233    echo "i=$i"
     234    if [ "$i" -ge "2" ] ; then
     235        lvmversion=2
     236    fi
    271237fi
    272238
    273239if [ $lvmversion = 2 ]; then
    274     echo "LVM version >= 2.0 found."
     240    echo "LVM version >= 2.0 found."
     241    LVMCMD="lvm"
     242else
     243    LVMCMD=""
    275244fi
    276245
     
    281250echo "To get started, type:-"
    282251if [ $lvmversion = 2 ]; then
    283     echo "(insmod dm-mod)"
    284     echo "(insmod dm_mod)"
    285     echo "# lvm vgchange -an"
     252    echo "(insmod dm-mod)"
     253    echo "(insmod dm_mod)"
    286254else
    287     echo "(insmod lvm-mod)"
    288     echo "# vgchange -an"
    289 fi
     255    echo "(insmod lvm-mod)"
     256fi
     257echo "# $LVMCMD vgchange -an"
    290258for i in `ListAllPhysicalVolumes` ; do
    291 #    echo "# dd if=/dev/zero of=$i bs=512 count=1"
    292     if [ $lvmversion = 2 ]; then
    293     echo "# echo y | lvm pvcreate -ff $i"
    294     else
    295     echo "# echo y | pvcreate -ff $i"
    296     fi
    297 done
    298 if [ $lvmversion = 2 ]; then
    299     echo "# lvm vgscan; echo"
    300 else
    301     echo "# vgscan; echo"
    302 fi
     259    echo "# echo y | $LVMCMD pvcreate -ff $i"
     260done
     261echo "# $LVMCMD vgscan; echo"
    303262echo ""
    304263echo "Create and activate the VG's (volume groups)."
    305264all_volume_groups=`ListAllVolumeGroups`
    306265for current_VG in $all_volume_groups ; do
    307     if [ $lvmversion -ne 2 ]; then
    308         echo "# rm -Rf /dev/$current_VG"
    309     fi
    310     ProcessVolumeGroup $current_VG
     266    if [ $lvmversion -ne 2 ]; then
     267        echo "# rm -Rf /dev/$current_VG"
     268    fi
     269    ProcessVolumeGroup $current_VG
    311270done
    312271echo ""
     
    314273all_logical_volumes=`ListAllLogicalVolumes`
    315274for current_LV in $all_logical_volumes ; do
    316     ProcessLogicalVolume $current_LV
     275    ProcessLogicalVolume $current_LV
    317276done
    318277echo ""
    319 if [ $lvmversion = 2 ]; then
    320     echo "# lvm vgscan"
    321 else
    322     echo "# vgscan"
    323 fi
     278echo "# $LVMCMD vgscan"
    324279echo "Now you may format the LV's:-"
    325280for i in `ListAllLogicalVolumes` ; do
    326     echo "(mkfs -t foo $i or something like that)"
     281    echo "(mkfs -t foo $i or something like that)"
    327282done
    328283WriteShutdownScript
  • trunk/mindi/mindi

    r292 r300  
    10251025    local module_list module fname oss r kern
    10261026    oss="/root/oss/modules"
    1027     module_list=`ListKernelModules`
     1027    module_list="`lsmod | sed -n '2,$s/ .*//p'`"
    10281028###
    10291029### Sq-Modification ... Use kernelname for module search path if specified
     
    10321032    if [ "${kernelname}" != "" -a "${kernelname}" != "FAILSAFE" ]
    10331033    then
    1034       kern=${kernelname}
    1035     else
    1036       kern="`uname -r`"
     1034        kern=${kernelname}
     1035    else
     1036        kern="`uname -r`"
    10371037    fi
    10381038###
     
    10411041    for module in $module_list $EXTRA_MODS ; do
    10421042        r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1`
    1043     echo "module $module --> $r" >> $LOGFILE
    1044     [ "$r" ] && echo "$r"
    1045     [ -f "$oss" ] && find $oss | fgrep $module
     1043        echo "module $module --> $r" >> $LOGFILE
     1044        [ "$r" ] && echo "$r"
     1045        [ -f "$oss" ] && find $oss | fgrep $module
    10461046    done
    10471047    find /lib/modules/$kern/modules.* -type f 2> /dev/null
     
    10511051
    10521052
    1053 ListKernelModules() {
    1054     local output q
    1055     output=""
    1056     for q in `lsmod | sed -n '2,$s/ .*//p'` ; do
    1057     output="$q $output"
    1058     done
    1059     echo "$output"
    1060 }
     1053#ListKernelModules() {
     1054    #local output q
     1055    #output=""
     1056    #for q in `lsmod | sed -n '2,$s/ .*//p'` ; do
     1057        #output="$q $output"
     1058    #done
     1059    #echo "`lsmod | sed -n '2,$s/ .*//p'`"
     1060#}
    10611061
    10621062
     
    12351235   
    12361236    echo -en "for outerloop in 1 2 3 4 5 ; do\necho -en \".\"\n" >> $outfile
    1237     list_to_echo="`ListKernelModules`"
     1237    list_to_echo="`lsmod | sed -n '2,$s/ .*//p'`"
    12381238#    LTE=`echo "$list_to_echo" | tr ' ' '\n' | grep -n "" | cut -d':' -f2,3,4 | tr '\n' ' '`
    12391239#    lte_old="$LTE"
     
    12451245    # Make temporary modprobe.conf file if we are told so
    12461246    if [ $tmpmodprobe_flag == "Y" ] ; then
    1247     infile="/tmp/modprobe.conf.mindi.$$"
    1248     find /etc/modprobe.d -maxdepth 1 -name "*" -xtype f > $infile
    1249     else
    1250     infile="/etc/modules.conf"
     1247        infile="/tmp/modprobe.conf.mindi.$$"
     1248        find /etc/modprobe.d -maxdepth 1 -name "*" -xtype f > $infile
     1249    else
     1250        infile="/etc/modules.conf"
    12511251    fi
    12521252    for module in $list_to_echo $EXTRA_MODS ; do
    1253     params=`sed -n "s/^options \\+$module \\+//p" $infile`
    1254     modpaths=`FindSpecificModuleInPath $searchpath $module`
    1255     for i in $modpaths ; do
    1256         echo "MyInsmod $i $params > /dev/null 2> /dev/null" \
    1257             | tr '.' '#' \
    1258             | sed s/#o#gz/#o/ \
    1259             | sed s/#o#gz/#o/ \
    1260             | sed s/#ko#gz/#ko/ \
    1261             | sed s/#ko#gz/#ko/ \
     1253        params=`sed -n "s/^options \\+$module \\+//p" $infile`
     1254        modpaths=`FindSpecificModuleInPath $searchpath $module`
     1255        for i in $modpaths ; do
     1256            echo "MyInsmod $i $params > /dev/null 2> /dev/null" \
     1257                | tr '.' '#' \
     1258                | sed s/#o#gz/#o/ \
     1259                | sed s/#o#gz/#o/ \
     1260                | sed s/#ko#gz/#ko/ \
     1261                | sed s/#ko#gz/#ko/ \
    12621262                | tr '#' '.' >> $outfile
    1263 
    1264         echo -en "$i added to module list.\n" >> $LOGFILE
    1265     done
     1263            echo -en "$i added to module list.\n" >> $LOGFILE
     1264        done
    12661265    done
    12671266    echo -en "done\n" >> $outfile
     
    12721271    # Remove temporary modprobe.conf file if we have created one
    12731272    if [ $tmpmodprobe_flag == "Y" ] ; then
    1274     rm -f $infile
     1273        rm -f $infile
    12751274    fi
    12761275}
     
    28702869
    28712870
    2872 
    2873 ListUnsavedKernelModules() {
    2874     local fname modules
    2875     fname=/tmp/$RANDOM.$$.$RANDOM
    2876     ListKernelModules > $fname
    2877     lsmod | cut -d' ' -f1 >> $fname
    2878     lsmod | cut -d' ' -f1 >> $fname
    2879     modules=`sort $fname | uniq -d2 | tr '\n' ' '`
    2880     rm -f $fname
    2881     [ "$modules" ] && echo "Unsaved kernel modules: $modules" >> $LOGFILE
    2882 }
     2871# BERLIOS: This function is wrong
     2872# Should be recoded. Desactivated in between
     2873
     2874#ListUnsavedKernelModules() {
     2875    #local fname modules
     2876    #fname=/tmp/$RANDOM.$$.$RANDOM
     2877    #lsmod | sed -n '2,$s/ .*//p' > $fname
     2878    #modules=`sort $fname | uniq -d2 | tr '\n' ' '`
     2879    #rm -f $fname
     2880    #[ "$modules" ] && echo "Unsaved kernel modules: $modules" >> $LOGFILE
     2881#}
    28832882
    28842883
     
    32423241rm -f /tmp/mountlist.txt.$$ $FDISKLOG /tmp/mindilinux
    32433242LogIt "$FRIENDLY_OUTSTRING\n"
    3244 ListUnsavedKernelModules
     3243#ListUnsavedKernelModules
    32453244for mtpt in $FLOPPY_WAS_MOUNTED ; do
    32463245    mount $mtpt
  • trunk/mondo/ChangeLog

    r295 r300  
    1818- Abort|Warn when one of the include|exclude dirs (-I|-E) does not exist
    1919  (Bruno Cornec/Jeffs)
     20- Replaced partimagehack with ntfsclone from ntfsprogs package.
     21  (Andree Leidenfrost)
    2022
    2123v2.06 (2005-12-23)
  • trunk/mondo/mondo/common/libmondo-archive-EXT.h

    r262 r300  
    2727extern int slice_up_file_etc(struct s_bkpinfo *bkpinfo,
    2828                             char *biggie_filename,
    29                              char *partimagehack_fifo,
     29                             char *ntfsprog_fifo,
    3030                             long biggie_file_number,
    3131                             long noof_biggie_files,
    32                              bool use_partimagehack);
     32                             bool use_ntfsprog);
    3333extern int verify_data(struct s_bkpinfo *bkpinfo);
    3434extern void wipe_archives(char *d);
  • trunk/mondo/mondo/common/libmondo-archive.c

    r262 r300  
    19681968    char *bigfile_fname = NULL;
    19691969    char *sz_devfile;
    1970     char *partimagehack_fifo = NULL;
     1970    char *ntfsprog_fifo = NULL;
    19711971    /*@ long *********************************************** */
    19721972    long biggie_file_number = 0;
     
    19811981    FILE *ftmp = NULL;
    19821982    bool delete_when_done;
    1983     bool use_partimagehack;
     1983    bool use_ntfsprog;
    19841984    /*@ long long ****************************************** */
    19851985    long long biggie_fsize;
     
    20152015    for (getline(&bigfile_fname, &n, fin); !feof(fin);
    20162016         getline(&bigfile_fname, &n, fin), biggie_file_number++) {
    2017         use_partimagehack = FALSE;
     2017        use_ntfsprog = FALSE;
    20182018        if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
    20192019            bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
     
    20292029            delete_when_done = TRUE;
    20302030        } else {
    2031             // Call partimagehack if it's a /dev entry (i.e. a partition to be imaged)
     2031            // Call ntfsclone (formerly partimagehack) if it's a /dev entry (i.e. a partition to be imaged)
    20322032            log_msg(2, "bigfile_fname = %s", bigfile_fname);
    2033             use_partimagehack = FALSE;
     2033            use_ntfsprog = FALSE;
    20342034            if (!strncmp(bigfile_fname, "/dev/", 5)
    20352035                && is_dev_an_NTFS_dev(bigfile_fname)) {
    2036                 use_partimagehack = TRUE;
     2036                use_ntfsprog = TRUE;
    20372037                log_msg(2,
    2038                         "Calling partimagehack in background because %s is an NTFS partition",
     2038                        "Calling ntfsclone in background because %s is an NTFS partition",
    20392039                        bigfile_fname);
    20402040                asprintf(&sz_devfile, "/tmp/%d.%d.000",
     
    20422042                         (int) (random() % 32768));
    20432043                mkfifo(sz_devfile, 0x770);
    2044                 partimagehack_fifo = sz_devfile;
     2044                ntfsprog_fifo = sz_devfile;
    20452045                switch (pid = fork()) {
    20462046                case -1:
     
    20482048                case 0:
    20492049                    log_msg(2,
    2050                             "CHILD - fip - calling feed_into_partimage(%s, %s)",
     2050                            "CHILD - fip - calling feed_into_ntfsprog(%s, %s)",
    20512051                            bigfile_fname, sz_devfile);
    2052                     res = feed_into_partimage(bigfile_fname, sz_devfile);
     2052                    res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
    20532053                    exit(res);
    20542054                    break;
    20552055                default:
    20562056                    log_msg(2,
    2057                             "feed_into_partimage() called in background --- pid=%ld",
     2057                            "feed_into_ntfsprog() called in background --- pid=%ld",
    20582058                            (long int) (pid));
    20592059
     
    20632063            // Otherwise, use good old 'dd' and 'bzip2'
    20642064            else {
    2065                 partimagehack_fifo = NULL;
     2065                ntfsprog_fifo = NULL;
    20662066            }
    20672067
     
    20722072            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    20732073                write_header_block_to_stream(biggie_fsize, bigfile_fname,
    2074                                              use_partimagehack ?
     2074                                             use_ntfsprog ?
    20752075                                             BLK_START_A_PIHBIGGIE :
    20762076                                             BLK_START_A_NORMBIGGIE);
    20772077            }
    2078             res = slice_up_file_etc(bkpinfo, bigfile_fname,
    2079                                     partimagehack_fifo, biggie_file_number,
    2080                                     noof_biggie_files, use_partimagehack);
     2078            res =
     2079                slice_up_file_etc(bkpinfo, bigfile_fname,
     2080                                  ntfsprog_fifo, biggie_file_number,
     2081                                  noof_biggie_files, use_ntfsprog);
    20812082            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    20822083                tmp = calc_checksum_of_file(bigfile_fname);
     
    29962997 *
    29972998 * @param biggie_filename The file to chop up.
    2998  * @param partimagehack_fifo The FIFO to partimagehack if this is an imagedev, NULL otherwise.
     2999 * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise.
    29993000 * @param biggie_file_number The sequence number of this biggie file (starting from 0).
    30003001 * @param noof_biggie_files The number of biggie files there are total.
     
    30053006int
    30063007slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
    3007                   char *partimagehack_fifo, long biggie_file_number,
    3008                   long noof_biggie_files, bool use_partimagehack)
     3008                  char *ntfsprog_fifo, long biggie_file_number,
     3009                  long noof_biggie_files, bool use_ntfsprog)
    30093010{
    30103011
     
    30493050
    30503051    biggiestruct.for_backward_compatibility = '\n';
    3051     biggiestruct.use_partimagehack = use_partimagehack;
     3052    biggiestruct.use_ntfsprog = use_ntfsprog;
    30523053    optimal_set_size = bkpinfo->optimal_set_size;
    30533054    if (is_this_file_compressed(biggie_filename)
     
    30643065        fatal_error("bkpinfo->optimal_set_size is insanely small");
    30653066    }
    3066     if (partimagehack_fifo) {
    3067         file_to_openin = partimagehack_fifo;
     3067    if (ntfsprog_fifo) {
     3068        file_to_openin = ntfsprog_fifo;
    30683069        asprintf(&checksum_line, "IGNORE");
    30693070        log_msg(2,
    30703071                "Not calculating checksum for %s: it would take too long",
    30713072                biggie_filename);
    3072         totallength = get_phys_size_of_drive(biggie_filename)*1024*1024LL;
     3073        if ( !find_home_of_exe("ntfsresize")) {
     3074            fatal_error("ntfsresize not found");
     3075        }
     3076        sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
     3077        log_it("command = %s", command);
     3078        strcpy (tmp, call_program_and_get_last_line_of_output(command));
     3079        log_it("res of it = %s", tmp);
     3080        totallength = atoll(tmp);
    30733081    } else {
    30743082        file_to_openin = biggie_filename;
  • trunk/mondo/mondo/common/libmondo-archive.h

    r262 r300  
    2929void set_bit_N_of_array(char *array, int N, bool true_or_false);
    3030int slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
    31                       char *partimagehack_fifo,
     31                      char *ntfsprog_fifo,
    3232                      long biggie_file_number, long noof_biggie_files,
    33                       bool use_partimagehack);
     33                      bool use_ntfsprog);
    3434int verify_data(struct s_bkpinfo *bkpinfo);
    3535void wipe_archives(char *d);
  • trunk/mondo/mondo/common/libmondo-files.c

    r236 r300  
    711711    char *biggielist;
    712712    char *comment;
     713    char *tmp;
     714    char *command;
    713715
    714716    /*@ long ******************************************************** */
     
    722724    /*@ end vars *************************************************** */
    723725
     726    malloc_string(tmp);
     727    malloc_string(command);
    724728    log_it("Calculating size of all biggiefiles (in total)");
    725729    asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     
    736740            }
    737741            if (0 == strncmp(fname, "/dev/", 5)) {
    738                 file_len_K = get_phys_size_of_drive(fname) * 1024L;
     742                if (is_dev_an_NTFS_dev(fname)) {
     743                    if ( !find_home_of_exe("ntfsresize")) {
     744                        fatal_error("ntfsresize not found");
     745                    }
     746                    sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
     747                    log_it("command = %s", command);
     748                    strcpy (tmp, call_program_and_get_last_line_of_output(command));
     749                    log_it("res of it = %s", tmp);
     750                    file_len_K = atoll(tmp) / 1024L;
     751                } else {
     752                    file_len_K = get_phys_size_of_drive(fname) * 1024L;
     753                }
    739754            } else {
    740755                file_len_K = (long) (length_of_file(fname) / 1024);
     
    761776    paranoid_fclose(fin);
    762777    log_it("Finished calculating total size of all biggiefiles");
     778    paranoid_free(tmp);
     779    paranoid_free(command);
    763780    return (scratchL);
    764781}
  • trunk/mondo/mondo/common/libmondo-fork-EXT.h

    r59 r300  
    1414                                                             char *cmd);
    1515extern int copy_from_src_to_dest(FILE *, FILE *, char);
    16 extern int feed_into_partimage(char *input_device, char *output_fname);
    17 extern int feed_outfrom_partimage(char *output_device, char *input_fifo);
     16extern int feed_into_ntfsprog(char *input_device, char *output_fname);
     17extern int feed_outfrom_ntfsprog(char *output_device, char *input_fifo);
  • trunk/mondo/mondo/common/libmondo-fork.c

    r171 r300  
    1 /* $Id$
    2   subroutines for handling forking/pthreads/etc.
     1/* libmondo-fork.c
     2   $Id$
     3
     4- subroutines for handling forking/pthreads/etc.
     5
     6
     701/20/2006
     8- replaced partimagehack with ntfsclone
     9
     1006/20/2004
     11- create fifo /var/log/partimagehack-debug.log and empty it
     12  to keep ramdisk from filling up
     13
     1404/13/2004
     15- >= should be <= g_loglevel
     16
     1711/15/2003
     18- changed a few []s to char*s
     19 
     2010/12
     21- rewrote partimagehack handling (multiple fifos, chunks, etc.)
     22
     2310/11
     24- partimagehack now has debug level of N (set in my-stuff.h)
     25
     2610/08
     27- call to partimagehack when restoring will now log errors to /var/log/....log
     28
     2910/06
     30- cleaned up logging a bit
     31
     3209/30
     33- line 735 - missing char* cmd in sprintf()
     34
     3509/28
     36- added run_external_binary_with_percentage_indicator()
     37- rewritten eval_call_to_make_ISO()
     38
     3909/18
     40- call mkstemp instead of mktemp
     41
     4209/13
     43- major NTFS hackage
     44
     4509/12
     46- paranoid_system("rm -f /tmp/ *PARTIMAGE*") before calling partimagehack
     47
     4809/11
     49- forward-ported unbroken feed_*_partimage() subroutines
     50  from early August 2003
     51
     5209/08
     53- detect & use partimagehack if it exists
     54
     5509/05
     56- finally finished partimagehack hack :)
     57
     5807/04
     59- added subroutines to wrap around partimagehack
     60
     6104/27
     62- don't echo (...res=%d...) at end of log_it()
     63  unnecessarily
     64- replace newtFinished() and newtInit() with
     65  newtSuspend() and newtResume()
     66
     6704/24
     68- added some assert()'s and log_OS_error()'s
     69
     7004/09
     71- cleaned up run_program_and_log_output()
     72
     7304/07
     74- cleaned up code a bit
     75- let run_program_and_log_output() accept -1 (only log if _no error_)
     76
     7701/02/2003
     78- in eval_call_to_make_ISO(), append output to MONDO_LOGFILE
     79  instead of a temporary stderr text file
     80
     8112/10
     82- patch by Heiko Schlittermann to handle % chars in issue.net
     83
     8411/18
     85- if mkisofs in eval_call_to_make_ISO() returns an error then return it,
     86  whether ISO was created or not
     87
     8810/30
     89- if mkisofs in eval_call_to_make_ISO() returns an error then find out if
     90  the output (ISO) file has been created; if it has then return 0 anyway
     91
     9208/01 - 09/30
     93- run_program_and_log_output() now takes boolean operator to specify
     94  whether it will log its activities in the event of _success_
     95- system() now includes 2>/dev/null
     96- enlarged some tmp[]'s
     97- added run_program_and_log_to_screen() and run_program_and_log_output()
     98
     9907/24
     100- created
    3101*/
    4102
     
    370468
    371469/**
    372  * Thread callback to run a command (partimage) in the background.
    373  * @param xfb A transfer block of @c char, containing:
    374  * - xfb:[0] A marker, should be set to 2. Decremented to 1 while the command is running and 0 when it's finished.
    375  * - xfb:[1] The command's return value, if xfb:[0] is 0.
    376  * - xfb+2:  A <tt>NULL</tt>-terminated string containing the command to be run.
    377  * @return NULL to pthread_join.
    378  */
    379 void *call_partimage_in_bkgd(void *xfb)
    380 {
    381     char *transfer_block;
    382     int retval = 0;
    383 
    384     g_buffer_pid = getpid();
    385     unlink("/tmp/null");
    386     log_msg(1, "starting");
    387     transfer_block = (char *) xfb;
    388     transfer_block[0]--;        // should now be 1
    389     retval = system(transfer_block + 2);
    390     if (retval) {
    391         log_OS_error("partimage returned an error");
    392     }
    393     transfer_block[1] = retval;
    394     transfer_block[0]--;        // should now be 0
    395     g_buffer_pid = 0;
    396     log_msg(1, "returning");
    397     pthread_exit(NULL);
    398 }
    399 
    400 
    401 /**
    402  * File to touch if we want partimage to wait for us.
    403  */
    404 #define PAUSE_PARTIMAGE_FNAME "/tmp/PAUSE-PARTIMAGE-FOR-MONDO"
    405 
    406 /**
    407470 * Apparently used. @bug This has a purpose, but what?
    408471 */
     
    410473#define PIMP_END_SZ "ENDENDEND0xBBC10xBBC2T231hc81h42vws89ff3kff9a82gv34r7fghbka"
    411474
    412 /**
    413  * Marker to start the next subvolume for Partimage.
    414  */
    415 #define NEXT_SUBVOL_PLEASE "I-grew-up-on-the-crime-side,-the-New-York-Times-side,-where-staying-alive-was-no-jive"
    416 
    417 /**
    418  * Marker to end the partimage file.
    419  */
    420 #define NO_MORE_SUBVOLS "On-second-hand,momma-bounced-on-old-man,-and-so-we-moved-to-Shaolin-Land."
     475
     476
    421477
    422478int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction)
     
    559615}
    560616
    561 
    562617/**
    563  * Call partimage from @p input_device to @p output_fname.
    564  * @param input_device The device to read.
    565  * @param output_fname The file to write.
    566  * @return 0 for success, nonzero for failure.
    567  */
    568 int dynamically_create_pipes_and_copy_from_them_to_output_file(char
    569                                                                *input_device, char
    570                                                                *output_fname)
    571 {
    572     char *curr_fifo;
    573     char *prev_fifo = NULL;
    574     char *next_fifo;
    575     char *command;
    576     char *sz_call_to_partimage;
    577     int fifo_number = 0;
    578     struct stat buf;
    579     pthread_t partimage_thread;
    580     int res = 0;
    581     char *tmpstub;
    582     FILE *fout;
    583     FILE *fin;
    584     char *tmp;
    585 
    586     log_msg(1, "g_tmpfs_mountpt = %s", g_tmpfs_mountpt);
    587     if (g_tmpfs_mountpt && g_tmpfs_mountpt[0]
    588         && does_file_exist(g_tmpfs_mountpt)) {
    589         asprintf(&tmpstub, g_tmpfs_mountpt);
    590     } else {
    591         asprintf(&tmpstub, "/tmp");
    592     }
    593     paranoid_system("rm -f /tmp/*PARTIMAGE*");
    594     asprintf(&command, "rm -Rf %s/pih-fifo-*", tmpstub);
    595     paranoid_system(command);
    596     paranoid_free(command);
    597 
    598     asprintf(&tmp, "%s/pih-fifo-%ld", tmpstub, (long int) random());
    599     paranoid_free(tmpstub);
    600     tmpstub = tmp;
    601     paranoid_free(tmp);
    602 
    603     mkfifo(tmpstub, S_IRWXU | S_IRWXG); // never used, though...
    604     asprintf(&curr_fifo, "%s.%03d", tmpstub, fifo_number);
    605     asprintf(&next_fifo, "%s.%03d", tmpstub, fifo_number + 1);
    606     mkfifo(curr_fifo, S_IRWXU | S_IRWXG);
    607     mkfifo(next_fifo, S_IRWXU | S_IRWXG);   // make sure _next_ fifo already exists before we call partimage
    608     asprintf(&sz_call_to_partimage,
    609             "%c%cpartimagehack " PARTIMAGE_PARAMS
    610             " save %s %s > /tmp/stdout 2> /tmp/stderr", 2, 0, input_device,
    611             tmpstub);
    612     log_msg(5, "curr_fifo   = %s", curr_fifo);
    613     log_msg(5, "next_fifo   = %s", next_fifo);
    614     log_msg(5, "sz_call_to_partimage call is '%s'",
    615             sz_call_to_partimage + 2);
    616     if (!lstat(output_fname, &buf) && S_ISREG(buf.st_mode)) {
    617         log_msg(5, "Deleting %s", output_fname);
    618         unlink(output_fname);
    619     }
    620     if (!(fout = fopen(output_fname, "w"))) {
    621         fatal_error("Unable to openout to output_fname");
    622     }
    623     res =
    624         pthread_create(&partimage_thread, NULL, call_partimage_in_bkgd,
    625                        (void *) sz_call_to_partimage);
    626     if (res) {
    627         fatal_error("Failed to create thread to call partimage");
    628     }
    629     log_msg(1, "Running fore/back at same time");
    630     log_to_screen("Working with partimagehack...");
    631     while (sz_call_to_partimage[0] > 0) {
    632         asprintf(&tmp, "%s\n", NEXT_SUBVOL_PLEASE);
    633         if (fwrite(tmp, 1, 128, fout) != 128) {
    634             fatal_error("Cannot write interim block");
    635         }
    636         paranoid_free(tmp);
    637 
    638         log_msg(5, "fifo_number=%d", fifo_number);
    639         log_msg(4, "Cat'ting %s", curr_fifo);
    640         if (!(fin = fopen(curr_fifo, "r"))) {
    641             fatal_error("Unable to openin from fifo");
    642         }
    643         if (prev_fifo !=  NULL) {
    644             log_msg(5, "Deleting %s", prev_fifo);
    645             unlink(prev_fifo);      // just in case
    646             paranoid_free(prev_fifo);
    647         }
    648         copy_from_src_to_dest(fin, fout, 'w');
    649         paranoid_fclose(fin);
    650         fifo_number++;
    651 
    652         prev_fifo = curr_fifo;
    653         curr_fifo = next_fifo;
    654         log_msg(5, "Creating %s", next_fifo);
    655         asprintf(&next_fifo, "%s.%03d", tmpstub, fifo_number + 1);
    656         mkfifo(next_fifo, S_IRWXU | S_IRWXG);   // make sure _next_ fifo exists before we cat this one
    657         system("sync");
    658         sleep(5);
    659     }
    660     asprintf(&tmp, "%s\n", NO_MORE_SUBVOLS);
    661     if (fwrite(tmp, 1, 128, fout) != 128) {
    662         fatal_error("Cannot write interim block");
    663     }
    664     if (fwrite(tmp, 1, 128, fout) != 128) {
    665         fatal_error("Cannot write interim block");
    666     }
    667     if (fwrite(tmp, 1, 128, fout) != 128) {
    668         fatal_error("Cannot write interim block");
    669     }
    670     if (fwrite(tmp, 1, 128, fout) != 128) {
    671         fatal_error("Cannot write interim block");
    672     }
    673     paranoid_free(tmp);
    674     paranoid_fclose(fout);
    675     log_to_screen("Cleaning up after partimagehack...");
    676     log_msg(3, "Final fifo_number=%d", fifo_number);
    677     paranoid_system("sync");
    678     unlink(next_fifo);
    679     paranoid_free(next_fifo);
    680 
    681     unlink(curr_fifo);
    682     paranoid_free(curr_fifo);
    683 
    684     unlink(prev_fifo);
    685     paranoid_free(prev_fifo);
    686 
    687     log_to_screen("Finished cleaning up.");
    688 
    689 //  if (!lstat(sz_wait_for_this_file, &statbuf))
    690 //    { log_msg(3, "WARNING! %s was not processed.", sz_wait_for_this_file); }
    691     log_msg(2, "Waiting for pthread_join() to join.");
    692     pthread_join(partimage_thread, NULL);
    693     res = sz_call_to_partimage[1];
    694     paranoid_free(sz_call_to_partimage);
    695     log_msg(2, "pthread_join() joined OK.");
    696     log_msg(1, "Partimagehack(save) returned %d", res);
    697     unlink(tmpstub);
    698     paranoid_free(tmpstub);
    699 
    700     return (res);
    701 }
    702 
    703 
    704 /**
    705  * Feed @p input_device through partimage to @p output_fname.
     618 * Feed @p input_device through ntfsclone to @p output_fname.
    706619 * @param input_device The device to image.
    707620 * @param output_fname The file to write.
    708621 * @return 0 for success, nonzero for failure.
    709622 */
    710 int feed_into_partimage(char *input_device, char *output_fname)
     623int feed_into_ntfsprog(char *input_device, char *output_fname)
    711624{
    712625// BACKUP
    713     int res;
     626    int res = -1;
     627    char*command;
    714628
    715629    if (!does_file_exist(input_device)) {
    716630        fatal_error("input device does not exist");
    717631    }
    718     if (!find_home_of_exe("partimagehack")) {
    719         fatal_error("partimagehack not found");
    720     }
    721     res =
    722         dynamically_create_pipes_and_copy_from_them_to_output_file
    723         (input_device, output_fname);
     632    if ( !find_home_of_exe("ntfsclone")) {
     633        fatal_error("ntfsclone not found");
     634    }
     635    malloc_string(command);
     636    sprintf(command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device);
     637    res = run_program_and_log_output(command, 5);
     638    paranoid_free(command);
    724639    return (res);
    725640}
     
    871786}
    872787
    873 #define PIH_LOG "/var/log/partimage-debug.log"
    874788
    875789/**
    876  * Feed @p input_fifo through partimage (restore) to @p output_device.
    877  * @param input_fifo The partimage file to read.
     790 * Feed @p input_fifo through ntfsclone (restore) to @p output_device.
     791 * @param input_fifo The ntfsclone file to read.
    878792 * @param output_device Where to put the output.
    879  * @return The return value of partimagehack (0 for success).
    880  * @bug Probably unnecessary, as the partimage is just a sparse file. We could use @c dd to restore it.
     793 * @return The return value of ntfsclone (0 for success).
    881794 */
    882 int feed_outfrom_partimage(char *output_device, char *input_fifo)
     795int feed_outfrom_ntfsprog(char *output_device, char *input_fifo)
    883796{
    884797// RESTORE
    885     char *tmp;
    886     char *stuff;
    887     char *sz_call_to_partimage;
    888     pthread_t partimage_thread;
    889     int res;
    890     char *curr_fifo;
    891     char *prev_fifo = NULL;
    892     char *oldest_fifo = NULL;
    893     char *next_fifo;
    894     char *afternxt_fifo;
    895     int fifo_number = 0;
    896     char *tmpstub;
    897     FILE *fin;
    898     FILE *fout;
    899 
    900     log_msg(1, "output_device=%s", output_device);
    901     log_msg(1, "input_fifo=%s", input_fifo);
    902     asprintf(&tmpstub, "/tmp");
    903 
    904     log_msg(1, "tmpstub was %s", tmpstub);
    905     asprintf(&stuff, tmpstub);
    906     paranoid_free(tmpstub);
    907 
    908     asprintf(&tmpstub, "%s/pih-fifo-%ld", stuff, (long int) random());
    909     paranoid_free(stuff);
    910 
    911     log_msg(1, "tmpstub is now %s", tmpstub);
    912     unlink("/tmp/PARTIMAGEHACK-POSITION");
    913     unlink(PAUSE_PARTIMAGE_FNAME);
    914     paranoid_system("rm -f /tmp/*PARTIMAGE*");
    915     asprintf(&curr_fifo, "%s.%03d", tmpstub, fifo_number);
    916     asprintf(&next_fifo, "%s.%03d", tmpstub, fifo_number + 1);
    917     asprintf(&afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2);
    918     mkfifo(PIH_LOG, S_IRWXU | S_IRWXG);
    919     mkfifo(curr_fifo, S_IRWXU | S_IRWXG);
    920     mkfifo(next_fifo, S_IRWXU | S_IRWXG);   // make sure _next_ fifo already exists before we call partimage
    921     mkfifo(afternxt_fifo, S_IRWXU | S_IRWXG);
    922     system("cat " PIH_LOG " > /dev/null &");
    923     log_msg(3, "curr_fifo   = %s", curr_fifo);
    924     log_msg(3, "next_fifo   = %s", next_fifo);
    925     if (!does_file_exist(input_fifo)) {
    926         fatal_error("input fifo does not exist");
    927     }
    928     if (!(fin = fopen(input_fifo, "r"))) {
    929         fatal_error("Unable to openin from input_fifo");
    930     }
    931     if (!find_home_of_exe("partimagehack")) {
    932         fatal_error("partimagehack not found");
    933     }
    934     asprintf(&sz_call_to_partimage,
    935             "%c%cpartimagehack " PARTIMAGE_PARAMS
    936             " restore %s %s > /dev/null 2>> %s", 2, 0, output_device, curr_fifo,
    937             MONDO_LOGFILE);
    938     log_msg(1, "output_device = %s", output_device);
    939     log_msg(1, "curr_fifo = %s", curr_fifo);
    940     log_msg(1, "sz_call_to_partimage+2 = %s", sz_call_to_partimage + 2);
    941     res =
    942         pthread_create(&partimage_thread, NULL, call_partimage_in_bkgd,
    943                        (void *) sz_call_to_partimage);
    944     if (res) {
    945         fatal_error("Failed to create thread to call partimage");
    946     }
    947     log_msg(1, "Running fore/back at same time");
    948     log_msg(2, " Trying to openin %s", input_fifo);
    949     if (!does_file_exist(input_fifo)) {
    950         log_msg(2, "Warning - %s does not exist", input_fifo);
    951     }
    952     while (!does_file_exist("/tmp/PARTIMAGEHACK-POSITION")) {
    953         log_msg(6, "Waiting for partimagehack (restore) to start");
    954         sleep(1);
    955     }
    956 
    957     if (!(tmp = malloc(128))) {
    958         fatal_error("Failed to malloc() tmp");
    959     }
    960     while (sz_call_to_partimage[0] > 0) {
    961         if (fread(tmp, 1, 128, fin) != 128) {
    962             fatal_error("Cannot read introductory block");
    963         }
    964         if (strstr(tmp, NEXT_SUBVOL_PLEASE)) {
    965             log_msg(2, "Great. Next subvol coming up.");
    966         } else if (strstr(tmp, NO_MORE_SUBVOLS)) {
    967             log_msg(2, "Great. That was the last subvol.");
    968             break;
    969         } else {
    970             log_msg(2, "WTF is this? '%s'", tmp);
    971             fatal_error("Unknown interim block");
    972         }
    973         if (feof(fin)) {
    974             log_msg(1, "Eof(fin) detected. Breaking.");
    975             break;
    976         }
    977         log_msg(3, "Processing subvol %d", fifo_number);
    978         log_msg(5, "fifo_number=%d", fifo_number);
    979         if (!(fout = fopen(curr_fifo, "w"))) {
    980             fatal_error("Cannot openout to curr_fifo");
    981         }
    982         copy_from_src_to_dest(fout, fin, 'r');
    983         paranoid_fclose(fout);
    984         fifo_number++;
    985         if (oldest_fifo != NULL) {
    986             log_msg(6, "Deleting %s", oldest_fifo);
    987             unlink(oldest_fifo);    // just in case
    988             paranoid_free(oldest_fifo);
    989         }
    990         oldest_fifo = prev_fifo;
    991         prev_fifo = curr_fifo;
    992         curr_fifo = next_fifo;
    993         next_fifo = afternxt_fifo;
    994         asprintf(&afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2);
    995         log_msg(6, "Creating %s", afternxt_fifo);
    996         mkfifo(afternxt_fifo, S_IRWXU | S_IRWXG);   // make sure _next_ fifo already exists before we access current fifo
    997         fflush(fin);
    998 //      system("sync");
    999         usleep(1000L * 100L);
    1000     }
    1001     paranoid_free(tmp);
    1002     paranoid_free(tmpstub);
    1003 
    1004     paranoid_fclose(fin);
    1005     paranoid_system("sync");
    1006     log_msg(1, "Partimagehack has finished. Great. Fin-closing.");
    1007     log_msg(1, "Waiting for pthread_join");
    1008     pthread_join(partimage_thread, NULL);
    1009     res = sz_call_to_partimage[1];
    1010     paranoid_free(sz_call_to_partimage);
    1011 
    1012     log_msg(1, "Yay. Partimagehack (restore) returned %d", res);
    1013     unlink(prev_fifo);
    1014     paranoid_free(prev_fifo);
    1015 
    1016     unlink(curr_fifo);
    1017     paranoid_free(curr_fifo);
    1018 
    1019     unlink(next_fifo);
    1020     paranoid_free(next_fifo);
    1021 
    1022     unlink(afternxt_fifo);
    1023     paranoid_free(afternxt_fifo);
    1024 
    1025     unlink(PIH_LOG);
    1026     /* BERLIOS : pas de unlink(oldest_fifo) ??? */
    1027     paranoid_free(oldest_fifo);
    1028 
     798    int res = -1;
     799    char *command;
     800
     801    if ( !find_home_of_exe("ntfsclone")) {
     802        fatal_error("ntfsclone not found");
     803    }
     804    asprintf(&command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo);
     805    res = run_program_and_log_output(command, 5);
     806    paranoid_free(command);
    1029807    return (res);
    1030808}
  • trunk/mondo/mondo/common/libmondo-fork.h

    r59 r300  
    1515int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd);
    1616int copy_from_src_to_dest(FILE *, FILE *, char);
    17 int feed_into_partimage(char *input_device, char *output_fname);
    18 int feed_outfrom_partimage(char *output_device, char *input_fifo);
     17int feed_into_ntfsprog(char *input_device, char *output_fname);
     18int feed_outfrom_ntfsprog(char *output_device, char *input_fifo);
  • trunk/mondo/mondo/common/libmondo-verify.c

    r274 r300  
    339339                if (res && !strncmp(biggiestruct.filename, " /dev/", 5)) {
    340340                    log_msg(3,
    341                             "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via partimagehack, not dd.",
     341                            "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via ntfsclone, not dd.",
    342342                            biggiestruct.filename);
    343343                    log_msg(3,
  • trunk/mondo/mondo/common/mondostructures.h

    r171 r300  
    342342   *
    343343   * This is useful for backing up NTFS partitions.
    344    * @c partimage is used to back up only the used sectors, so the space tradeoff is not bad.
     344   * @c ntfsclone is used to back up only the used sectors, so the space tradeoff is not bad.
    345345   * However, several caveats apply to such a partition:
    346346   * - It must not be mounted during the backup
    347    * - It must be in a format that partimage knows how to handle
     347   * - It must be in a format that ntfsclone knows how to handle, i.e. NTFS
    348348   * - It cannot be verified during the verify or compare phase
    349349   * - It may not be resized or selectively restored at restore-time (all or nothing)
     
    661661     */
    662662    struct stat properties;
    663     bool use_partimagehack;
     663    bool use_ntfsprog;
    664664};
    665665
  • trunk/mondo/mondo/common/my-stuff.h

    r238 r300  
    151151#define BLK_STOP_BIGGIEFILES    39  ///< Marker block: stop the biggiefile section.
    152152#define BLK_START_A_NORMBIGGIE  40  ///< Marker block: start a normal biggiefile.
    153 #define BLK_START_A_PIHBIGGIE   41  ///< Marker block: start a partimagehack'd biggiefile
     153#define BLK_START_A_PIHBIGGIE   41  ///< Marker block: start a ntfsprog'd biggiefile
    154154#define BLK_START_EXTENDED_ATTRIBUTES 45    ///< Marker block: start xattr/acl info
    155155#define BLK_STOP_EXTENDED_ATTRIBUTES 46 ///< Marker block: stop xattr/acl info
     
    389389#define DEFAULT_DEBUG_LEVEL 4   ///< By default, don't log messages with a loglevel higher than this.
    390390
    391 #define SZ_PARTIMAGE_VOLSIZE "1048576"  // was 4096
    392 #define PARTIMAGE_PARAMS "-z0 -V" SZ_PARTIMAGE_VOLSIZE " -o -b -d -g1"
     391#define SZ_NTFSPROG_VOLSIZE "1048576"   // was 4096
     392#define NTFSPROG_PARAMS "-z0 -V" SZ_NTFSPROG_VOLSIZE " -o -b -d -g1"
    393393
    394394#define MNT_CDROM "/mnt/cdrom"
  • trunk/mondo/mondo/common/newt-specific.c

    r219 r300  
    281281        kill_anything_like_this("/mondo/do-not");
    282282        kill_anything_like_this("tmp.mondo");
    283         kill_anything_like_this("partimagehack");
     283        kill_anything_like_this("ntfsclone");
    284284        sync();
    285285        asprintf(&tmp, "umount %s", g_tmpfs_mountpt);
  • trunk/mondo/mondo/mondoarchive/main.c

    r262 r300  
    157157
    158158    diffs = 0;
    159     unlink("/var/log/partimagehack-debug.log");
    160159    printf("Initializing...\n");
    161160    if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) {
  • trunk/mondo/mondo/mondoarchive/mondo-cli.c

    r292 r300  
    572572        asprintf(&tmp, flag_val['x']);
    573573        bkpinfo->image_devs = tmp;
    574         if (run_program_and_log_output("which partimagehack", 2)) {
    575             fatal_error("Please install partimagehack RPM/tarball.");
     574        if (run_program_and_log_output("which ntfsclone", 2)) {
     575            fatal_error("Please install ntfsprogs package/tarball.");
    576576        }
    577577    }
  • trunk/mondo/mondo/mondorestore/mondo-restore.c

    r274 r300  
    13681368  /** malloc ***/
    13691369    char *checksum, *outfile_fname, *tmp, *bzip2_command,
    1370         *partimagehack_command, *suffix, *sz_devfile;
     1370        *ntfsprog_command, *suffix, *sz_devfile;
    13711371    char *bigblk;
    13721372    char *p;
     
    13751375    long sliceno;
    13761376    long siz;
    1377     char partimagehack_fifo[MAX_STR_LEN];
     1377    char ntfsprog_fifo[MAX_STR_LEN];
    13781378    char *file_to_openout = NULL;
    13791379    struct s_filename_and_lstat_info biggiestruct;
    13801380    struct utimbuf the_utime_buf, *ubuf;
    1381     bool use_partimage_hack = FALSE;
     1381    bool use_ntfsprog_hack = FALSE;
    13821382    pid_t pid;
    13831383    int res = 0;
     
    13941394    malloc_string(tmp);
    13951395    malloc_string(bzip2_command);
    1396     malloc_string(partimagehack_command);
     1396    malloc_string(ntfsprog_command);
    13971397    malloc_string(suffix);
    13981398    malloc_string(sz_devfile);
     
    14511451
    14521452    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
    1453     if (biggiestruct.use_partimagehack) {
     1453    if (biggiestruct.use_ntfsprog) {
    14541454        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
    14551455            log_msg(1,
    1456                     "I was in error when I set biggiestruct.use_partimagehack to TRUE.");
     1456                    "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
    14571457            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
    1458             biggiestruct.use_partimagehack = FALSE;
    1459         }
    1460     }
    1461 
    1462     if (biggiestruct.use_partimagehack) // if it's an NTFS device
     1458            biggiestruct.use_ntfsprog = FALSE;
     1459        }
     1460    }
     1461
     1462    if (biggiestruct.use_ntfsprog)  // if it's an NTFS device
    14631463//  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
    14641464    {
    14651465        g_loglevel = 4;
    1466         use_partimage_hack = TRUE;
     1466        use_ntfsprog_hack = TRUE;
    14671467        log_msg(2,
    1468                 "Calling partimagehack in background because %s is an NTFS /dev entry",
     1468                "Calling ntfsclone in background because %s is an NTFS /dev entry",
    14691469                outfile_fname);
    14701470        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
    14711471                (int) (random() % 32768));
    14721472        mkfifo(sz_devfile, 0x770);
    1473         strcpy(partimagehack_fifo, sz_devfile);
    1474         file_to_openout = partimagehack_fifo;
     1473        strcpy(ntfsprog_fifo, sz_devfile);
     1474        file_to_openout = ntfsprog_fifo;
    14751475        switch (pid = fork()) {
    14761476        case -1:
     
    14781478        case 0:
    14791479            log_msg(3,
    1480                     "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
    1481                     biggiestruct.filename, partimagehack_fifo);
     1480                    "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
     1481                    biggiestruct.filename, ntfsprog_fifo);
    14821482            res =
    1483                 feed_outfrom_partimage(biggiestruct.filename,
    1484                                        partimagehack_fifo);
     1483                feed_outfrom_ntfsprog(biggiestruct.filename,
     1484                                       ntfsprog_fifo);
    14851485//          log_msg(3, "CHILD - fip - exiting");
    14861486            exit(res);
     
    14881488        default:
    14891489            log_msg(3,
    1490                     "feed_into_partimage() called in background --- pid=%ld",
     1490                    "feed_into_ntfsprog() called in background --- pid=%ld",
    14911491                    (long int) (pid));
    14921492        }
    14931493    } else {
    1494         use_partimage_hack = FALSE;
    1495         partimagehack_fifo[0] = '\0';
     1494        use_ntfsprog_hack = FALSE;
     1495        ntfsprog_fifo[0] = '\0';
    14961496        file_to_openout = outfile_fname;
    14971497        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    15201520        return (1);
    15211521    }
    1522     log_msg(3, "Opened out to %s", outfile_fname);  // CD/DVD --> mondorestore --> partimagehack --> hard disk itself
     1522    log_msg(3, "Opened out to %s", outfile_fname);  // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
    15231523
    15241524    for (sliceno = 1, finished = FALSE; !finished;) {
     
    16291629    g_loglevel = old_loglevel;
    16301630
    1631     if (use_partimage_hack) {
    1632         log_msg(3, "Waiting for partimage to finish");
     1631    if (use_ntfsprog_hack) {
     1632        log_msg(3, "Waiting for ntfsclone to finish");
    16331633        sprintf(tmp,
    1634                 " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
     1634                " ps ax | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
    16351635        while (system(tmp) == 0) {
    16361636            sleep(1);
    16371637        }
    1638         log_it("OK, partimage has really finished");
     1638        log_it("OK, ntfsclone has really finished");
    16391639    }
    16401640
     
    16521652    paranoid_free(tmp);
    16531653    paranoid_free(bzip2_command);
    1654     paranoid_free(partimagehack_command);
     1654    paranoid_free(ntfsprog_command);
    16551655    paranoid_free(suffix);
    16561656    paranoid_free(sz_devfile);
     
    16821682                                     long long biggiefile_size, //UNUSED
    16831683                                     struct s_node *filelist,
    1684                                      int use_partimagehack,
     1684                                     int use_ntfsprog,
    16851685                                     char *pathname_of_last_file_restored)
    16861686{
     
    16921692    char *command;
    16931693    char *outfile_fname;
    1694     char *partimagehack_command;
     1694    char *ntfsprog_command;
    16951695    char *sz_devfile;
    1696     char *partimagehack_fifo;
     1696    char *ntfsprog_fifo;
    16971697    char *file_to_openout = NULL;
    16981698
     
    17061706    long long slice_siz;
    17071707    bool dummy_restore = FALSE;
    1708     bool use_partimage_hack = FALSE;
     1708    bool use_ntfsprog_hack = FALSE;
    17091709    pid_t pid;
    17101710    struct s_filename_and_lstat_info biggiestruct;
     
    17131713
    17141714    malloc_string(tmp);
    1715     malloc_string(partimagehack_fifo);
     1715    malloc_string(ntfsprog_fifo);
    17161716    malloc_string(outfile_fname);
    17171717    malloc_string(command);
    17181718    malloc_string(sz_devfile);
    1719     malloc_string(partimagehack_command);
     1719    malloc_string(ntfsprog_command);
    17201720    old_loglevel = g_loglevel;
    17211721    assert(bkpinfo != NULL);
     
    17241724
    17251725    pathname_of_last_file_restored[0] = '\0';
    1726     if (use_partimagehack == BLK_START_A_PIHBIGGIE) {
    1727         use_partimagehack = 1;
     1726    if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
     1727        use_ntfsprog = 1;
    17281728        log_msg(1, "%s --- pih=YES", orig_bf_fname);
    1729     } else if (use_partimagehack == BLK_START_A_NORMBIGGIE) {
    1730         use_partimagehack = 0;
     1729    } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
     1730        use_ntfsprog = 0;
    17311731        log_msg(1, "%s --- pih=NO", orig_bf_fname);
    17321732    } else {
    1733         use_partimagehack = 0;
     1733        use_ntfsprog = 0;
    17341734        log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
    17351735    }
     
    17571757    }
    17581758
    1759     if (use_partimagehack) {
     1759    if (use_ntfsprog) {
    17601760        if (strncmp(orig_bf_fname, "/dev/", 5)) {
    17611761            log_msg(1,
    1762                     "I was in error when I set use_partimagehack to TRUE.");
     1762                    "I was in error when I set use_ntfsprog to TRUE.");
    17631763            log_msg(1, "%s isn't even in /dev", orig_bf_fname);
    1764             use_partimagehack = FALSE;
    1765         }
    1766     }
    1767 
    1768     if (use_partimagehack) {
     1764            use_ntfsprog = FALSE;
     1765        }
     1766    }
     1767
     1768    if (use_ntfsprog) {
    17691769        g_loglevel = 4;
    17701770        strcpy(outfile_fname, orig_bf_fname);
    1771         use_partimage_hack = TRUE;
     1771        use_ntfsprog_hack = TRUE;
    17721772        log_msg(2,
    1773                 "Calling partimagehack in background because %s is a /dev entry",
     1773                "Calling ntfsclone in background because %s is a /dev entry",
    17741774                outfile_fname);
    17751775        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
    17761776                (int) (random() % 32768));
    17771777        mkfifo(sz_devfile, 0x770);
    1778         strcpy(partimagehack_fifo, sz_devfile);
    1779         file_to_openout = partimagehack_fifo;
     1778        strcpy(ntfsprog_fifo, sz_devfile);
     1779        file_to_openout = ntfsprog_fifo;
    17801780        switch (pid = fork()) {
    17811781        case -1:
     
    17831783        case 0:
    17841784            log_msg(3,
    1785                     "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
    1786                     outfile_fname, partimagehack_fifo);
     1785                    "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
     1786                    outfile_fname, ntfsprog_fifo);
    17871787            res =
    1788                 feed_outfrom_partimage(outfile_fname, partimagehack_fifo);
     1788                feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
    17891789//          log_msg(3, "CHILD - fip - exiting");
    17901790            exit(res);
     
    17921792        default:
    17931793            log_msg(3,
    1794                     "feed_into_partimage() called in background --- pid=%ld",
     1794                    "feed_into_ntfsprog() called in background --- pid=%ld",
    17951795                    (long int) (pid));
    17961796        }
     
    18041804                    orig_bf_fname);
    18051805        }
    1806         use_partimage_hack = FALSE;
    1807         partimagehack_fifo[0] = '\0';
     1806        use_ntfsprog_hack = FALSE;
     1807        ntfsprog_fifo[0] = '\0';
    18081808        file_to_openout = outfile_fname;
    18091809        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    18821882            pathname_of_last_file_restored);
    18831883
    1884     if (use_partimage_hack) {
    1885         log_msg(3, "Waiting for partimage to finish");
     1884    if (use_ntfsprog_hack) {
     1885        log_msg(3, "Waiting for ntfsclone to finish");
    18861886        sprintf(tmp,
    1887                 " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
     1887                " ps ax | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
    18881888        while (system(tmp) == 0) {
    18891889            sleep(1);
    18901890        }
    1891         log_msg(3, "OK, partimage has really finished");
     1891        log_msg(3, "OK, ntfsclone has really finished");
    18921892    }
    18931893
     
    19061906    paranoid_free(outfile_fname);
    19071907    paranoid_free(command);
    1908     paranoid_free(partimagehack_command);
     1908    paranoid_free(ntfsprog_command);
    19091909    paranoid_free(sz_devfile);
    1910     paranoid_free(partimagehack_fifo);
     1910    paranoid_free(ntfsprog_fifo);
    19111911    g_loglevel = old_loglevel;
    19121912    return (retval);
Note: See TracChangeset for help on using the changeset viewer.