Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x68k/dev Check file open mode at ioctl.



details:   https://anonhg.NetBSD.org/src/rev/46260f8e719f
branches:  trunk
changeset: 473688:46260f8e719f
user:      minoura <minoura%NetBSD.org@localhost>
date:      Tue Jun 15 15:04:56 1999 +0000

description:
Check file open mode at ioctl.
Add debug option SRAM_DEBUG_DONTDOIT.

diffstat:

 sys/arch/x68k/dev/sram.c |  28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

diffs (87 lines):

diff -r 9e13a38b8a3d -r 46260f8e719f sys/arch/x68k/dev/sram.c
--- a/sys/arch/x68k/dev/sram.c  Tue Jun 15 15:04:40 1999 +0000
+++ b/sys/arch/x68k/dev/sram.c  Tue Jun 15 15:04:56 1999 +0000
@@ -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 @@
 #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 @@
        }
 
        su->flags |= SRF_OPEN;
+       if (flags & FREAD)
+               su->flags |= SRF_READ;
+       if (flags & FWRITE)
+               su->flags |= SRF_WRITE;
+
        return (0);
 }
 
@@ -112,9 +118,12 @@
        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 @@
        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 @@
 
        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 @@
                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;



Home | Main Index | Thread Index | Old Index