Deleted Added
full compact
nfs.subr (259054) nfs.subr (264840)
1if [ ! "$_MEDIA_NFS_SUBR" ]; then _MEDIA_NFS_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_NFS_SUBR" ]; then _MEDIA_NFS_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: head/usr.sbin/bsdconfig/share/media/nfs.subr 259054 2013-12-07 00:31:01Z dteske $
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/nfs.subr 264840 2014-04-23 22:04:04Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/nfs.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr

--- 52 unchanged lines hidden (view full) ---

88
89 f_struct_new DEVICE device_nfs
90 device_nfs set name "$nfs"
91
92 if ! f_struct device_network ||
93 ! f_dialog_yesno "$msg_youve_already_done_the_network_configuration"
94 then
95 f_struct device_network &&
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/nfs.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr

--- 52 unchanged lines hidden (view full) ---

88
89 f_struct_new DEVICE device_nfs
90 device_nfs set name "$nfs"
91
92 if ! f_struct device_network ||
93 ! f_dialog_yesno "$msg_youve_already_done_the_network_configuration"
94 then
95 f_struct device_network &&
96 f_device_shutdown network
96 f_device_shutdown device_network
97 f_device_select_tcp || return $FAILURE
97 f_device_select_tcp || return $FAILURE
98 local dev
99 f_getvar $VAR_NETWORK_DEVICE dev
100 f_struct_copy "device_$dev" device_network
98 local dev if
99 f_getvar $VAR_NETWORK_DEVICE if
100 f_device_find -1 "$if" $DEVICE_TYPE_NETWORK dev
101 f_struct_copy "$dev" device_network
101 fi
102 fi
102 f_device_init network ||
103 f_device_init device_network ||
103 f_dprintf "%s: $msg_net_device_init_failed\n" f_media_set_nfs
104
105 local hostname="${nfs%%:*}"
106 if f_isset $VAR_NAMESERVER && ! {
107 f_validate_ipaddr "$hostname" || f_validate_ipaddr6 "$hostname"
108 }; then
109 f_show_info "$msg_looking_up_host" "$hostname"
110 f_dprintf "%s Looking up hostname, %s, using host(1)" \
111 "f_media_set_nfs" "$hostname"
112 if ! f_quietly f_host_lookup "$hostname"; then
113 f_show_msg "$msg_cannot_resolve_hostname" "$hostname"
114 f_struct device_network &&
104 f_dprintf "%s: $msg_net_device_init_failed\n" f_media_set_nfs
105
106 local hostname="${nfs%%:*}"
107 if f_isset $VAR_NAMESERVER && ! {
108 f_validate_ipaddr "$hostname" || f_validate_ipaddr6 "$hostname"
109 }; then
110 f_show_info "$msg_looking_up_host" "$hostname"
111 f_dprintf "%s Looking up hostname, %s, using host(1)" \
112 "f_media_set_nfs" "$hostname"
113 if ! f_quietly f_host_lookup "$hostname"; then
114 f_show_msg "$msg_cannot_resolve_hostname" "$hostname"
115 f_struct device_network &&
115 f_device_shutdown network
116 f_device_shutdown device_network
116 f_struct_free device_network
117 unset $VAR_NFS_PATH
118 return $FAILURE
119 fi
120 f_dprintf "Found DNS entry for %s successfully." "$hostname"
121 fi
122
123 setvar $VAR_NFS_HOST "$hostname"

--- 28 unchanged lines hidden (view full) ---

152# VAR_SLOW_ETHER [Optional]
153# If non-NULL, adjusts the read/write size to avoid timeouts.
154#
155f_media_init_nfs()
156{
157 local funcname=f_media_init_nfs
158 local dev="$1" name err
159
117 f_struct_free device_network
118 unset $VAR_NFS_PATH
119 return $FAILURE
120 fi
121 f_dprintf "Found DNS entry for %s successfully." "$hostname"
122 fi
123
124 setvar $VAR_NFS_HOST "$hostname"

--- 28 unchanged lines hidden (view full) ---

153# VAR_SLOW_ETHER [Optional]
154# If non-NULL, adjusts the read/write size to avoid timeouts.
155#
156f_media_init_nfs()
157{
158 local funcname=f_media_init_nfs
159 local dev="$1" name err
160
160 device_$dev get name name || return $FAILURE
161 $dev get name name || return $FAILURE
161 f_dprintf "Init routine called for NFS device. name=[%s]" \
162 "$name"
163
164 if [ "$NFS_MOUNTED" ]; then
165 f_dprintf "NFS device already mounted."
166 return $SUCCESS
167 fi
168
162 f_dprintf "Init routine called for NFS device. name=[%s]" \
163 "$name"
164
165 if [ "$NFS_MOUNTED" ]; then
166 f_dprintf "NFS device already mounted."
167 return $SUCCESS
168 fi
169
169 if ! f_device_init network; then
170 if ! f_device_init device_network; then
170 f_dprintf "f_media_init_nfs: %s" "$msg_net_device_init_failed"
171 return $FAILURE
172 fi
173
174 if [ ! -e "$MOUNTPOINT" ]; then
175 f_eval_catch $funcname mkdir 'mkdir -p "%s"' "$MOUNTPOINT" ||
176 return $FAILURE
177 fi

--- 15 unchanged lines hidden (view full) ---

193 if ! f_eval_catch -dk err $funcname mount_nfs \
194 'mount_nfs %s -o "%s" "%s" "%s"' \
195 "${secure:+-P}" "$options" "$name" "$MOUNTPOINT"
196 then
197 err="${err#mount_nfs: }"
198 f_show_msg "$msg_error_mounting_device" \
199 "$name" "$MOUNTPOINT" "$err"
200 f_struct device_network &&
171 f_dprintf "f_media_init_nfs: %s" "$msg_net_device_init_failed"
172 return $FAILURE
173 fi
174
175 if [ ! -e "$MOUNTPOINT" ]; then
176 f_eval_catch $funcname mkdir 'mkdir -p "%s"' "$MOUNTPOINT" ||
177 return $FAILURE
178 fi

--- 15 unchanged lines hidden (view full) ---

194 if ! f_eval_catch -dk err $funcname mount_nfs \
195 'mount_nfs %s -o "%s" "%s" "%s"' \
196 "${secure:+-P}" "$options" "$name" "$MOUNTPOINT"
197 then
198 err="${err#mount_nfs: }"
199 f_show_msg "$msg_error_mounting_device" \
200 "$name" "$MOUNTPOINT" "$err"
201 f_struct device_network &&
201 f_device_shutdown network
202 f_device_shutdown device_network
202 return $FAILURE
203 fi
204 NFS_MOUNTED=1
205
206 f_dprintf "Mounted NFS device %s onto %s" "$name" "$MOUNTPOINT"
207
208 return $SUCCESS
209}
210
211# f_media_get_nfs $device $file [$probe_type]
212#
213# Returns data from $file on a mounted NFS device. Similar to cat(1). If
214# $probe_type is present and non-NULL, returns success if $file exists. If
215# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to
216# standard-out.
217#
218f_media_get_nfs()
219{
220 local dev="$1" file="$2" probe_type="$3"
203 return $FAILURE
204 fi
205 NFS_MOUNTED=1
206
207 f_dprintf "Mounted NFS device %s onto %s" "$name" "$MOUNTPOINT"
208
209 return $SUCCESS
210}
211
212# f_media_get_nfs $device $file [$probe_type]
213#
214# Returns data from $file on a mounted NFS device. Similar to cat(1). If
215# $probe_type is present and non-NULL, returns success if $file exists. If
216# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to
217# standard-out.
218#
219f_media_get_nfs()
220{
221 local dev="$1" file="$2" probe_type="$3"
222 local name
221
223
224 $dev get name name
222 f_dprintf "f_media_get_nfs: dev=[%s] file=[%s] probe_type=%s" \
225 f_dprintf "f_media_get_nfs: dev=[%s] file=[%s] probe_type=%s" \
223 "$dev" "$file" "$probe_type"
226 "$name" "$file" "$probe_type"
224
225 f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type"
226}
227
228# f_media_shutdown_nfs $device
229#
230# Shuts down the NFS device using umount(8). Return status should be ignored.
231#

--- 24 unchanged lines hidden ---
227
228 f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type"
229}
230
231# f_media_shutdown_nfs $device
232#
233# Shuts down the NFS device using umount(8). Return status should be ignored.
234#

--- 24 unchanged lines hidden ---