1247280Sdteskeif [ ! "$_MEDIA_DIRECTORY_SUBR" ]; then _MEDIA_DIRECTORY_SUBR=1 2247280Sdteske# 3247280Sdteske# Copyright (c) 2012-2013 Devin Teske 4252980Sdteske# All rights reserved. 5247280Sdteske# 6247280Sdteske# Redistribution and use in source and binary forms, with or without 7247280Sdteske# modification, are permitted provided that the following conditions 8247280Sdteske# are met: 9247280Sdteske# 1. Redistributions of source code must retain the above copyright 10247280Sdteske# notice, this list of conditions and the following disclaimer. 11247280Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12247280Sdteske# notice, this list of conditions and the following disclaimer in the 13247280Sdteske# documentation and/or other materials provided with the distribution. 14247280Sdteske# 15247280Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16252987Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17247280Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18247280Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19247280Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20252987Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21247280Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22247280Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23247280Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24247280Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25247280Sdteske# SUCH DAMAGE. 26247280Sdteske# 27247280Sdteske# $FreeBSD: releng/10.2/usr.sbin/bsdconfig/share/media/directory.subr 266290 2014-05-17 03:28:43Z dteske $ 28247280Sdteske# 29247280Sdteske############################################################ INCLUDES 30247280Sdteske 31247280SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 32247280Sdteske. $BSDCFG_SHARE/common.subr || exit 1 33247280Sdteskef_dprintf "%s: loading includes..." media/directory.subr 34247280Sdteskef_include $BSDCFG_SHARE/device.subr 35247280Sdteskef_include $BSDCFG_SHARE/dialog.subr 36252077Sdteskef_include $BSDCFG_SHARE/media/common.subr 37252077Sdteskef_include $BSDCFG_SHARE/struct.subr 38247280Sdteskef_include $BSDCFG_SHARE/variable.subr 39247280Sdteske 40247280SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" 41247280Sdteskef_include_lang $BSDCFG_LIBE/include/messages.subr 42247280Sdteske 43247280Sdteske############################################################ GLOBALS 44247280Sdteske 45247280SdteskeDIRECTORY_CHECKED= 46247280Sdteske 47247280Sdteske############################################################ FUNCTIONS 48247280Sdteske 49247280Sdteske# f_media_set_directory 50247280Sdteske# 51247280Sdteske# Return success if we both found and set the media type to be a local 52247280Sdteske# directory. 53247280Sdteske# 54247280Sdteske# Variables from variable.subr that can be used to script user input: 55247280Sdteske# 56247280Sdteske# VAR_DIRECTORY_PATH 57247280Sdteske# Path to an existing directory containing the FreeBSD 58247280Sdteske# distribution files. 59247280Sdteske# 60247280Sdteskef_media_set_directory() 61247280Sdteske{ 62247280Sdteske local path 63247280Sdteske 64247280Sdteske f_media_close 65247280Sdteske 66247280Sdteske f_variable_get_value $VAR_DIRECTORY_PATH \ 67247280Sdteske "$msg_enter_a_fully_qualified_pathname_for_the_directory" 68247280Sdteske f_getvar $VAR_DIRECTORY_PATH path 69247280Sdteske [ "$path" ] || return $FAILURE 70247280Sdteske 71247280Sdteske f_struct_new DEVICE device_directory 72252737Sdteske device_directory set name "$path" 73247280Sdteske device_directory set get f_media_get_directory 74247280Sdteske device_directory set init f_media_init_directory 75247280Sdteske device_directory set shutdown f_media_shutdown_directory 76247280Sdteske device_directory set private "$path" 77247280Sdteske 78247280Sdteske f_struct_copy device_directory device_media 79247280Sdteske f_struct_free device_directory 80247280Sdteske 81247280Sdteske f_struct device_media || return $FAILURE 82247280Sdteske} 83247280Sdteske 84247280Sdteske# f_media_init_directory $device 85247280Sdteske# 86247280Sdteske# Initializes the Directory media device. Returns success if the directory path 87247280Sdteske# both exists and is a directory. 88247280Sdteske# 89247280Sdteskef_media_init_directory() 90247280Sdteske{ 91247280Sdteske local dev="$1" path 92247280Sdteske 93266290Sdteske $dev get private path || return $FAILURE 94247280Sdteske f_dprintf "Init routine called for Directory device. path=[%s]" \ 95247280Sdteske "$path" 96247280Sdteske 97247280Sdteske # Track whether we've been through here before (for remote filesystems 98247280Sdteske # mounted in the directory path, not repeating these queries saves us 99247280Sdteske # valuable time for slow/uncooperative links). 100247280Sdteske if [ "$DIRECTORY_CHECKED" ]; then 101247280Sdteske f_dprintf "Directory device already checked." 102247280Sdteske return $SUCCESS 103247280Sdteske fi 104247280Sdteske 105247280Sdteske if [ ! -e "$path" ]; then 106247280Sdteske f_show_msg "$msg_no_such_file_or_directory" \ 107247280Sdteske "f_media_init_directory" "$path" 108247280Sdteske return $FAILURE 109247280Sdteske elif [ ! -d "$path" ]; then 110247280Sdteske f_show_msg "$msg_not_a_directory" \ 111247280Sdteske "f_media_init_directory" "$path" 112247280Sdteske return $FAILURE 113247280Sdteske fi 114247280Sdteske DIRECTORY_CHECKED=1 115247280Sdteske return $SUCCESS 116247280Sdteske} 117247280Sdteske 118253333Sdteske# f_media_get_directory $device $file [$probe_type] 119247280Sdteske# 120247280Sdteske# Returns data from $file in the existing/current filesystem. Similar to 121253333Sdteske# cat(1). If $probe_type is present and non-NULL, returns success if $file 122253333Sdteske# exists. If $probe_type is equal to $PROBE_SIZE, prints the size of $file in 123253333Sdteske# bytes to standard-out. 124247280Sdteske# 125247280Sdteskef_media_get_directory() 126247280Sdteske{ 127253333Sdteske local dev="$1" file="$2" probe_type="$3" path 128266290Sdteske local name 129247280Sdteske 130266290Sdteske $dev get name name 131253333Sdteske f_dprintf "f_media_get_directory: dev=[%s] file=[%s] probe_type=%s" \ 132266290Sdteske "$name" "$file" "$probe_type" 133247280Sdteske 134266290Sdteske $dev get private path 135253333Sdteske f_media_generic_get "$path" "$file" "$probe_type" 136247280Sdteske} 137247280Sdteske 138247280Sdteske# f_media_shutdown_directory $device 139247280Sdteske# 140247280Sdteske# Shuts down the Directory device. Return status should be ignored. 141247280Sdteske# 142247280Sdteskef_media_shutdown_directory() 143247280Sdteske{ 144247280Sdteske DIRECTORY_CHECKED= 145247280Sdteske} 146247280Sdteske 147247280Sdteske############################################################ MAIN 148247280Sdteske 149247280Sdteskef_dprintf "%s: Successfully loaded." media/directory.subr 150247280Sdteske 151247280Sdteskefi # ! $_MEDIA_DIRECTORY_SUBR 152