Detect floppy diskette

Joshua Oreman oremanj at get-linux.org
Tue Aug 26 14:42:45 PDT 2003


On Tue, Aug 26, 2003 at 03:00:23PM -0500 or thereabouts, Charles Howse wrote:
> > Try this:
> > % perl
> > use POSIX qw/:fcntl_h dup2 setsid/;
> > if (fork) { exit; }
> > setsid;
> > 
> > my $fd = POSIX::open "/dev/null", O_WRONLY or die "Can't open 
> > /dev/null: $!\n";
> > dup2 $fd, 0;
> > dup2 $fd, 1;
> > dup2 $fd, 2;
> > 
> > sleep 5;
> > 
> > system "sudo mount /dev/fd0 /mnt";
> > 
> > %    # wait for an error within 5 seconds or so
> > 
> > If no error appears, I think you forgot the / on /dev/null up 
> > there :-) Make
> > sure to unmount the floppy afterwards.
> > If there is an error, it proves that it was/is a kernel message.
> 
> Looks good, now...I have to insert this perl code into a bash script as
> a function.
> This generates a syntax error:
> #!/usr/local/bin/bash
> 
> Chkflp(){
> /usr/bin/perl
add <<EOF to the end of this line
> use POSIX qw/:fcntl_h dup2 setsid/;
> if (fork) { exit; }
> setsid;
>  
> my $fd = POSIX::open "/dev/null", O_WRONLY or die "Can't open 
> /dev/null: $!\n";
> dup2 $fd, 0;
> dup2 $fd, 1;
> dup2 $fd, 2;
>  
> sleep 5;
put EOF on a new line here
> }
> <remainder of bash script>

But I think you misunderstood me.
This script will check to see whether you *can* trap the error. Run it manually
on the command line, wait a few seconds, see if you get an error w/o a floppy in
the drive. If no error, great; put this in bash script:

FloppyInDrive() {
	perl << 'EOF'
use POSIX;
my $fd = POSIX::open "/dev/null", POSIX::O_WRONLY or die "can't open /dev/null";
dup2 $fd, $_ for (0, 1, 2);
exec "dd if=/dev/fd0 of=/dev/null bs=1k count=1";
EOF
	return $?
}

until FloppyInDrive; do echo "please insert floppy and press enter"; read key; done
--
Something like that. This is how it looks on my Linux box (sorry, no FreeBSD example yet):
bash-2.05a# FloppyInDrive() {
>         perl << 'EOF'
> use POSIX;
> my $fd = POSIX::open "/dev/null", POSIX::O_WRONLY or die "can't open /dev/null";
> dup2 $fd, $_ for (0, 1, 2);
> exec "dd if=/dev/floppy/0 of=/dev/null bs=1k count=1";
> EOF
>         return $?
> }
bash-2.05a#
<insert floppy>
bash-2.05a# until FloppyInDrive; do echo "please insert floppy and press enter"; read key; done
<eject floppy>
bash-2.05a# SysRq : Changing Loglevel
Loglevel set to 9
until FloppyInDrive; do echo "please insert floppy and press enter"; read key; done
end_request: I/O error, dev 02:00 (floppy), sector 0
please insert floppy and press enter

end_request: I/O error, dev 02:00 (floppy), sector 0
please insert floppy and press enter
<insert floppy>
<eject floppy>
bash-2.05a# SysRq : Changing Loglevel
Loglevel set to 3
until FloppyInDrive; do echo "please insert floppy and press enter"; read key; done
please insert floppy and press enter

please insert floppy and press enter
<insert floppy>
bash-2.05a#

If the original errors, well, maybe the above will work anyway. Maybe it won't. Oh well.

-- Josh

> 
> 
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"


More information about the freebsd-questions mailing list