1*7323adacSDevin Teskeif [ ! "$_MEDIA_DOS_SUBR" ]; then _MEDIA_DOS_SUBR=1 2*7323adacSDevin Teske# 3*7323adacSDevin Teske# Copyright (c) 2012-2013 Devin Teske 4*7323adacSDevin Teske# All Rights Reserved. 5*7323adacSDevin Teske# 6*7323adacSDevin Teske# Redistribution and use in source and binary forms, with or without 7*7323adacSDevin Teske# modification, are permitted provided that the following conditions 8*7323adacSDevin Teske# are met: 9*7323adacSDevin Teske# 1. Redistributions of source code must retain the above copyright 10*7323adacSDevin Teske# notice, this list of conditions and the following disclaimer. 11*7323adacSDevin Teske# 2. Redistributions in binary form must reproduce the above copyright 12*7323adacSDevin Teske# notice, this list of conditions and the following disclaimer in the 13*7323adacSDevin Teske# documentation and/or other materials provided with the distribution. 14*7323adacSDevin Teske# 15*7323adacSDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*7323adacSDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 17*7323adacSDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*7323adacSDevin Teske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*7323adacSDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*7323adacSDevin Teske# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*7323adacSDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*7323adacSDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*7323adacSDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*7323adacSDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*7323adacSDevin Teske# SUCH DAMAGE. 26*7323adacSDevin Teske# 27*7323adacSDevin Teske# $FreeBSD$ 28*7323adacSDevin Teske# 29*7323adacSDevin Teske############################################################ INCLUDES 30*7323adacSDevin Teske 31*7323adacSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 32*7323adacSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 33*7323adacSDevin Teskef_dprintf "%s: loading includes..." media/dos.subr 34*7323adacSDevin Teskef_include $BSDCFG_SHARE/struct.subr 35*7323adacSDevin Teskef_include $BSDCFG_SHARE/device.subr 36*7323adacSDevin Teskef_include $BSDCFG_SHARE/dialog.subr 37*7323adacSDevin Teskef_include $BSDCFG_SHARE/variable.subr 38*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/common.subr 39*7323adacSDevin Teske 40*7323adacSDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig" 41*7323adacSDevin Teskef_include_lang $BSDCFG_LIBE/include/messages.subr 42*7323adacSDevin Teske 43*7323adacSDevin Teske############################################################ GLOBALS 44*7323adacSDevin Teske 45*7323adacSDevin TeskeDOS_MOUNTED= 46*7323adacSDevin Teske 47*7323adacSDevin Teske############################################################ FUNCTIONS 48*7323adacSDevin Teske 49*7323adacSDevin Teske# f_media_set_dos 50*7323adacSDevin Teske# 51*7323adacSDevin Teske# Return success if we both found and set the media type to be a DOS partition. 52*7323adacSDevin Teske# 53*7323adacSDevin Teskef_media_set_dos() 54*7323adacSDevin Teske{ 55*7323adacSDevin Teske f_media_close 56*7323adacSDevin Teske 57*7323adacSDevin Teske local devs ndevs 58*7323adacSDevin Teske f_device_find "" $DEVICE_TYPE_DOS devs 59*7323adacSDevin Teske ndevs=$( set -- $devs; echo $# ) 60*7323adacSDevin Teske 61*7323adacSDevin Teske if [ ${ndevs:=0} -eq 0 ]; then 62*7323adacSDevin Teske f_dialog_msgbox "$msg_no_dos_primary_partitions_found" 63*7323adacSDevin Teske return $FAILURE 64*7323adacSDevin Teske elif [ $ndevs -gt 1 ]; then 65*7323adacSDevin Teske local title="$msg_choose_a_dos_partition" 66*7323adacSDevin Teske local prompt="$msg_please_select_dos_partition" 67*7323adacSDevin Teske local hline="" 68*7323adacSDevin Teske 69*7323adacSDevin Teske local dev retval 70*7323adacSDevin Teske dev=$( f_device_menu \ 71*7323adacSDevin Teske "$title" "$prompt" "$hline" $DEVICE_TYPE_DOS \ 72*7323adacSDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) 73*7323adacSDevin Teske retval=$? 74*7323adacSDevin Teske [ "$dev" ] || return $FAILURE 75*7323adacSDevin Teske 76*7323adacSDevin Teske f_device_find "$dev" $DEVICE_TYPE_DOS devs 77*7323adacSDevin Teske [ "$devs" ] || return $FAILURE 78*7323adacSDevin Teske dev="${devs%%[$IFS]*}" 79*7323adacSDevin Teske 80*7323adacSDevin Teske f_struct_copy device_$dev device_media 81*7323adacSDevin Teske [ $retval -eq $SUCCESS ] || return $FAILURE 82*7323adacSDevin Teske else 83*7323adacSDevin Teske f_struct_copy device_$devs device_media 84*7323adacSDevin Teske fi 85*7323adacSDevin Teske 86*7323adacSDevin Teske f_struct device_media || return $FAILURE 87*7323adacSDevin Teske} 88*7323adacSDevin Teske 89*7323adacSDevin Teske# f_media_init_dos $device 90*7323adacSDevin Teske# 91*7323adacSDevin Teske# Initializes the DOS media device. Returns success if able to mount the DOS 92*7323adacSDevin Teske# partition device using mount_msdosfs(8). 93*7323adacSDevin Teske# 94*7323adacSDevin Teskef_media_init_dos() 95*7323adacSDevin Teske{ 96*7323adacSDevin Teske local dev="$1" devname err 97*7323adacSDevin Teske 98*7323adacSDevin Teske device_$dev get devname devname || return $FAILURE 99*7323adacSDevin Teske f_dprintf "Init routine called for DOS device. devname=[%s]" \ 100*7323adacSDevin Teske "$devname" 101*7323adacSDevin Teske 102*7323adacSDevin Teske if [ "$DOS_MOUNTED" ]; then 103*7323adacSDevin Teske f_dprintf "DOS device already mounted." 104*7323adacSDevin Teske return $SUCCESS 105*7323adacSDevin Teske fi 106*7323adacSDevin Teske 107*7323adacSDevin Teske if [ ! -e "$MOUNTPOINT" ] && 108*7323adacSDevin Teske ! err=$( mkdir -p "$MOUNTPOINT" 2>&1 ) 109*7323adacSDevin Teske then 110*7323adacSDevin Teske f_dialog_msgbox "$err" 111*7323adacSDevin Teske return $FAILURE 112*7323adacSDevin Teske fi 113*7323adacSDevin Teske 114*7323adacSDevin Teske if ! err=$( mount_msdosfs "$devname" "$MOUNTPOINT" 2>&1 ) 115*7323adacSDevin Teske then 116*7323adacSDevin Teske err="${err#mount_msdosfs: }"; err="${err#$devname: }" 117*7323adacSDevin Teske f_show_msg "$msg_error_mounting_device" \ 118*7323adacSDevin Teske "$devname" "$MOUNTPOINT" "$err" 119*7323adacSDevin Teske return $FAILURE 120*7323adacSDevin Teske fi 121*7323adacSDevin Teske DOS_MOUNTED=1 122*7323adacSDevin Teske return $SUCCESS 123*7323adacSDevin Teske} 124*7323adacSDevin Teske 125*7323adacSDevin Teske# f_media_get_dos $device $file [$probe_only] 126*7323adacSDevin Teske# 127*7323adacSDevin Teske# Returns data from $file on a mounted DOS partition device. Similar to cat(1). 128*7323adacSDevin Teske# $probe_only is currently unused by this media type. 129*7323adacSDevin Teske# 130*7323adacSDevin Teskef_media_get_dos() 131*7323adacSDevin Teske{ 132*7323adacSDevin Teske local dev="$1" file="$2" probe_only="$3" 133*7323adacSDevin Teske 134*7323adacSDevin Teske f_dprintf "f_media_get_dos: dev=[%s] file=[%s] probe_only=%s" \ 135*7323adacSDevin Teske "$dev" "$file" "$probe_only" 136*7323adacSDevin Teske 137*7323adacSDevin Teske f_media_generic_get "$MOUNTPOINT" "$file" 138*7323adacSDevin Teske} 139*7323adacSDevin Teske 140*7323adacSDevin Teske# f_media_shutdown_dos $device 141*7323adacSDevin Teske# 142*7323adacSDevin Teske# Shuts down the DOS partition device using umount(8). Return status should be 143*7323adacSDevin Teske# ignored. 144*7323adacSDevin Teske# 145*7323adacSDevin Teskef_media_shutdown_dos() 146*7323adacSDevin Teske{ 147*7323adacSDevin Teske local dev="$1" err 148*7323adacSDevin Teske 149*7323adacSDevin Teske [ "$DOS_MOUNTED" ] || return 150*7323adacSDevin Teske 151*7323adacSDevin Teske if ! err=$( umount -f "$MOUNTPOINT" 2>&1 ); then 152*7323adacSDevin Teske err="${err#umount: }"; err="${err#*: }" 153*7323adacSDevin Teske f_show_msg "$msg_could_not_unmount_the_dos_partition" \ 154*7323adacSDevin Teske "$MOUNTPOINT" "$err" 155*7323adacSDevin Teske else 156*7323adacSDevin Teske DOS_MOUNTED= 157*7323adacSDevin Teske fi 158*7323adacSDevin Teske} 159*7323adacSDevin Teske 160*7323adacSDevin Teske############################################################ MAIN 161*7323adacSDevin Teske 162*7323adacSDevin Teskef_dprintf "%s: Successfully loaded." media/dos.subr 163*7323adacSDevin Teske 164*7323adacSDevin Teskefi # ! $_MEDIA_DOS_SUBR 165