1if [ ! "$_MEDIA_FLOPPY_SUBR" ]; then _MEDIA_FLOPPY_SUBR=1 2# 3# Copyright (c) 2012-2013 Devin Teske 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# |
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/floppy.subr 264840 2014-04-23 22:04:04Z dteske $ |
28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." media/floppy.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/dialog.subr --- 21 unchanged lines hidden (view full) --- 57 58 local devs ndevs 59 f_device_find "" $DEVICE_TYPE_FLOPPY devs 60 f_count ndevs $devs 61 62 if [ ${ndevs:=0} -eq 0 ]; then 63 f_interactive && f_show_msg "$msg_no_floppy_devices_found" 64 return $FAILURE |
65 elif [ $ndevs -eq 1 ]; then 66 f_struct_copy $devs device_media 67 else 68 local dev |
69 local title="$msg_choose_a_floppy_drive" 70 local prompt="$msg_please_select_a_floppy_drive" |
71 local hline= |
72 |
73 dev=$( f_device_menu \ 74 "$title" "$prompt" "$hline" $DEVICE_TYPE_FLOPPY \ |
75 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) || 76 return $FAILURE |
77 |
78 f_struct_copy "$dev" device_media |
79 fi 80 81 f_struct device_media && 82 device_media unset private 83 84 f_struct device_media || return $FAILURE 85} 86 87# f_media_init_floppy $device 88# 89# Initializes the Floppy media device. Returns success if able to mount the 90# Floppy disk device using either mount_msdosfs(8) or mount(8) (tried in that 91# order). 92# 93f_media_init_floppy() 94{ 95 local funcname=f_media_init_floppy 96 local dev="$1" devname err 97 |
98 $dev get devname devname || return $FAILURE |
99 f_dprintf "Init floppy called for %s distribution. devname=[%s]" \ 100 "${FLOPPY_DISTWANTED:-some}" "$devname" 101 102 if [ "$FLOPPY_MOUNTED" ]; then 103 f_dprintf "Floppy device already mounted." 104 return $SUCCESS 105 fi 106 107 local mp |
108 $dev get private mp |
109 if [ ! -e "${mp:=$MOUNTPOINT}" ] && ! f_quietly mkdir -p "$mp"; then 110 f_show_msg "$msg_unable_to_make_directory_mountpoint" \ 111 "$mp" "$devname" 112 return $FAILURE 113 fi 114 115 if f_interactive; then 116 local desc |
117 $dev get desc desc |
118 if [ "$FLOPPY_DISTWANTED" ]; then 119 f_show_msg "$msg_please_insert_floppy_in_drive" "$desc" 120 else 121 f_show_msg "$msg_please_insert_floppy_containing" \ 122 "$FLOPPY_DISTWANTED" "$desc" 123 fi 124 fi 125 126 if ! { 127 f_eval_catch -dk err $funcname mount_msdosfs \ 128 'mount_msdosfs -o ro -m 0777 -u 0 -g 0 "%s" "%s"' \ 129 "$devname" "$mp" || 130 f_eval_catch -dk err $funcname mount \ 131 'mount -o ro "%s" "%s"' "$devname" "$mp" 132 }; then 133 err="${err#mount: }"; err="${err#*: }" 134 local name |
135 $dev get name name |
136 f_show_msg "$msg_error_mounting_floppy_device" \ 137 "$name" "$devname" "$mp" "$err" 138 return $FAILURE 139 fi 140 FLOPPY_MOUNTED=1 141 FLOPPY_DISTWANTED= 142 return $SUCCESS 143} --- 4 unchanged lines hidden (view full) --- 148# If $probe_type is present and non-NULL, limits retries to zero and returns 149# success if $file exists. If $probe_type is equal to $PROBE_SIZE, prints the 150# size of $file in bytes to standard-out. 151# 152f_media_get_floppy() 153{ 154 local funcname=f_media_get_floppy 155 local dev="$1" file="$2" probe_type="$3" |
156 local name |
157 |
158 $dev get name name |
159 f_dprintf "f_media_get_floppy: dev=[%s] file=[%s] probe_type=%s" \ |
160 "$name" "$file" "$probe_type" |
161 162 # 163 # floppies don't use f_media_generic_get() because it's too expensive 164 # to speculatively open files on a floppy disk. Make user get it 165 # right or give up with floppies. 166 # 167 local mp |
168 $dev get private mp |
169 local fp="${mp:=$MOUNTPOINT}/$file" 170 if ! [ -f "$fp" -a -r "$fp" ]; then 171 local nretries=4 172 [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1" 173 [ "$probe_type" ] && return $FAILURE 174 while ! [ -f "$fp" -a -r "$fp" ]; do 175 if [ $nretries -eq 0 ]; then 176 f_show_msg "$msg_failed_to_get_floppy_file" \ --- 27 unchanged lines hidden (view full) --- 204# 205f_media_shutdown_floppy() 206{ 207 local funcname=f_media_shutdown_floppy 208 local dev="$1" err mp 209 210 [ "$FLOPPY_MOUNTED" ] || return $FAILURE 211 |
212 $dev get private mp |
213 if f_eval_catch -d $funcname umount \ 214 'umount -f "%s"' "${mp:=$MOUNTPOINT}" 215 then 216 FLOPPY_MOUNTED= 217 if f_interactive && [ "$_systemState" != "fixit" ]; then 218 local desc |
219 $dev get desc desc |
220 f_show_msg "$msg_you_may_remove_the_floppy" "$desc" 221 fi 222 fi 223} 224 225############################################################ MAIN 226 227f_dprintf "%s: Successfully loaded." media/floppy.subr 228 229fi # ! $_MEDIA_FLOPPY_SUBR |