+print_raid_data()
+{
+ eval $LOGFS
+ local device='' device_string='' device_state='' raid_level='' device_components=''
+ local device_report='' u_data='' blocks='' super_blocks='' algorithm='' chunk_size=''
+ local bitmap_values='' recovery_progress_bar='' recovery_percent='' recovered_sectors=''
+ local finish_time='' recovery_speed='' raid_counter=0 device_counter=1 basic_counter=1
+ local a_raid_working='' raid_data='' kernel_support='' read_ahead='' unused_devices=''
+ local basic_raid='' basic_raid_separator='' basic_raid_plural='' inactive=''
+ local component_separator='' device_id='' print_string='' loop_limit=0 array_count_unused=''
+ local array_count='' raid_event='' b_print_lines='true'
+ local no_raid_detected='' dev_string='/dev/'
+ local empty_raid_data='' report_size='report' blocks_avail='blocks' chunk_raid_usage='chunk size'
+
+ if [[ -n $BSD_TYPE ]];then
+ no_raid_detected='No zfs software RAID detected - other types not yet supported.'
+ empty_raid_data='No zfs RAID data available - other types not yet supported.'
+ report_size='full size'
+ blocks_avail='available size'
+ chunk_raid_usage='raid allocated'
+ else
+ no_raid_detected="No RAID data available - $FILE_MDSTAT is missing - is md_mod kernel module loaded?"
+ empty_raid_data="No RAID devices detected - $FILE_MDSTAT and md_mod kernel raid module present"
+ fi
+
+ if [[ $BSD_TYPE == 'bsd' ]];then
+ dev_string=''
+ fi
+ if [[ $B_RAID_SET != 'true' ]];then
+ get_raid_data
+ fi
+
+ for (( i=0; i < ${#A_RAID_DATA[@]}; i++ ))
+ do
+ IFS=","
+ a_raid_working=(${A_RAID_DATA[i]})
+ IFS="$ORIGINAL_IFS"
+
+ # reset on each iteration
+ algorithm=''
+ bitmap_values=''
+ blocks=''
+ component_separator=''
+ device=''
+ device_components=''
+ device_id=''
+ device_report=''
+ device_state=''
+ failed=''
+ finish_time=''
+ inactive=''
+ raid_event=''
+ raid_level=''
+ recovery_percent=''
+ recovery_progress_bar=''
+ recovered_sectors=''
+ recovery_speed=''
+ spare=''
+ super_blocks=''
+ u_data=''
+
+ if [[ -n $( grep '^md' <<< ${a_raid_working[0]} ) && -z $BSD_TYPE ]] || \
+ [[ -n $BSD_TYPE && ${a_raid_working[0]} != '' ]];then
+ if [[ $B_SHOW_BASIC_RAID == 'true' ]];then
+ if [[ $basic_raid != '' ]];then
+ basic_raid_plural='s'
+ fi
+ if [[ ${a_raid_working[1]} == 'inactive' ]];then
+ inactive=" - ${a_raid_working[1]}"
+ fi
+ basic_raid="$basic_raid$basic_raid_separator${C1}$basic_counter${SEP3}${C2} $dev_string${a_raid_working[0]}$inactive"
+ basic_raid_separator=' '
+ (( basic_counter++ ))
+ else
+ device_id="-$device_counter"
+ device="$dev_string${a_raid_working[0]}"
+
+ (( device_counter++ ))
+ if [[ ${a_raid_working[1]} != '' ]];then
+ device_state=" - ${a_raid_working[1]}"
+ fi
+
+ if [[ ${a_raid_working[2]} == '' ]];then
+ raid_level='N/A'
+ else
+ raid_level=${a_raid_working[2]}
+ fi
+ # there's one case: md0 : inactive that has to be protected against
+ if [[ ${a_raid_working[2]} == '' && ${a_raid_working[1]} == 'inactive' ]];then
+ raid_level=''
+ else
+ raid_level=" ${C1}raid${SEP3}${C2} $raid_level"
+ fi
+ if [[ ${a_raid_working[4]} != '' ]];then
+ device_report="${a_raid_working[4]}"
+ else
+ device_report="N/A"
+ fi
+ if [[ $B_EXTRA_DATA == 'true' ]];then
+ if [[ ${a_raid_working[6]} != '' ]];then
+ blocks=${a_raid_working[6]}
+ else
+ blocks='N/A'
+ fi
+ blocks=" ${C1}$blocks_avail${SEP3}${C2} $blocks"
+
+ if [[ ${a_raid_working[9]} != '' ]];then
+ chunk_size=${a_raid_working[9]}
+ else
+ chunk_size='N/A'
+ fi
+ chunk_size=" ${C1}$chunk_raid_usage${SEP3}${C2} $chunk_size"
+ if [[ ${a_raid_working[10]} != '' ]];then
+ bitmap_value='true'
+ bitmap_value=" ${C1}bitmap${SEP3}${C2} $bitmap_value"
+ fi
+ fi
+ if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
+ if [[ ${a_raid_working[5]} != '' ]];then
+ u_data=" ${a_raid_working[5]}"
+ fi
+ if [[ ${a_raid_working[7]} != '' ]];then
+ super_blocks=" ${C1}super blocks${SEP3}${C2} ${a_raid_working[7]}"
+ fi
+ if [[ ${a_raid_working[8]} != '' ]];then
+ algorithm=" ${C1}algorithm${SEP3}${C2} ${a_raid_working[8]}"
+ fi
+ fi
+ if [[ ${a_raid_working[3]} == '' ]];then
+ if [[ ${a_raid_working[1]} != 'inactive' ]];then
+ device_components='N/A'
+ fi
+ else
+ for component in ${a_raid_working[3]}
+ do
+ if [[ $B_EXTRA_DATA != 'true' ]];then
+ component=$( sed 's/\[[0-9]\+\]//' <<< $component )
+ fi
+ # NOTE: for bsd zfs, states are: ONLINE,DEGRADED,OFFLINE (at least)
+ if [[ -n $( grep -E '(F|DEGRADED)' <<< $component ) ]];then
+ component=$( sed -e 's/(F)//' -e 's/F//' -e 's/DEGRADED//' <<< $component )
+ failed="$failed $component"
+ component=''
+ elif [[ -n $( grep -E '(S|OFFLINE)' <<< $component ) ]];then
+ component=$( sed -e 's/(S)//' -e 's/S//' -e 's/OFFLINE//' <<< $component )
+ spare="$spare $component"
+ component=''
+ else
+ device_components="$device_components$component_separator$component"
+ component_separator=' '
+ fi
+ done
+
+ if [[ $failed != '' ]];then
+ failed=" ${C1}FAILED${SEP3}${C2}$failed${C2}"
+ fi
+ if [[ $spare != '' ]];then
+ spare=" ${C1}spare${SEP3}${C2}$spare${C2}"
+ fi
+
+ if [[ -n $device_components || -n $spare || -n $failed ]];then
+ if [[ $B_EXTRA_DATA != 'true' && -z $BSD_TYPE ]];then
+ if [[ $device_report != 'N/A' && -n $device_components ]];then
+ device_components="$device_report - $device_components"
+ fi
+ fi
+ if [[ $device_components == '' ]];then
+ device_components='none'
+ fi
+ device_components="${C1}online${SEP3}${C2} $device_components"
+ device_components=" ${C1}components${SEP3}${C2} $device_components$failed$spare"
+ fi
+ fi
+ a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$raid_level$device_components"
+
+ if [[ $B_EXTRA_DATA == 'true' && ${a_raid_working[1]} != 'inactive' ]];then
+ a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$device_components"
+ (( raid_counter++ ))
+ print_string="${C1}Info${SEP3}${C2}$raid_level ${C1}$report_size${SEP3}${C2} $device_report$u_data"
+ print_string="$print_string$blocks$chunk_size$bitmap_value$super_blocks$algorithm"
+ a_raid_data[$raid_counter]="$print_string"
+ else
+ a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$raid_level$device_components"
+ fi
+ (( raid_counter++ ))
+
+ # now let's do the recover line if required
+ if [[ ${a_raid_working[12]} != '' ]];then
+ recovery_percent=$( cut -d '~' -f 2 <<< ${a_raid_working[12]} )
+ if [[ ${a_raid_working[14]} != '' ]];then
+ finish_time=${a_raid_working[14]}
+ else
+ finish_time='N/A'
+ fi
+ finish_time=" ${C1}time remaining${SEP3}${C2} $finish_time"
+ if [[ $B_EXTRA_DATA == 'true' ]];then
+ if [[ ${a_raid_working[13]} != '' ]];then
+ recovered_sectors=" ${C1}sectors${SEP3}${C2} ${a_raid_working[13]}"
+ fi
+ fi
+ if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
+ if [[ ${a_raid_working[11]} != '' ]];then
+ recovery_progress_bar=" ${a_raid_working[11]}"
+ fi
+ if [[ ${a_raid_working[15]} != '' ]];then
+ recovery_speed=" ${C1}speed${SEP3}${C2} ${a_raid_working[15]}"
+ fi
+ fi
+
+ a_raid_data[$raid_counter]="${C1}Recovering${SEP3}${C2} $recovery_percent$recovery_progress_bar$recovered_sectors$finish_time$recovery_speed"
+ (( raid_counter++ ))
+ fi
+ fi
+ elif [[ ${a_raid_working[0]} == 'KernelRaidSupport' ]];then
+ if [[ ${a_raid_working[1]} == '' ]];then
+ kernel_support='N/A'
+ else
+ kernel_support=${a_raid_working[1]}
+ fi
+ kernel_support=" ${C1}supported${SEP3}${C2} $kernel_support"
+ elif [[ ${a_raid_working[0]} == 'ReadAhead' ]];then
+ if [[ ${a_raid_working[1]} != '' ]];then
+ read_ahead=${a_raid_working[1]}
+ read_ahead=" ${C1}read ahead${SEP3}${C2} $read_ahead"
+ fi
+ elif [[ ${a_raid_working[0]} == 'UnusedDevices' ]];then
+ if [[ ${a_raid_working[1]} == '' ]];then
+ unused_devices='N/A'
+ else
+ unused_devices=${a_raid_working[1]}
+ fi
+ unused_devices="${C1}Unused Devices${SEP3}${C2} $unused_devices"
+ elif [[ ${a_raid_working[0]} == 'raidEvent' ]];then
+ if [[ ${a_raid_working[1]} != '' ]];then
+ raid_event=${a_raid_working[1]}
+ raid_event=" ${C1}Raid Event${SEP3}${C2} ${a_raid_working[1]}"
+ fi
+ fi
+ done
+
+ if [[ $B_SHOW_BASIC_RAID == 'true' && $basic_raid != '' ]];then
+ a_raid_data[0]="${C1}Device$basic_raid_plural${SEP3}${C2} $basic_raid"
+ fi
+ # note bsd temp test hack to make it run
+ if [[ $B_MDSTAT_FILE != 'true' && -z $BSD_TYPE ]] || \
+ [[ -n $BSD_TYPE && $B_BSD_RAID == 'false' ]];then
+ if [[ $B_SHOW_RAID_R == 'true' ]];then
+ a_raid_data[0]="$no_raid_detected"
+ else
+ b_print_lines='false'
+ fi
+ else
+ if [[ ${a_raid_data[0]} == '' ]];then
+ if [[ $B_SHOW_BASIC_RAID != 'true' ]];then
+ a_raid_data[0]="$empty_raid_data"
+ else
+ b_print_lines='false'
+ fi
+ fi
+ # now let's add on the system line and the unused device line. Only print on -xx
+ if [[ $kernel_support$read_ahead$raid_event != '' ]];then
+ array_count=${#a_raid_data[@]}
+ a_raid_data[array_count]="${C1}System${SEP3}${C2}$kernel_support$read_ahead$raid_event"
+ loop_limit=1
+ fi
+ if [[ $unused_devices != '' ]];then
+ array_count_unused=${#a_raid_data[@]}
+ a_raid_data[array_count_unused]="$unused_devices"
+ loop_limit=2
+ fi
+ fi
+
+ # we don't want to print anything if it's -b and no data is present, just a waste of a line
+ if [[ $b_print_lines == 'true' ]];then
+ # print out all lines, line starter on first line
+ for (( i=0; i < ${#a_raid_data[@]} - $loop_limit;i++ ))
+ do
+ if [[ $i -eq 0 ]];then
+ line_starter='RAID:'
+ else
+ line_starter=' '
+ fi
+ if [[ $B_EXTRA_EXTRA_DATA == 'true' && $array_count != '' ]];then
+ if [[ $i == 0 ]];then
+ raid_data=$( create_print_line "$line_starter" "${a_raid_data[array_count]}" )
+ print_screen_output "$raid_data"
+ line_starter=' '
+ fi
+ fi
+ raid_data=$( create_print_line "$line_starter" "${a_raid_data[i]}" )
+ print_screen_output "$raid_data"
+ if [[ $B_EXTRA_EXTRA_DATA == 'true' && $array_count_unused != '' ]];then
+ if [[ $i == $(( array_count_unused - 2 )) ]];then
+ raid_data=$( create_print_line "$line_starter" "${a_raid_data[array_count_unused]}" )
+ print_screen_output "$raid_data"
+ fi
+ fi
+ done
+ fi
+
+ eval $LOGFE
+}