diff options
Diffstat (limited to 'usr.sbin/bsdconfig/share/media/floppy.subr')
-rw-r--r-- | usr.sbin/bsdconfig/share/media/floppy.subr | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/usr.sbin/bsdconfig/share/media/floppy.subr b/usr.sbin/bsdconfig/share/media/floppy.subr index ac05937..eb6bc5e 100644 --- a/usr.sbin/bsdconfig/share/media/floppy.subr +++ b/usr.sbin/bsdconfig/share/media/floppy.subr @@ -144,17 +144,19 @@ f_media_init_floppy() return $SUCCESS } -# f_media_get_floppy $device $file [$probe_only] +# f_media_get_floppy $device $file [$probe_type] # # Returns data from $file on a mounted Floppy disk device. Similar to cat(1). -# If $probe_only is present and non-null, limits retries to zero. +# If $probe_type is present and non-NULL, limits retries to zero and returns +# success if $file exists. If $probe_type is equal to $PROBE_SIZE, prints the +# size of $file in bytes to standard-out. # f_media_get_floppy() { - local dev="$1" file="$2" probe_only="$3" + local dev="$1" file="$2" probe_type="$3" - f_dprintf "f_media_get_floppy: dev=[%s] file=[%s] probe_only=%s" \ - "$dev" "$file" "$probe_only" + f_dprintf "f_media_get_floppy: dev=[%s] file=[%s] probe_type=%s" \ + "$dev" "$file" "$probe_type" # # floppies don't use f_media_generic_get() because it's too expensive @@ -166,11 +168,13 @@ f_media_get_floppy() local fp="${mp:=$MOUNTPOINT}/$file" if ! [ -f "$fp" -a -r "$fp" ]; then local nretries=4 - [ "$probe_only" ] && return $FAILURE + [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1" + [ "$probe_type" ] && return $FAILURE while ! [ -f "$fp" -a -r "$fp" ]; do if [ $nretries -eq 0 ]; then f_show_msg "$msg_failed_to_get_floppy_file" \ "$fp" + [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1" return $FAILURE fi FLOPPY_DISTWANTED="$fp" @@ -178,9 +182,17 @@ f_media_get_floppy() f_media_init_floppy "$dev" || return $FAILURE nretries=$(( $nretries - 1 )) done - elif [ "$probe_only" ]; then - return $SUCCESS fi + # + # If we reach here, $file exists + # + if [ "$probe_type" = "$PROBE_SIZE" ]; then + local size + size=$( stat -f %z "$fp" 2>&1 ) || f_dprintf "stat: %s" "$size" + f_isinteger "$size" || size=-1 + echo "$size" + fi + [ "$probe_type" ] && return $SUCCESS cat "$fp" } |