1 if [ ! "$_MEDIA_CDROM_SUBR" ]; then _MEDIA_CDROM_SUBR=1
3 # Copyright (c) 2012-2013 Devin Teske
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
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
29 ############################################################ INCLUDES
31 BSDCFG_SHARE="/usr/share/bsdconfig"
32 . $BSDCFG_SHARE/common.subr || exit 1
33 f_dprintf "%s: loading includes..." media/cdrom.subr
34 f_include $BSDCFG_SHARE/device.subr
35 f_include $BSDCFG_SHARE/dialog.subr
36 f_include $BSDCFG_SHARE/media/common.subr
37 f_include $BSDCFG_SHARE/struct.subr
38 f_include $BSDCFG_SHARE/variable.subr
40 BSDCFG_LIBE="/usr/libexec/bsdconfig"
41 f_include_lang $BSDCFG_LIBE/include/messages.subr
43 ############################################################ GLOBALS
46 CDROM_PREVIOUSLY_MOUNTED=
49 ############################################################ FUNCTIONS
53 # Return success if we both found and set the media type to be a CD.
60 f_device_find "" $DEVICE_TYPE_CDROM devs
63 if [ ${ndevs:=0} -eq 0 ]; then
64 f_interactive && f_show_msg "$msg_no_cd_dvd_devices_found"
66 elif [ $ndevs -eq 1 ]; then
67 f_struct_copy $devs device_media
70 local title="$msg_choose_a_cd_dvd_type"
71 local prompt="$msg_please_select_a_cd_dvd_drive"
74 dev=$( f_device_menu \
75 "$title" "$prompt" "$hline" $DEVICE_TYPE_CDROM \
76 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) ||
79 f_struct_copy "$dev" device_media
82 f_struct device_media || return $FAILURE
85 # f_media_init_cdrom $device
87 # Initializes the CDROM media device. Returns success if able to mount the CD
88 # device using mount_cd9660(8).
92 local funcname=f_media_init_cdrom
93 local dev="$1" devname err
95 f_struct "$dev" get devname devname || return $FAILURE
96 f_dprintf "Init routine called for CDROM device. devname=[%s]" \
99 if [ "$CDROM_MOUNTED" ]; then
100 f_dprintf "CDROM device already mounted."
104 if [ ! -e "$MOUNTPOINT" ]; then
105 f_eval_catch $funcname mkdir 'mkdir -p "%s"' "$MOUNTPOINT" ||
109 if ! f_eval_catch -dk err $funcname mount_cd9660 \
110 'mount_cd9660 "%s" "%s"' "$devname" "$MOUNTPOINT"
112 err="${err#mount_cd9660: }"; err="${err#$devname: }"
115 # Perhaps the CDROM drive is already mounted as /cdrom
116 if f_mounted /cdrom; then
117 CDROM_PREVIOUSLY_MOUNTED=1
124 "") : good ;; # no error
126 [ "$CDROM_INIT_QUIET" ] ||
127 f_show_msg "$msg_error_mounting_device" \
128 "$devname" "$MOUNTPOINT" "$err"
134 : xxx # /cdrom.inf has been deprecated since 9.0-R
136 # No other CDROM media validation at this time
141 # f_media_get_cdrom $device $file [$probe_type]
143 # Returns data from $file on a mounted CDROM device. Similar to cat(1). If
144 # $probe_type is present and non-NULL, returns success if $file exists. If
145 # $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to
150 local dev="$1" file="$2" probe_type="$3"
154 f_dprintf "f_media_get_cdrom: dev=[%s] file=[%s] probe_type=%s" \
155 "$name" "$file" "$probe_type"
157 f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type"
160 # f_media_shutdown_cdrom $device
162 # Shuts down the CDROM device. Return status should be ignored.
164 f_media_shutdown_cdrom()
166 local funcname=f_media_shutdown_cdrom
169 [ "$CDROM_MOUNTED" ] || return $FAILURE
171 if [ "$CDROM_PREVIOUSLY_MOUNTED" ]; then
176 if ! f_eval_catch -dk err $funcname umount \
177 'umount -f "%s"' "$MOUNTPOINT"
179 err="${err#umount: }"; err="${err#*: }"
180 f_show_msg "$msg_could_not_unmount_the_cdrom_dvd" \
187 # f_media_eject_cdrom $device
189 # Eject the media from the CDROM device. Returns success.
191 f_media_eject_cdrom()
193 local funcname=f_media_eject_cdrom
194 local dev="$1" name devname err
196 f_struct "$dev" || return $SUCCESS
197 $dev get name name || return $SUCCESS
198 $dev get devname devname || return $SUCCESS
201 case "$name" in */*) return $SUCCESS; esac
203 f_dprintf "Ejecting CDROM/DVD at %s" "$devname"
204 if ! f_eval_catch -dk err $funcname cdcontrol \
205 'cdcontrol -f "%s" eject' "$devname"
207 f_dprintf "Could not eject the CDROM/DVD from %s: %s" \
208 "$devname" "${err#cdcontrol: }"
213 ############################################################ MAIN
215 f_dprintf "%s: Successfully loaded." media/cdrom.subr
217 fi # ! $_MEDIA_CDROM_SUBR