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 259054 2013-12-07 00:31:01Z 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 -gt 1 ]; then
66 local title="$msg_choose_a_floppy_drive"
67 local prompt="$msg_please_select_a_floppy_drive"
68 local hline=""
69
70 local dev retval
71 dev=$( f_device_menu \
72 "$title" "$prompt" "$hline" $DEVICE_TYPE_FLOPPY \
73 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD )
74 retval=$?
75 [ "$dev" ] || return $FAILURE
76
77 f_device_find "$dev" $DEVICE_TYPE_FLOPPY devs
78 [ "$devs" ] || return $FAILURE
79 dev="${devs%%[$IFS]*}"
80
81 f_struct_copy device_$dev device_media
82 [ $retval -eq $SUCCESS ] || return $FAILURE
83 else
84 f_struct_copy device_$devs device_media
85 fi
86
87 f_struct device_media &&
88 device_media unset private
89
90 f_struct device_media || return $FAILURE
91}
92
93# f_media_init_floppy $device
94#
95# Initializes the Floppy media device. Returns success if able to mount the
96# Floppy disk device using either mount_msdosfs(8) or mount(8) (tried in that
97# order).
98#
99f_media_init_floppy()
100{
101 local funcname=f_media_init_floppy
102 local dev="$1" devname err
103
104 device_$dev get devname devname || return $FAILURE
105 f_dprintf "Init floppy called for %s distribution. devname=[%s]" \
106 "${FLOPPY_DISTWANTED:-some}" "$devname"
107
108 if [ "$FLOPPY_MOUNTED" ]; then
109 f_dprintf "Floppy device already mounted."
110 return $SUCCESS
111 fi
112
113 local mp
114 device_$dev get private mp
115 if [ ! -e "${mp:=$MOUNTPOINT}" ] && ! f_quietly mkdir -p "$mp"; then
116 f_show_msg "$msg_unable_to_make_directory_mountpoint" \
117 "$mp" "$devname"
118 return $FAILURE
119 fi
120
121 if f_interactive; then
122 local desc
123 device_$dev get desc desc
124 if [ "$FLOPPY_DISTWANTED" ]; then
125 f_show_msg "$msg_please_insert_floppy_in_drive" "$desc"
126 else
127 f_show_msg "$msg_please_insert_floppy_containing" \
128 "$FLOPPY_DISTWANTED" "$desc"
129 fi
130 fi
131
132 if ! {
133 f_eval_catch -dk err $funcname mount_msdosfs \
134 'mount_msdosfs -o ro -m 0777 -u 0 -g 0 "%s" "%s"' \
135 "$devname" "$mp" ||
136 f_eval_catch -dk err $funcname mount \
137 'mount -o ro "%s" "%s"' "$devname" "$mp"
138 }; then
139 err="${err#mount: }"; err="${err#*: }"
140 local name
141 device_$dev get name name
142 f_show_msg "$msg_error_mounting_floppy_device" \
143 "$name" "$devname" "$mp" "$err"
144 return $FAILURE
145 fi
146 FLOPPY_MOUNTED=1
147 FLOPPY_DISTWANTED=
148 return $SUCCESS
149}
--- 4 unchanged lines hidden (view full) ---
154# If $probe_type is present and non-NULL, limits retries to zero and returns
155# success if $file exists. If $probe_type is equal to $PROBE_SIZE, prints the
156# size of $file in bytes to standard-out.
157#
158f_media_get_floppy()
159{
160 local funcname=f_media_get_floppy
161 local dev="$1" file="$2" probe_type="$3"
162
163 f_dprintf "f_media_get_floppy: dev=[%s] file=[%s] probe_type=%s" \
164 "$dev" "$file" "$probe_type"
165
166 #
167 # floppies don't use f_media_generic_get() because it's too expensive
168 # to speculatively open files on a floppy disk. Make user get it
169 # right or give up with floppies.
170 #
171 local mp
172 device_$dev get private mp
173 local fp="${mp:=$MOUNTPOINT}/$file"
174 if ! [ -f "$fp" -a -r "$fp" ]; then
175 local nretries=4
176 [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1"
177 [ "$probe_type" ] && return $FAILURE
178 while ! [ -f "$fp" -a -r "$fp" ]; do
179 if [ $nretries -eq 0 ]; then
180 f_show_msg "$msg_failed_to_get_floppy_file" \
--- 27 unchanged lines hidden (view full) ---
208#
209f_media_shutdown_floppy()
210{
211 local funcname=f_media_shutdown_floppy
212 local dev="$1" err mp
213
214 [ "$FLOPPY_MOUNTED" ] || return $FAILURE
215
216 device_$dev get private mp
217 if f_eval_catch -d $funcname umount \
218 'umount -f "%s"' "${mp:=$MOUNTPOINT}"
219 then
220 FLOPPY_MOUNTED=
221 if f_interactive && [ "$_systemState" != "fixit" ]; then
222 local desc
223 device_$dev get desc desc
224 f_show_msg "$msg_you_may_remove_the_floppy" "$desc"
225 fi
226 fi
227}
228
229############################################################ MAIN
230
231f_dprintf "%s: Successfully loaded." media/floppy.subr
232
233fi # ! $_MEDIA_FLOPPY_SUBR
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 259054 2013-12-07 00:31:01Z 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 -gt 1 ]; then
66 local title="$msg_choose_a_floppy_drive"
67 local prompt="$msg_please_select_a_floppy_drive"
68 local hline=""
69
70 local dev retval
71 dev=$( f_device_menu \
72 "$title" "$prompt" "$hline" $DEVICE_TYPE_FLOPPY \
73 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD )
74 retval=$?
75 [ "$dev" ] || return $FAILURE
76
77 f_device_find "$dev" $DEVICE_TYPE_FLOPPY devs
78 [ "$devs" ] || return $FAILURE
79 dev="${devs%%[$IFS]*}"
80
81 f_struct_copy device_$dev device_media
82 [ $retval -eq $SUCCESS ] || return $FAILURE
83 else
84 f_struct_copy device_$devs device_media
85 fi
86
87 f_struct device_media &&
88 device_media unset private
89
90 f_struct device_media || return $FAILURE
91}
92
93# f_media_init_floppy $device
94#
95# Initializes the Floppy media device. Returns success if able to mount the
96# Floppy disk device using either mount_msdosfs(8) or mount(8) (tried in that
97# order).
98#
99f_media_init_floppy()
100{
101 local funcname=f_media_init_floppy
102 local dev="$1" devname err
103
104 device_$dev get devname devname || return $FAILURE
105 f_dprintf "Init floppy called for %s distribution. devname=[%s]" \
106 "${FLOPPY_DISTWANTED:-some}" "$devname"
107
108 if [ "$FLOPPY_MOUNTED" ]; then
109 f_dprintf "Floppy device already mounted."
110 return $SUCCESS
111 fi
112
113 local mp
114 device_$dev get private mp
115 if [ ! -e "${mp:=$MOUNTPOINT}" ] && ! f_quietly mkdir -p "$mp"; then
116 f_show_msg "$msg_unable_to_make_directory_mountpoint" \
117 "$mp" "$devname"
118 return $FAILURE
119 fi
120
121 if f_interactive; then
122 local desc
123 device_$dev get desc desc
124 if [ "$FLOPPY_DISTWANTED" ]; then
125 f_show_msg "$msg_please_insert_floppy_in_drive" "$desc"
126 else
127 f_show_msg "$msg_please_insert_floppy_containing" \
128 "$FLOPPY_DISTWANTED" "$desc"
129 fi
130 fi
131
132 if ! {
133 f_eval_catch -dk err $funcname mount_msdosfs \
134 'mount_msdosfs -o ro -m 0777 -u 0 -g 0 "%s" "%s"' \
135 "$devname" "$mp" ||
136 f_eval_catch -dk err $funcname mount \
137 'mount -o ro "%s" "%s"' "$devname" "$mp"
138 }; then
139 err="${err#mount: }"; err="${err#*: }"
140 local name
141 device_$dev get name name
142 f_show_msg "$msg_error_mounting_floppy_device" \
143 "$name" "$devname" "$mp" "$err"
144 return $FAILURE
145 fi
146 FLOPPY_MOUNTED=1
147 FLOPPY_DISTWANTED=
148 return $SUCCESS
149}
--- 4 unchanged lines hidden (view full) ---
154# If $probe_type is present and non-NULL, limits retries to zero and returns
155# success if $file exists. If $probe_type is equal to $PROBE_SIZE, prints the
156# size of $file in bytes to standard-out.
157#
158f_media_get_floppy()
159{
160 local funcname=f_media_get_floppy
161 local dev="$1" file="$2" probe_type="$3"
162
163 f_dprintf "f_media_get_floppy: dev=[%s] file=[%s] probe_type=%s" \
164 "$dev" "$file" "$probe_type"
165
166 #
167 # floppies don't use f_media_generic_get() because it's too expensive
168 # to speculatively open files on a floppy disk. Make user get it
169 # right or give up with floppies.
170 #
171 local mp
172 device_$dev get private mp
173 local fp="${mp:=$MOUNTPOINT}/$file"
174 if ! [ -f "$fp" -a -r "$fp" ]; then
175 local nretries=4
176 [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1"
177 [ "$probe_type" ] && return $FAILURE
178 while ! [ -f "$fp" -a -r "$fp" ]; do
179 if [ $nretries -eq 0 ]; then
180 f_show_msg "$msg_failed_to_get_floppy_file" \
--- 27 unchanged lines hidden (view full) ---
208#
209f_media_shutdown_floppy()
210{
211 local funcname=f_media_shutdown_floppy
212 local dev="$1" err mp
213
214 [ "$FLOPPY_MOUNTED" ] || return $FAILURE
215
216 device_$dev get private mp
217 if f_eval_catch -d $funcname umount \
218 'umount -f "%s"' "${mp:=$MOUNTPOINT}"
219 then
220 FLOPPY_MOUNTED=
221 if f_interactive && [ "$_systemState" != "fixit" ]; then
222 local desc
223 device_$dev get desc desc
224 f_show_msg "$msg_you_may_remove_the_floppy" "$desc"
225 fi
226 fi
227}
228
229############################################################ MAIN
230
231f_dprintf "%s: Successfully loaded." media/floppy.subr
232
233fi # ! $_MEDIA_FLOPPY_SUBR