From: iwj@cam-orl.co.uk (Ian Jackson)
Newsgroups: comp.os.linux
Subject: Floppy driver default type - for SCSI and passworded BIOS
Summary: patch enclosed to enable you to make your system more secure
Keywords: floppy, fd, CMOS, BIOS, boot
Date: 18 Nov 92 14:22:02 GMT
Followup-To: comp.os.linux
Organization: Olivetti Research Ltd

Here is a small patch to floppy.c which allows the type of the first
floppy drive to have a default in the kernel in case the CMOS thinks
it's not present.

Linus would rather not put it in the default kernel as it is quite
specialised, so I'm posting it here for any interested people.

I find the patch useful because I live in a shared house and I don't
want anybody being able to boot my computer from a floppy and delete
all my files, send rude mail, etc. (taking the cover off the computer
is too extreme for them !).

Unfortunately, though I have a password-protected BIOS where I can
change the boot order the Adaptec SCSI BIOS (which I have to leave
enabled so I can boot from my SCSI disk) takes over the boot and
always tries the floppy first; I think that most SCSI controllers do
this.

The way round this is to configure the CMOS to record drive 'A' as
"none". Then the Adaptec always fails to boot from it.  Unfortunately
then you can't use the floppy, as Linux looks in the CMOS to find the
drive type - and that's where this patch comes in.

You define FD0_DEFAULT_TYPE (in config.{dist,site}.h or wherever) as
the number of the default drive type and it will use that if the CMOS
says there is no drive. If you don't define the special symbol
everything is just as before.

If you need to boot from floppy for any reason you go into the CMOS
setup (giving the CMOS password, of course) and change the drive type
back to whatever it should really be, and then you're away.

Unfortunately the patch results in yet another file depending on
config.h and thus on config.{dist,site}.h, but then such is life.

I changed it about four days ago and it has been working fine since.

The enclosed patch was between 0.98.3 without the emergency mount
patch and 0.98.5 with my modification, but I chopped out a spurious
difference by hand, so it should now be relative to 0.98.5. I don't
have RCS/CVS up yet so I haven't been able to check that.

Regards,
Ian Jackson.

*** floppy.c%	Tue Nov 17 00:57:10 1992
--- floppy.c	Tue Nov 17 00:57:06 1992
***************
*** 58,63 ****
--- 58,73 ----
   * floppy as the first thing after bootup.
   */
  
+ /* 14.11.92
+  * Added support for FD0_DEFAULT_TYPE, to allow use of fd0 even if
+  * not present in CMOS configuration. This is intended to allow people
+  * to prevent booting from floppy while still allowing access to the
+  * drive once booted, if you have a password-protected BIOS.
+  * This is needed even if you can change the boot order if you intend
+  * to boot from an Adaptec SCSI disk, as Adaptec's BIOS (which you have
+  * to leave switched on) will try the floppy anyway ! - Ian Jackson.
+  */
+ 
  #define REALLY_SLOW_IO
  #define FLOPPY_IRQ 6
  #define FLOPPY_DMA 2
***************
*** 69,74 ****
--- 79,85 ----
  #include <linux/fdreg.h>
  #include <linux/fd.h>
  #include <linux/errno.h>
+ #include <linux/config.h>
  
  #include <asm/dma.h>
  #include <asm/system.h>
***************
*** 1149,1154 ****
--- 1160,1176 ----
  		printk("fd%d is %s",drive,base->name);
  		return base;
  	}
+ #ifdef FD0_DEFAULT_TYPE
+ # if (FD0_DEFAULT_TYPE > 0) && (FD0_DEFAULT_TYPE < 5)
+ 	if (drive == 0 && code == 0) {
+ 	        base = &floppy_types[(FD0_DEFAULT_TYPE-1)*2];
+ 		printk("fd%d defaults to %s",drive,base->name);
+ 		return base;
+ 	}
+ # else
+ #  error FD0_DEFAULT_TYPE is out of range (1 to 4 is allowed)
+ # endif
+ #endif
  	printk("fd%d is unknown type %d",drive,code);
  	return NULL;
  }
-- 
Ian Jackson  iwj@cam-orl.co.uk ..!uknet!cam-orl!iwj  These opinions are my own.
Olivetti Research Ltd, Old Addenbrookes Site, Trumpington St, Cambridge, UK;
Home: 35 Molewood Close, Cambridge, CB4 3SR; +44 223 327029.     +44 223 343398