Check file open mode at ioctl.

Add debug option SRAM_DEBUG_DONTDOIT.
This commit is contained in:
minoura 1999-06-15 15:04:56 +00:00
parent 1501054824
commit cd06c07723
1 changed files with 24 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sram.c,v 1.5 1997/10/10 21:45:18 oki Exp $ */
/* $NetBSD: sram.c,v 1.6 1999/06/15 15:04:56 minoura Exp $ */
/*
* Copyright (c) 1994 Kazuhisa Shimizu.
@ -46,7 +46,8 @@ struct sram_softc sram_softc;
#ifdef DEBUG
#define SRAM_DEBUG_OPEN 0x01
#define SRAM_DEBUG_CLOSE 0x02
#define SRAM_DEBUG_IOCTL 0x03
#define SRAM_DEBUG_IOCTL 0x04
#define SRAM_DEBUG_DONTDOIT 0x08
int sramdebug = SRAM_DEBUG_IOCTL;
#endif
@ -93,6 +94,11 @@ sramopen(dev, flags)
}
su->flags |= SRF_OPEN;
if (flags & FREAD)
su->flags |= SRF_READ;
if (flags & FWRITE)
su->flags |= SRF_WRITE;
return (0);
}
@ -112,9 +118,12 @@ sramclose (dev, flags)
if (su->flags & SRF_OPEN) {
su->flags = 0;
}
su->flags &= ~(SRF_READ|SRF_WRITE);
}
extern
/*ARGSUSED*/
int
sramioctl (dev, cmd, data, flag, p)
@ -127,6 +136,7 @@ sramioctl (dev, cmd, data, flag, p)
int error = 0;
struct sram_io *sram_io;
register char *sramtop = IODEVbase->io_sram;
struct sram_softc *su = &sram_softc;
#ifdef DEBUG
if (sramdebug & SRAM_DEBUG_IOCTL)
@ -136,6 +146,8 @@ sramioctl (dev, cmd, data, flag, p)
switch (cmd) {
case SIOGSRAM:
if ((su->flags & SRF_READ) == 0)
return(EPERM);
#ifdef DEBUG
if (sramdebug & SRAM_DEBUG_IOCTL) {
printf("Sram ioctl SIOGSRAM address=%p\n", data);
@ -148,15 +160,23 @@ sramioctl (dev, cmd, data, flag, p)
bcopy(sramtop + sram_io->offset, &(sram_io->sram), SRAM_IO_SIZE);
break;
case SIOPSRAM:
if ((su->flags & SRF_WRITE) == 0)
return(EPERM);
#ifdef DEBUG
if (sramdebug & SRAM_DEBUG_IOCTL) {
printf("Sram ioctl SIOSSRAM address=%p\n", data);
printf("Sram ioctl SIOSSRAM offset=%x\n", sram_io->offset);
printf("Sram ioctl SIOPSRAM address=%p\n", data);
printf("Sram ioctl SIOPSRAM offset=%x\n", sram_io->offset);
}
#endif
if (sram_io == NULL ||
sram_io->offset + SRAM_IO_SIZE > SRAM_SIZE)
return(EFAULT);
#ifdef DEBUG
if (sramdebug & SRAM_DEBUG_DONTDOIT) {
printf ("Sram ioctl SIOPSRAM: skipping actual write\n");
break;
}
#endif
sysport.sramwp = 0x31;
bcopy(&(sram_io->sram), sramtop + sram_io->offset,SRAM_IO_SIZE);
sysport.sramwp = 0x00;