17323adacSDevin Teskeif [ ! "$_MEDIA_UFS_SUBR" ]; then _MEDIA_UFS_SUBR=1 27323adacSDevin Teske# 37323adacSDevin Teske# Copyright (c) 2012-2013 Devin Teske 4f8ea072aSDevin Teske# All rights reserved. 57323adacSDevin Teske# 67323adacSDevin Teske# Redistribution and use in source and binary forms, with or without 77323adacSDevin Teske# modification, are permitted provided that the following conditions 87323adacSDevin Teske# are met: 97323adacSDevin Teske# 1. Redistributions of source code must retain the above copyright 107323adacSDevin Teske# notice, this list of conditions and the following disclaimer. 117323adacSDevin Teske# 2. Redistributions in binary form must reproduce the above copyright 127323adacSDevin Teske# notice, this list of conditions and the following disclaimer in the 137323adacSDevin Teske# documentation and/or other materials provided with the distribution. 147323adacSDevin Teske# 157323adacSDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 168e37a7c8SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 177323adacSDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 187323adacSDevin Teske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 197323adacSDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 208e37a7c8SDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 217323adacSDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 227323adacSDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 237323adacSDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 247323adacSDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 257323adacSDevin Teske# SUCH DAMAGE. 267323adacSDevin Teske# 277323adacSDevin Teske# $FreeBSD$ 287323adacSDevin Teske# 297323adacSDevin Teske############################################################ INCLUDES 307323adacSDevin Teske 317323adacSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 327323adacSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 337323adacSDevin Teskef_dprintf "%s: loading includes..." media/ufs.subr 347323adacSDevin Teskef_include $BSDCFG_SHARE/device.subr 357323adacSDevin Teskef_include $BSDCFG_SHARE/dialog.subr 367323adacSDevin Teskef_include $BSDCFG_SHARE/media/common.subr 371de60ff0SDevin Teskef_include $BSDCFG_SHARE/struct.subr 381de60ff0SDevin Teskef_include $BSDCFG_SHARE/variable.subr 397323adacSDevin Teske 407323adacSDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig" 417323adacSDevin Teskef_include_lang $BSDCFG_LIBE/include/messages.subr 427323adacSDevin Teske 437323adacSDevin Teske############################################################ GLOBALS 447323adacSDevin Teske 457323adacSDevin TeskeUFS_MOUNTED= 467323adacSDevin Teske 477323adacSDevin Teske############################################################ FUNCTIONS 487323adacSDevin Teske 497323adacSDevin Teske# f_media_set_ufs 507323adacSDevin Teske# 517323adacSDevin Teske# Return success if we both found and set the media type to be a UFS partition. 527323adacSDevin Teske# Variables from variable.subr that can be used to script user input: 537323adacSDevin Teske# 547323adacSDevin Teske# VAR_UFS_PATH 557323adacSDevin Teske# Path to a UFS character device node to be used with mount(8) in 567323adacSDevin Teske# mounting a UFS formatted partition. Valid examples include: 577323adacSDevin Teske# /dev/da0s1a 587323adacSDevin Teske# /dev/ad4s1e 597323adacSDevin Teske# However, other forms may be valid (see mount(8) for additional 607323adacSDevin Teske# information). 617323adacSDevin Teske# 627323adacSDevin Teskef_media_set_ufs() 637323adacSDevin Teske{ 647323adacSDevin Teske local ufs 657323adacSDevin Teske 667323adacSDevin Teske f_media_close 677323adacSDevin Teske 687323adacSDevin Teske local devs ndevs 697323adacSDevin Teske f_device_find "" $DEVICE_TYPE_UFS devs 707323adacSDevin Teske ndevs=$( set -- $devs; echo $# ) 717323adacSDevin Teske 727323adacSDevin Teske if [ ${ndevs:=0} -eq 0 ]; then 737323adacSDevin Teske f_variable_get_value $VAR_UFS_PATH \ 747323adacSDevin Teske "$msg_enter_the_device_name_of_a_ufs_formatted_partition" 757323adacSDevin Teske f_getvar $VAR_UFS_PATH ufs 767323adacSDevin Teske [ "$ufs" ] || return $FAILURE 777323adacSDevin Teske 787323adacSDevin Teske local fstype 797323adacSDevin Teske fstype=$( df -nT $ufs 2> /dev/null | 807323adacSDevin Teske awk '!/Type/{print $2;exit}' ) 817323adacSDevin Teske 827323adacSDevin Teske f_struct_new DEVICE device_ufs 837323adacSDevin Teske device_ufs set name ${fstype:-ufs} 847323adacSDevin Teske device_ufs set devname "$ufs" 857323adacSDevin Teske device_ufs set get f_media_get_ufs 867323adacSDevin Teske device_ufs set init f_media_init_ufs 877323adacSDevin Teske device_ufs set shutdown f_media_shutdown_ufs 887323adacSDevin Teske device_ufs unset private 897323adacSDevin Teske 907323adacSDevin Teske f_struct_copy device_ufs device_media 917323adacSDevin Teske f_struct_free device_ufs 927323adacSDevin Teske elif [ $ndevs -gt 1 ]; then 937323adacSDevin Teske local title="$msg_choose_a_ufs_partition" 947323adacSDevin Teske local prompt="$msg_please_select_ufs_partition" 957323adacSDevin Teske local hline="" 967323adacSDevin Teske 977323adacSDevin Teske local dev retval 987323adacSDevin Teske dev=$( f_device_menu \ 997323adacSDevin Teske "$title" "$prompt" "$hline" $DEVICE_TYPE_UFS \ 1007323adacSDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) 1017323adacSDevin Teske retval=$? 1027323adacSDevin Teske [ "$dev" ] || return $FAILURE 1037323adacSDevin Teske 1047323adacSDevin Teske f_struct_copy device_$dev device_media 1057323adacSDevin Teske [ $retval -eq $SUCCESS ] || return $FAILURE 1067323adacSDevin Teske else 1077323adacSDevin Teske f_struct_copy device_$devs device_media 1087323adacSDevin Teske fi 1097323adacSDevin Teske 1107323adacSDevin Teske f_struct device_media || return $FAILURE 1117323adacSDevin Teske} 1127323adacSDevin Teske 1137323adacSDevin Teske# f_media_init_ufs $device 1147323adacSDevin Teske# 1157323adacSDevin Teske# Initializes the UFS media device. Returns success if able to mount the UFS 1167323adacSDevin Teske# partition device using mount(1). 1177323adacSDevin Teske# 1187323adacSDevin Teskef_media_init_ufs() 1197323adacSDevin Teske{ 1207323adacSDevin Teske local dev="$1" devname err 1217323adacSDevin Teske 1227323adacSDevin Teske device_$dev get devname devname || return $FAILURE 1237323adacSDevin Teske f_dprintf "Init routine called for UFS device. devname=[%s]" \ 1247323adacSDevin Teske "$devname" 1257323adacSDevin Teske 1267323adacSDevin Teske if [ "$UFS_MOUNTED" ]; then 1277323adacSDevin Teske f_dprintf "UFS device already mounted." 1287323adacSDevin Teske return $SUCCESS 1297323adacSDevin Teske fi 1307323adacSDevin Teske 1317323adacSDevin Teske if [ ! -e "$devname" ]; then 1327323adacSDevin Teske f_show_msg "$msg_no_such_file_or_directory" \ 1337323adacSDevin Teske "f_media_init_ufs" "$devname" 1347323adacSDevin Teske return $FAILURE 1357323adacSDevin Teske fi 1367323adacSDevin Teske 1377323adacSDevin Teske if [ ! -e "$MOUNTPOINT" ] && 1387323adacSDevin Teske ! err=$( mkdir -p "$MOUNTPOINT" 2>&1 ) 1397323adacSDevin Teske then 1407323adacSDevin Teske f_dialog_msgbox "$err" 1417323adacSDevin Teske return $FAILURE 1427323adacSDevin Teske fi 1437323adacSDevin Teske 1447323adacSDevin Teske if ! err=$( mount "$devname" "$MOUNTPOINT" 2>&1 ) 1457323adacSDevin Teske then 1467323adacSDevin Teske err="${err#mount: }"; err="${err#$devname : }" 1477323adacSDevin Teske f_show_msg "$msg_error_mounting_device" \ 1487323adacSDevin Teske "$devname" "$MOUNTPOINT" "$err" 1497323adacSDevin Teske return $FAILURE 1507323adacSDevin Teske fi 1517323adacSDevin Teske UFS_MOUNTED=1 1527323adacSDevin Teske return $SUCCESS 1537323adacSDevin Teske} 1547323adacSDevin Teske 155*dde7be41SDevin Teske# f_media_get_ufs $device $file [$probe_type] 1567323adacSDevin Teske# 1577323adacSDevin Teske# Returns data from $file on a mounted UFS partition device. Similar to cat(1). 158*dde7be41SDevin Teske# If $probe_type is present and non-NULL, returns success if $file exists. If 159*dde7be41SDevin Teske# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to 160*dde7be41SDevin Teske# standard-out. 1617323adacSDevin Teske# 1627323adacSDevin Teskef_media_get_ufs() 1637323adacSDevin Teske{ 164*dde7be41SDevin Teske local dev="$1" file="$2" probe_type="$3" 1657323adacSDevin Teske 166*dde7be41SDevin Teske f_dprintf "f_media_get_ufs: dev=[%s] file=[%s] probe_type=%s" \ 167*dde7be41SDevin Teske "$dev" "$file" "$probe_type" 1687323adacSDevin Teske 169*dde7be41SDevin Teske f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type" 1707323adacSDevin Teske} 1717323adacSDevin Teske 1727323adacSDevin Teske# f_media_shutdown_ufs $device 1737323adacSDevin Teske# 1747323adacSDevin Teske# Shuts down the UFS device using umount(8). Return status should be ignored. 1757323adacSDevin Teske# 1767323adacSDevin Teskef_media_shutdown_ufs() 1777323adacSDevin Teske{ 1787323adacSDevin Teske local dev="$1" err 1797323adacSDevin Teske 1807323adacSDevin Teske [ "$UFS_MOUNTED" ] || return 1817323adacSDevin Teske 1827323adacSDevin Teske if ! err=$( umount -f "$MOUNTPOINT" 2>&1 ); then 1837323adacSDevin Teske err="${err#umount: }"; err="${err#*: }" 1847323adacSDevin Teske f_show_msg "$msg_could_not_unmount_the_ufs_partition" \ 1857323adacSDevin Teske "$MOUNTPOINT" "$err" 1867323adacSDevin Teske else 1877323adacSDevin Teske UFS_MOUNTED= 1887323adacSDevin Teske fi 1897323adacSDevin Teske} 1907323adacSDevin Teske 1917323adacSDevin Teske############################################################ MAIN 1927323adacSDevin Teske 1937323adacSDevin Teskef_dprintf "%s: Successfully loaded." media/ufs.subr 1947323adacSDevin Teske 1957323adacSDevin Teskefi # ! $_MEDIA_UFS_SUBR 196