17323adacSDevin Teskeif [ ! "$_MEDIA_DOS_SUBR" ]; then _MEDIA_DOS_SUBR=1 27323adacSDevin Teske# 37323adacSDevin Teske# Copyright (c) 2012-2013 Devin Teske 4*f8ea072aSDevin 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 167323adacSDevin 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 207323adacSDevin Teske# DAMAGES (INLUDING, 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/dos.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 TeskeDOS_MOUNTED= 467323adacSDevin Teske 477323adacSDevin Teske############################################################ FUNCTIONS 487323adacSDevin Teske 497323adacSDevin Teske# f_media_set_dos 507323adacSDevin Teske# 517323adacSDevin Teske# Return success if we both found and set the media type to be a DOS partition. 527323adacSDevin Teske# 537323adacSDevin Teskef_media_set_dos() 547323adacSDevin Teske{ 557323adacSDevin Teske f_media_close 567323adacSDevin Teske 577323adacSDevin Teske local devs ndevs 587323adacSDevin Teske f_device_find "" $DEVICE_TYPE_DOS devs 597323adacSDevin Teske ndevs=$( set -- $devs; echo $# ) 607323adacSDevin Teske 617323adacSDevin Teske if [ ${ndevs:=0} -eq 0 ]; then 627079fc4eSDevin Teske f_show_msg "$msg_no_dos_primary_partitions_found" 637323adacSDevin Teske return $FAILURE 647323adacSDevin Teske elif [ $ndevs -gt 1 ]; then 657323adacSDevin Teske local title="$msg_choose_a_dos_partition" 667323adacSDevin Teske local prompt="$msg_please_select_dos_partition" 677323adacSDevin Teske local hline="" 687323adacSDevin Teske 697323adacSDevin Teske local dev retval 707323adacSDevin Teske dev=$( f_device_menu \ 717323adacSDevin Teske "$title" "$prompt" "$hline" $DEVICE_TYPE_DOS \ 727323adacSDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) 737323adacSDevin Teske retval=$? 747323adacSDevin Teske [ "$dev" ] || return $FAILURE 757323adacSDevin Teske 767323adacSDevin Teske f_device_find "$dev" $DEVICE_TYPE_DOS devs 777323adacSDevin Teske [ "$devs" ] || return $FAILURE 787323adacSDevin Teske dev="${devs%%[$IFS]*}" 797323adacSDevin Teske 807323adacSDevin Teske f_struct_copy device_$dev device_media 817323adacSDevin Teske [ $retval -eq $SUCCESS ] || return $FAILURE 827323adacSDevin Teske else 837323adacSDevin Teske f_struct_copy device_$devs device_media 847323adacSDevin Teske fi 857323adacSDevin Teske 867323adacSDevin Teske f_struct device_media || return $FAILURE 877323adacSDevin Teske} 887323adacSDevin Teske 897323adacSDevin Teske# f_media_init_dos $device 907323adacSDevin Teske# 917323adacSDevin Teske# Initializes the DOS media device. Returns success if able to mount the DOS 927323adacSDevin Teske# partition device using mount_msdosfs(8). 937323adacSDevin Teske# 947323adacSDevin Teskef_media_init_dos() 957323adacSDevin Teske{ 967323adacSDevin Teske local dev="$1" devname err 977323adacSDevin Teske 987323adacSDevin Teske device_$dev get devname devname || return $FAILURE 997323adacSDevin Teske f_dprintf "Init routine called for DOS device. devname=[%s]" \ 1007323adacSDevin Teske "$devname" 1017323adacSDevin Teske 1027323adacSDevin Teske if [ "$DOS_MOUNTED" ]; then 1037323adacSDevin Teske f_dprintf "DOS device already mounted." 1047323adacSDevin Teske return $SUCCESS 1057323adacSDevin Teske fi 1067323adacSDevin Teske 1077323adacSDevin Teske if [ ! -e "$MOUNTPOINT" ] && 1087323adacSDevin Teske ! err=$( mkdir -p "$MOUNTPOINT" 2>&1 ) 1097323adacSDevin Teske then 1107323adacSDevin Teske f_dialog_msgbox "$err" 1117323adacSDevin Teske return $FAILURE 1127323adacSDevin Teske fi 1137323adacSDevin Teske 1147323adacSDevin Teske if ! err=$( mount_msdosfs "$devname" "$MOUNTPOINT" 2>&1 ) 1157323adacSDevin Teske then 1167323adacSDevin Teske err="${err#mount_msdosfs: }"; err="${err#$devname: }" 1177323adacSDevin Teske f_show_msg "$msg_error_mounting_device" \ 1187323adacSDevin Teske "$devname" "$MOUNTPOINT" "$err" 1197323adacSDevin Teske return $FAILURE 1207323adacSDevin Teske fi 1217323adacSDevin Teske DOS_MOUNTED=1 1227323adacSDevin Teske return $SUCCESS 1237323adacSDevin Teske} 1247323adacSDevin Teske 1257323adacSDevin Teske# f_media_get_dos $device $file [$probe_only] 1267323adacSDevin Teske# 1277323adacSDevin Teske# Returns data from $file on a mounted DOS partition device. Similar to cat(1). 128424d0badSDevin Teske# If $probe_only is present and non-NULL, returns success if $file exists. 1297323adacSDevin Teske# 1307323adacSDevin Teskef_media_get_dos() 1317323adacSDevin Teske{ 1327323adacSDevin Teske local dev="$1" file="$2" probe_only="$3" 1337323adacSDevin Teske 1347323adacSDevin Teske f_dprintf "f_media_get_dos: dev=[%s] file=[%s] probe_only=%s" \ 1357323adacSDevin Teske "$dev" "$file" "$probe_only" 1367323adacSDevin Teske 137424d0badSDevin Teske f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only" 1387323adacSDevin Teske} 1397323adacSDevin Teske 1407323adacSDevin Teske# f_media_shutdown_dos $device 1417323adacSDevin Teske# 1427323adacSDevin Teske# Shuts down the DOS partition device using umount(8). Return status should be 1437323adacSDevin Teske# ignored. 1447323adacSDevin Teske# 1457323adacSDevin Teskef_media_shutdown_dos() 1467323adacSDevin Teske{ 1477323adacSDevin Teske local dev="$1" err 1487323adacSDevin Teske 1497323adacSDevin Teske [ "$DOS_MOUNTED" ] || return 1507323adacSDevin Teske 1517323adacSDevin Teske if ! err=$( umount -f "$MOUNTPOINT" 2>&1 ); then 1527323adacSDevin Teske err="${err#umount: }"; err="${err#*: }" 1537323adacSDevin Teske f_show_msg "$msg_could_not_unmount_the_dos_partition" \ 1547323adacSDevin Teske "$MOUNTPOINT" "$err" 1557323adacSDevin Teske else 1567323adacSDevin Teske DOS_MOUNTED= 1577323adacSDevin Teske fi 1587323adacSDevin Teske} 1597323adacSDevin Teske 1607323adacSDevin Teske############################################################ MAIN 1617323adacSDevin Teske 1627323adacSDevin Teskef_dprintf "%s: Successfully loaded." media/dos.subr 1637323adacSDevin Teske 1647323adacSDevin Teskefi # ! $_MEDIA_DOS_SUBR 165