From owner-freebsd-questions Tue Sep 2 13:24:57 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id NAA25391 for questions-outgoing; Tue, 2 Sep 1997 13:24:57 -0700 (PDT) Received: from adam.adonai.net (adam.adonai.net [207.8.83.2]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id NAA25379 for ; Tue, 2 Sep 1997 13:24:42 -0700 (PDT) Received: from localhost (leec@localhost) by adam.adonai.net (8.8.5/8.7.3) with SMTP id PAA10625 for ; Tue, 2 Sep 1997 15:24:32 -0500 (CDT) Date: Tue, 2 Sep 1997 15:24:32 -0500 (CDT) From: "Lee Crites (AEI)" To: freebsd-questions@freebsd.org Subject: Check for dos floppy/floppy write protected... Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk I glanced at the thread about checking to see if a floppy is write protected. Unfortuantely, I did not check it closely enough to know for sure which list it came from. However, since I didn't remember seeing the inevitable "don't ask -hackers" response, I assumed it was to -questions, so that is where my reply is going... I have three scripts for each of my floppy drives which take care of mounting, unmounting, and checking the floppy. They work for me and my limited uses of them. Your mileage, as they say, my vary. Here they are, for your personal pleasure and enjoyment. You'll laugh; you'll cry; you'll hurl... ;) Remember, we're talking about msdos compatible floppies here. Also, I have a /floppy directory which I use as the base for the floppy drives. I also have /floppy/A and /floppy/B for, you guessed it, the A and B floppy drives. This has long ago since become nothing more than a nomenclature for this system since FreeBSD is the only os on it. But since I have a large "A" on the 3.5" and "B" on the 5.25" drives, it still has some meaning to me. In each of the two directories, I have a file called "nothing.is.mounted" (touch /floppy/A/nothing.is.mounted) which can only be seen if no floppy drive has been mounted. So to set up for these scripts, do the following (logged in with root permissions): * mkdir /floppy * mkdir /floppy/A * mkdir /floppy/B * touch /floppy/A/nothing.is.mounted * touch /floppy/B/nothing.is.mounted * chmod -R 777 /floppy * chown -R root.wheel /floppy Just for giggles and grins, I also have a /scripts directory into which I place all sorts of fun things like these. But that's a different story... This script checks to see if a floppy looks like it has been mounted. It assumes you know what you want, so if it sees something that looks like it has been mounted it will unmount it first. Finally, it mounts the floppy using mount_msdos. There are some who don't like using the mount_xxx commands, and their arguments are good. If you don't like that plan, pitch these scripts. #!/bin/csh -f # # Mount the A floppy drive. # echo "Mounting the A floppy (3.50)..." if ! ( -e /floppy/A/nothing.is.mounted ) then echo " -- already mounted, removing old version" umount /floppy/A endif mount_msdos /dev/fd0 /floppy/A && goto GotIt echo " -- error mounting floppy" exit GotIt: echo " -- floppy mounted" This will just unmount the floppy. #!/bin/csh -f # # Unmount the A floppy drive. # echo "Unmounting the A floppy..." if ( -e /floppy/A/nothing.is.mounted ) then echo " -- nothing mounted" exit endif umount /floppy/A This one assumes a floppy has been mounted but does not assume what the path to it is. Actually, I use this on more than just my FreeBSD server, so it had to have something just a little different. It checks the df -k command for the /dev/fd0 line, grabs the path from it, and tries to create a dummy file there. If the file can be created, guess what -- the floppy is writeable. SO..... That's what I try to do. Write a file then check for it. IF it's there, remove it and tell me the floppy is writeable. #!/bin/csh -f # # This will check to see if the floppy is write-protected. # -- this assumes the A drive is /dev/fd0 # echo "Checking to see if floppy is writable" # # Grab the pathname from the df command # set fdir = `df -k|grep /dev/fd0|awk '{print $6}'` # # See if we got something. # if ( "$fdir" == "" ) then echo " -- df could not find the floppy drive" exit endif # # Try to write something there. # touch $fdir/goober.goo >>& /dev/null # # See if it is there. # if ! ( -e $fdir/goober.goo ) then echo " -- floppy write protected" exit endif # # If we are here, the floppy is writeable # rm -f $fdir/goober.goo echo " -- floppy is writeable" # # done # I have a set of scripts called mountA, umountA, and checkA (the ones which are enclosed). I also have mountB, umountB, and checkB. That rounds out my msdos floppy set. I also used some stuff from Greg Lehey's book to make a mounta and mountb -- notice the case of A/B. If anyone cares, I can toss those into a message as well. Lee