[comp.unix.microport] 286 Ramdisk driver for Microport

root@qetzal.UUCP (Admin) (12/15/87)

Hey gang - something new to keep you busy over the 
holidays. Thanks to Jon Zeeff. Enjoy! 
-rcw


/*
   Ram disk driver for Sys V.2 (microport)   V1.0
   Written by Jon Zeeff umix!b-tech!zeeff.
   Copyright 1987 Jon Zeeff
   You may use this in any manner provided that you leave this notice 
   intact and don't hold me responsible for any problems with it.

   Compile with cc -O -Ml -c ramdisk.c
   Make sure you have the new .h files from the linkkit installed.

   You need a master line like:
   rd	0	oc	b	rd	3	0	1

   And a dfile.wini line like:
   rd	0	1

   Make a new kernel according to the instructions and then:
   mknod /dev/dsk/ramdisk b 3 10
   mkfs /dev/dsk/ramdisk 1000:200 1 2 
   mount /dev/dsk/ramdisk /tmp

*/

#include <sys/signal.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/iobuf.h>
#include <sys/conf.h>
#include <sys/dir.h>
#include <sys/user.h>
#include <sys/utsname.h>
#include <sys/elog.h>
#include <sys/erec.h>
#include <sys/errno.h>
#include <sys/trap.h>
#include <sys/mmu.h>
#include <sys/seg.h>
#include <sys/map.h>

char *mapin();

int mem=0;		/* click address of our memory */
long amount;		/* how many bytes we use */

/*
   Allocate the number of 512 byte blocks specified by the minor number.
   Note: the minor number is first multiplied by 100.  A minor number of
   1 gives you a 51200 byte ram disk.
*/

rdopen(dev,flag)
int dev,flag;
{
if (mem) return;		/* already open */
amount = 100L * 512 * dev;

if ((mem = malloc(coremap,btoc(amount))) == 0) {
   printf("*** error in allocating memory for ram disk\n");
   u.u_error = ENOMEM;
}

}

rdclose(dev)
int dev;
{
/*  It might be nice to be able to get rid of a ram disk, but there is a 
    small problem in that it will be closed between doing a mkfs on it and
    mounting it.  You could get some process (sleep 500 < ramdisk) to keep
    it open while you do this.

if (mem) mfree(coremap,btoc(amount),mem);
mem = 0;
*/
}

rdstrategy(bp)
register struct buf *bp;
{
int x;
paddr_t trp;

/* Is someone trying to read/write beyond the end? */

if (bp->b_blkno * 512L + bp->b_bcount > amount) {
   bp->b_flags |= B_ERROR;
   bp->b_error |= ENXIO;
   bp->b_resid = bp->b_bcount;
   iodone(bp);
   return;
}

x = splbio();
trp = ctob((long)mem) + bp->b_blkno * 512L;

if (bp->b_flags & B_READ) 
   bcopy(mapin(trp,BUFSEL),bp->b_un.b_addr,bp->b_bcount); 
else
   bcopy(bp->b_un.b_addr,mapin(trp,BUFSEL),bp->b_bcount); 

splx(x);		
bp->b_resid = 0;
iodone(bp);
return;

}

rdprint()
{
/* don't ask me */
}



-- 
//////////////////286 Moderator -- comp.unix.microport\\\\\\\\\\\\\\\\\
Email to microport@uwspan for info on the newsgroup comp.unix.microport.
otherwise mail to microport@uwspan with a Subject containing one of:
386 286 Bug Source Merge or "Send Buglist" (rutgers!uwvax!uwspan!microport)