1if [ ! "$_MEDIA_DIRECTORY_SUBR" ]; then _MEDIA_DIRECTORY_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: 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. 14# 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 25# SUCH DAMAGE. 26#
| 1if [ ! "$_MEDIA_DIRECTORY_SUBR" ]; then _MEDIA_DIRECTORY_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: 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. 14# 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 25# SUCH DAMAGE. 26#
|
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/directory.subr 252987 2013-07-07 18:51:44Z dteske $
| 27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/directory.subr 253333 2013-07-14 03:08:52Z dteske $
|
28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." media/directory.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/dialog.subr 36f_include $BSDCFG_SHARE/media/common.subr 37f_include $BSDCFG_SHARE/struct.subr 38f_include $BSDCFG_SHARE/variable.subr 39 40BSDCFG_LIBE="/usr/libexec/bsdconfig" 41f_include_lang $BSDCFG_LIBE/include/messages.subr 42 43############################################################ GLOBALS 44 45DIRECTORY_CHECKED= 46 47############################################################ FUNCTIONS 48 49# f_media_set_directory 50# 51# Return success if we both found and set the media type to be a local 52# directory. 53# 54# Variables from variable.subr that can be used to script user input: 55# 56# VAR_DIRECTORY_PATH 57# Path to an existing directory containing the FreeBSD 58# distribution files. 59# 60f_media_set_directory() 61{ 62 local path 63 64 f_media_close 65 66 f_variable_get_value $VAR_DIRECTORY_PATH \ 67 "$msg_enter_a_fully_qualified_pathname_for_the_directory" 68 f_getvar $VAR_DIRECTORY_PATH path 69 [ "$path" ] || return $FAILURE 70 71 f_struct_new DEVICE device_directory 72 device_directory set name "$path" 73 device_directory set get f_media_get_directory 74 device_directory set init f_media_init_directory 75 device_directory set shutdown f_media_shutdown_directory 76 device_directory set private "$path" 77 78 f_struct_copy device_directory device_media 79 f_struct_free device_directory 80 81 f_struct device_media || return $FAILURE 82} 83 84# f_media_init_directory $device 85# 86# Initializes the Directory media device. Returns success if the directory path 87# both exists and is a directory. 88# 89f_media_init_directory() 90{ 91 local dev="$1" path 92 93 device_$dev get private path || return $FAILURE 94 f_dprintf "Init routine called for Directory device. path=[%s]" \ 95 "$path" 96 97 # Track whether we've been through here before (for remote filesystems 98 # mounted in the directory path, not repeating these queries saves us 99 # valuable time for slow/uncooperative links). 100 if [ "$DIRECTORY_CHECKED" ]; then 101 f_dprintf "Directory device already checked." 102 return $SUCCESS 103 fi 104 105 if [ ! -e "$path" ]; then 106 f_show_msg "$msg_no_such_file_or_directory" \ 107 "f_media_init_directory" "$path" 108 return $FAILURE 109 elif [ ! -d "$path" ]; then 110 f_show_msg "$msg_not_a_directory" \ 111 "f_media_init_directory" "$path" 112 return $FAILURE 113 fi 114 DIRECTORY_CHECKED=1 115 return $SUCCESS 116} 117
| 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." media/directory.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/dialog.subr 36f_include $BSDCFG_SHARE/media/common.subr 37f_include $BSDCFG_SHARE/struct.subr 38f_include $BSDCFG_SHARE/variable.subr 39 40BSDCFG_LIBE="/usr/libexec/bsdconfig" 41f_include_lang $BSDCFG_LIBE/include/messages.subr 42 43############################################################ GLOBALS 44 45DIRECTORY_CHECKED= 46 47############################################################ FUNCTIONS 48 49# f_media_set_directory 50# 51# Return success if we both found and set the media type to be a local 52# directory. 53# 54# Variables from variable.subr that can be used to script user input: 55# 56# VAR_DIRECTORY_PATH 57# Path to an existing directory containing the FreeBSD 58# distribution files. 59# 60f_media_set_directory() 61{ 62 local path 63 64 f_media_close 65 66 f_variable_get_value $VAR_DIRECTORY_PATH \ 67 "$msg_enter_a_fully_qualified_pathname_for_the_directory" 68 f_getvar $VAR_DIRECTORY_PATH path 69 [ "$path" ] || return $FAILURE 70 71 f_struct_new DEVICE device_directory 72 device_directory set name "$path" 73 device_directory set get f_media_get_directory 74 device_directory set init f_media_init_directory 75 device_directory set shutdown f_media_shutdown_directory 76 device_directory set private "$path" 77 78 f_struct_copy device_directory device_media 79 f_struct_free device_directory 80 81 f_struct device_media || return $FAILURE 82} 83 84# f_media_init_directory $device 85# 86# Initializes the Directory media device. Returns success if the directory path 87# both exists and is a directory. 88# 89f_media_init_directory() 90{ 91 local dev="$1" path 92 93 device_$dev get private path || return $FAILURE 94 f_dprintf "Init routine called for Directory device. path=[%s]" \ 95 "$path" 96 97 # Track whether we've been through here before (for remote filesystems 98 # mounted in the directory path, not repeating these queries saves us 99 # valuable time for slow/uncooperative links). 100 if [ "$DIRECTORY_CHECKED" ]; then 101 f_dprintf "Directory device already checked." 102 return $SUCCESS 103 fi 104 105 if [ ! -e "$path" ]; then 106 f_show_msg "$msg_no_such_file_or_directory" \ 107 "f_media_init_directory" "$path" 108 return $FAILURE 109 elif [ ! -d "$path" ]; then 110 f_show_msg "$msg_not_a_directory" \ 111 "f_media_init_directory" "$path" 112 return $FAILURE 113 fi 114 DIRECTORY_CHECKED=1 115 return $SUCCESS 116} 117
|
118# f_media_get_directory $device $file [$probe_only]
| 118# f_media_get_directory $device $file [$probe_type]
|
119# 120# Returns data from $file in the existing/current filesystem. Similar to
| 119# 120# Returns data from $file in the existing/current filesystem. Similar to
|
121# cat(1). If $probe_only is present and non-NULL, returns success if $file 122# exists.
| 121# cat(1). If $probe_type is present and non-NULL, returns success if $file 122# exists. If $probe_type is equal to $PROBE_SIZE, prints the size of $file in 123# bytes to standard-out.
|
123# 124f_media_get_directory() 125{
| 124# 125f_media_get_directory() 126{
|
126 local dev="$1" file="$2" probe_only="$3" path
| 127 local dev="$1" file="$2" probe_type="$3" path
|
127
| 128
|
128 f_dprintf "f_media_get_directory: dev=[%s] file=[%s] probe_only=%s" \ 129 "$dev" "$file" "$probe_only"
| 129 f_dprintf "f_media_get_directory: dev=[%s] file=[%s] probe_type=%s" \ 130 "$dev" "$file" "$probe_type"
|
130 131 device_$dev get private path
| 131 132 device_$dev get private path
|
132 f_media_generic_get "$path" "$file" "$probe_only"
| 133 f_media_generic_get "$path" "$file" "$probe_type"
|
133} 134 135# f_media_shutdown_directory $device 136# 137# Shuts down the Directory device. Return status should be ignored. 138# 139f_media_shutdown_directory() 140{ 141 DIRECTORY_CHECKED= 142} 143 144############################################################ MAIN 145 146f_dprintf "%s: Successfully loaded." media/directory.subr 147 148fi # ! $_MEDIA_DIRECTORY_SUBR
| 134} 135 136# f_media_shutdown_directory $device 137# 138# Shuts down the Directory device. Return status should be ignored. 139# 140f_media_shutdown_directory() 141{ 142 DIRECTORY_CHECKED= 143} 144 145############################################################ MAIN 146 147f_dprintf "%s: Successfully loaded." media/directory.subr 148 149fi # ! $_MEDIA_DIRECTORY_SUBR
|