directory.subr revision 247280
150397Sobrienif [ ! "$_MEDIA_DIRECTORY_SUBR" ]; then _MEDIA_DIRECTORY_SUBR=1 2169689Skan# 3132718Skan# Copyright (c) 2012-2013 Devin Teske 418334Speter# All Rights Reserved. 550397Sobrien# 618334Speter# Redistribution and use in source and binary forms, with or without 7132718Skan# modification, are permitted provided that the following conditions 818334Speter# are met: 9132718Skan# 1. Redistributions of source code must retain the above copyright 1018334Speter# notice, this list of conditions and the following disclaimer. 1118334Speter# 2. Redistributions in binary form must reproduce the above copyright 1218334Speter# notice, this list of conditions and the following disclaimer in the 1318334Speter# documentation and/or other materials provided with the distribution. 14132718Skan# 1518334Speter# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1618334Speter# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 1718334Speter# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1818334Speter# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1918334Speter# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20132718Skan# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21169689Skan# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22169689Skan# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2318334Speter# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24117395Skan# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2518334Speter# SUCH DAMAGE. 2618334Speter# 2718334Speter# $FreeBSD: head/usr.sbin/bsdconfig/share/media/directory.subr 247280 2013-02-25 19:55:32Z dteske $ 2818334Speter# 2918334Speter############################################################ INCLUDES 3018334Speter 3118334SpeterBSDCFG_SHARE="/usr/share/bsdconfig" 3218334Speter. $BSDCFG_SHARE/common.subr || exit 1 3318334Speterf_dprintf "%s: loading includes..." media/directory.subr 3418334Speterf_include $BSDCFG_SHARE/struct.subr 3518334Speterf_include $BSDCFG_SHARE/device.subr 3650397Sobrienf_include $BSDCFG_SHARE/dialog.subr 3750397Sobrienf_include $BSDCFG_SHARE/variable.subr 3818334Speterf_include $BSDCFG_SHARE/media/common.subr 39117395Skan 4018334SpeterBSDCFG_LIBE="/usr/libexec/bsdconfig" 4118334Speterf_include_lang $BSDCFG_LIBE/include/messages.subr 42169689Skan 4318334Speter############################################################ GLOBALS 44132718Skan 45132718SkanDIRECTORY_CHECKED= 4690075Sobrien 4790075Sobrien############################################################ FUNCTIONS 48132718Skan 49132718Skan# f_media_set_directory 5090075Sobrien# 5118334Speter# Return success if we both found and set the media type to be a local 5250397Sobrien# directory. 5350397Sobrien# 5418334Speter# Variables from variable.subr that can be used to script user input: 5518334Speter# 5650397Sobrien# VAR_DIRECTORY_PATH 5718334Speter# Path to an existing directory containing the FreeBSD 5818334Speter# distribution files. 5918334Speter# 60132718Skanf_media_set_directory() 6150397Sobrien{ 62117395Skan local path 6350397Sobrien 6450397Sobrien f_media_close 6550397Sobrien 6650397Sobrien f_variable_get_value $VAR_DIRECTORY_PATH \ 6790075Sobrien "$msg_enter_a_fully_qualified_pathname_for_the_directory" 6890075Sobrien f_getvar $VAR_DIRECTORY_PATH path 6990075Sobrien [ "$path" ] || return $FAILURE 7050397Sobrien 7150397Sobrien f_struct_new DEVICE device_directory 7250397Sobrien device_directory set get f_media_get_directory 73117395Skan device_directory set init f_media_init_directory 74117395Skan device_directory set shutdown f_media_shutdown_directory 75117395Skan device_directory set private "$path" 7690075Sobrien 77132718Skan f_struct_copy device_directory device_media 78132718Skan f_struct_free device_directory 79132718Skan 80132718Skan f_struct device_media || return $FAILURE 81132718Skan} 82132718Skan 83132718Skan# f_media_init_directory $device 84132718Skan# 85132718Skan# Initializes the Directory media device. Returns success if the directory path 86132718Skan# both exists and is a directory. 87169689Skan# 8890075Sobrienf_media_init_directory() 8990075Sobrien{ 9090075Sobrien local dev="$1" path 91132718Skan 92132718Skan device_$dev get private path || return $FAILURE 93132718Skan f_dprintf "Init routine called for Directory device. path=[%s]" \ 94122180Skan "$path" 95122180Skan 96122180Skan # Track whether we've been through here before (for remote filesystems 97169689Skan # mounted in the directory path, not repeating these queries saves us 98169689Skan # valuable time for slow/uncooperative links). 99169689Skan if [ "$DIRECTORY_CHECKED" ]; then 100132718Skan f_dprintf "Directory device already checked." 101117395Skan return $SUCCESS 102169689Skan fi 103169689Skan 104169689Skan if [ ! -e "$path" ]; then 105169689Skan f_show_msg "$msg_no_such_file_or_directory" \ 106169689Skan "f_media_init_directory" "$path" 107169689Skan return $FAILURE 108169689Skan elif [ ! -d "$path" ]; then 109169689Skan f_show_msg "$msg_not_a_directory" \ 110169689Skan "f_media_init_directory" "$path" 111169689Skan return $FAILURE 112169689Skan fi 113169689Skan DIRECTORY_CHECKED=1 114169689Skan return $SUCCESS 115169689Skan} 116169689Skan 117169689Skan# f_media_get_directory $device $file [$probe_only] 118169689Skan# 119169689Skan# Returns data from $file in the existing/current filesystem. Similar to 120169689Skan# cat(1). $probe_only is currently unused by this media type. 121169689Skan# 122169689Skanf_media_get_directory() 123169689Skan{ 124169689Skan local dev="$1" file="$2" probe_only="$3" path 125169689Skan 126169689Skan f_dprintf "f_media_get_directory: dev=[%s] file=[%s] probe_only=%s" \ 127169689Skan "$dev" "$file" "$probe_only" 128169689Skan 129169689Skan device_$dev get private path 130 f_media_generic_get "$path" "$file" 131} 132 133# f_media_shutdown_directory $device 134# 135# Shuts down the Directory device. Return status should be ignored. 136# 137f_media_shutdown_directory() 138{ 139 DIRECTORY_CHECKED= 140} 141 142############################################################ MAIN 143 144f_dprintf "%s: Successfully loaded." media/directory.subr 145 146fi # ! $_MEDIA_DIRECTORY_SUBR 147