cdrom.subr (252995) | cdrom.subr (263791) |
---|---|
1if [ ! "$_MEDIA_CDROM_SUBR" ]; then _MEDIA_CDROM_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# | 1if [ ! "$_MEDIA_CDROM_SUBR" ]; then _MEDIA_CDROM_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: stable/9/usr.sbin/bsdconfig/share/media/cdrom.subr 252995 2013-07-07 19:13:34Z dteske $ | 27# $FreeBSD: stable/9/usr.sbin/bsdconfig/share/media/cdrom.subr 263791 2014-03-27 03:20:47Z dteske $ |
28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." media/cdrom.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/dialog.subr --- 17 unchanged lines hidden (view full) --- 53# Return success if we both found and set the media type to be a CD. 54# 55f_media_set_cdrom() 56{ 57 f_media_close 58 59 local devs ndevs 60 f_device_find "" $DEVICE_TYPE_CDROM devs | 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." media/cdrom.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/dialog.subr --- 17 unchanged lines hidden (view full) --- 53# Return success if we both found and set the media type to be a CD. 54# 55f_media_set_cdrom() 56{ 57 f_media_close 58 59 local devs ndevs 60 f_device_find "" $DEVICE_TYPE_CDROM devs |
61 ndevs=$( set -- $devs; echo $# ) | 61 f_count ndevs $devs |
62 63 if [ ${ndevs:=0} -eq 0 ]; then 64 f_interactive && f_show_msg "$msg_no_cd_dvd_devices_found" 65 return $FAILURE 66 elif [ $ndevs -gt 1 ]; then 67 local title="$msg_choose_a_cd_dvd_type" 68 local prompt="$msg_please_select_a_cd_dvd_drive" 69 local hline="" --- 20 unchanged lines hidden (view full) --- 90 91# f_media_init_cdrom $device 92# 93# Initializes the CDROM media device. Returns success if able to mount the CD 94# device using mount_cd9660(8). 95# 96f_media_init_cdrom() 97{ | 62 63 if [ ${ndevs:=0} -eq 0 ]; then 64 f_interactive && f_show_msg "$msg_no_cd_dvd_devices_found" 65 return $FAILURE 66 elif [ $ndevs -gt 1 ]; then 67 local title="$msg_choose_a_cd_dvd_type" 68 local prompt="$msg_please_select_a_cd_dvd_drive" 69 local hline="" --- 20 unchanged lines hidden (view full) --- 90 91# f_media_init_cdrom $device 92# 93# Initializes the CDROM media device. Returns success if able to mount the CD 94# device using mount_cd9660(8). 95# 96f_media_init_cdrom() 97{ |
98 local funcname=f_media_init_cdrom |
|
98 local dev="$1" devname err 99 100 device_$dev get devname devname || return $FAILURE 101 f_dprintf "Init routine called for CDROM device. devname=[%s]" \ 102 "$devname" 103 104 if [ "$CDROM_MOUNTED" ]; then 105 f_dprintf "CDROM device already mounted." 106 return $SUCCESS 107 fi 108 | 99 local dev="$1" devname err 100 101 device_$dev get devname devname || return $FAILURE 102 f_dprintf "Init routine called for CDROM device. devname=[%s]" \ 103 "$devname" 104 105 if [ "$CDROM_MOUNTED" ]; then 106 f_dprintf "CDROM device already mounted." 107 return $SUCCESS 108 fi 109 |
109 if [ ! -e "$MOUNTPOINT" ] && 110 ! err=$( mkdir -p "$MOUNTPOINT" 2>&1 ) 111 then 112 f_dialog_msgbox "$err" 113 return $FAILURE | 110 if [ ! -e "$MOUNTPOINT" ]; then 111 f_eval_catch $funcname mkdir 'mkdir -p "%s"' "$MOUNTPOINT" || 112 return $FAILURE |
114 fi 115 | 113 fi 114 |
116 if ! err=$( mount_cd9660 "$devname" "$MOUNTPOINT" 2>&1 ) | 115 if ! f_eval_catch -dk err $funcname mount_cd9660 \ 116 'mount_cd9660 "%s" "%s"' "$devname" "$MOUNTPOINT" |
117 then 118 err="${err#mount_cd9660: }"; err="${err#$devname: }" 119 case "$err" in 120 "Device busy") 121 # Perhaps the CDROM drive is already mounted as /cdrom 122 if f_mounted /cdrom; then 123 CDROM_PREVIOUSLY_MOUNTED=1 124 MOUNTPOINT=/cdrom --- 14 unchanged lines hidden (view full) --- 139 140 : xxx # /cdrom.inf has been deprecated since 9.0-R 141 142 # No other CDROM media validation at this time 143 144 return $SUCCESS 145} 146 | 117 then 118 err="${err#mount_cd9660: }"; err="${err#$devname: }" 119 case "$err" in 120 "Device busy") 121 # Perhaps the CDROM drive is already mounted as /cdrom 122 if f_mounted /cdrom; then 123 CDROM_PREVIOUSLY_MOUNTED=1 124 MOUNTPOINT=/cdrom --- 14 unchanged lines hidden (view full) --- 139 140 : xxx # /cdrom.inf has been deprecated since 9.0-R 141 142 # No other CDROM media validation at this time 143 144 return $SUCCESS 145} 146 |
147# f_media_get_cdrom $device $file [$probe_only] | 147# f_media_get_cdrom $device $file [$probe_type] |
148# 149# Returns data from $file on a mounted CDROM device. Similar to cat(1). If | 148# 149# Returns data from $file on a mounted CDROM device. Similar to cat(1). If |
150# $probe_only is present and non-NULL, returns success if $file exists. | 150# $probe_type is present and non-NULL, returns success if $file exists. If 151# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to 152# standard-out. |
151# 152f_media_get_cdrom() 153{ | 153# 154f_media_get_cdrom() 155{ |
154 local dev="$1" file="$2" probe_only="$3" | 156 local dev="$1" file="$2" probe_type="$3" |
155 | 157 |
156 f_dprintf "f_media_get_cdrom: dev=[%s] file=[%s] probe_only=%s" \ 157 "$dev" "$file" "$probe_only" | 158 f_dprintf "f_media_get_cdrom: dev=[%s] file=[%s] probe_type=%s" \ 159 "$dev" "$file" "$probe_type" |
158 | 160 |
159 f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only" | 161 f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type" |
160} 161 162# f_media_shutdown_cdrom $device 163# | 162} 163 164# f_media_shutdown_cdrom $device 165# |
164# Shuts down the CDROM device and ejects the media using f_media_eject_cdrom(), 165# below. Return status should be ignored. | 166# Shuts down the CDROM device. Return status should be ignored. |
166# 167f_media_shutdown_cdrom() 168{ | 167# 168f_media_shutdown_cdrom() 169{ |
170 local funcname=f_media_shutdown_cdrom |
|
169 local dev="$1" err 170 | 171 local dev="$1" err 172 |
171 [ "$CDROM_MOUNTED" ] || return | 173 [ "$CDROM_MOUNTED" ] || return $FAILURE |
172 173 if [ "$CDROM_PREVIOUSLY_MOUNTED" ]; then 174 CDROM_MOUNTED= 175 return $SUCCESS 176 fi 177 | 174 175 if [ "$CDROM_PREVIOUSLY_MOUNTED" ]; then 176 CDROM_MOUNTED= 177 return $SUCCESS 178 fi 179 |
178 if ! err=$( umount -f "$MOUNTPOINT" 2>&1 ); then | 180 if ! f_eval_catch -dk err $funcname umount \ 181 'umount -f "%s"' "$MOUNPOINT" 182 then |
179 err="${err#umount: }"; err="${err#*: }" 180 f_show_msg "$msg_could_not_unmount_the_cdrom_dvd" \ 181 "$MOUNTPOINT" "$err" 182 else 183 CDROM_MOUNTED= 184 fi | 183 err="${err#umount: }"; err="${err#*: }" 184 f_show_msg "$msg_could_not_unmount_the_cdrom_dvd" \ 185 "$MOUNTPOINT" "$err" 186 else 187 CDROM_MOUNTED= 188 fi |
185 186 f_media_eject_cdrom "$dev" | |
187} 188 189# f_media_eject_cdrom $device 190# 191# Eject the media from the CDROM device. Returns success. 192# 193f_media_eject_cdrom() 194{ | 189} 190 191# f_media_eject_cdrom $device 192# 193# Eject the media from the CDROM device. Returns success. 194# 195f_media_eject_cdrom() 196{ |
197 local funcname=f_media_eject_cdrom |
|
195 local dev="$1" devname err 196 device_$dev get name devname || return $SUCCESS 197 case "$devname" in /dev/iso9660/*) return $SUCCESS; esac 198 f_dprintf "Ejecting CDROM/DVD at %s" "$devname" | 198 local dev="$1" devname err 199 device_$dev get name devname || return $SUCCESS 200 case "$devname" in /dev/iso9660/*) return $SUCCESS; esac 201 f_dprintf "Ejecting CDROM/DVD at %s" "$devname" |
199 if ! err=$( cdcontrol -f "$devname" eject 2>&1 ); then | 202 if ! f_eval_catch -dk err $funcname cdcontrol \ 203 'cdcontrol -f "%s" eject' "$devname" 204 then |
200 f_dprintf "Could not eject the CDROM/DVD from %s: %s" \ 201 "$devname" "${err#cdcontrol: }" 202 fi 203 return $SUCCESS 204} 205 206############################################################ MAIN 207 208f_dprintf "%s: Successfully loaded." media/cdrom.subr 209 210fi # ! $_MEDIA_CDROM_SUBR | 205 f_dprintf "Could not eject the CDROM/DVD from %s: %s" \ 206 "$devname" "${err#cdcontrol: }" 207 fi 208 return $SUCCESS 209} 210 211############################################################ MAIN 212 213f_dprintf "%s: Successfully loaded." media/cdrom.subr 214 215fi # ! $_MEDIA_CDROM_SUBR |