Print this page
7882 Add /dev/full , the always-full memory device
Reviewed by: Adam Stevko <adam.stevko@gmail.com>
Reviewed by: Toomas Soome <tsoome@me.com>

@@ -23,10 +23,11 @@
  * Use is subject to license terms.
  */
 
 /*
  * Copyright (c) 2015, Joyent, Inc.  All rights reserved.
+ * Copyright 2017 James S Blachly, MD <james.blachly@gmail.com>
  */
 
 /*
  * Memory special file
  */

@@ -158,10 +159,11 @@
                 { "mem",        M_MEM,          0,      NULL,   "all",  0640 },
                 { "kmem",       M_KMEM,         0,      NULL,   "all",  0640 },
                 { "allkmem",    M_ALLKMEM,      0,      "all",  "all",  0600 },
                 { "null",       M_NULL, PRIVONLY_DEV,   NULL,   NULL,   0666 },
                 { "zero",       M_ZERO, PRIVONLY_DEV,   NULL,   NULL,   0666 },
+                { "full",       M_FULL, PRIVONLY_DEV,   NULL,   NULL,   0666 },
         };
         kstat_t *ksp;
 
         mutex_init(&mm_lock, NULL, MUTEX_DEFAULT, NULL);
         mm_map = vmem_alloc(heap_arena, PAGESIZE, VM_SLEEP);

@@ -219,10 +221,11 @@
 mmopen(dev_t *devp, int flag, int typ, struct cred *cred)
 {
         switch (getminor(*devp)) {
         case M_NULL:
         case M_ZERO:
+        case M_FULL:
         case M_MEM:
         case M_KMEM:
         case M_ALLKMEM:
                 /* standard devices */
                 break;

@@ -245,10 +248,11 @@
     struct pollhead **phpp)
 {
         switch (getminor(dev)) {
         case M_NULL:
         case M_ZERO:
+        case M_FULL:
         case M_MEM:
         case M_KMEM:
         case M_ALLKMEM:
                 *reventsp = events & (POLLIN | POLLOUT | POLLPRI | POLLRDNORM |
                     POLLWRNORM | POLLRDBAND | POLLWRBAND);

@@ -436,10 +440,18 @@
                                     S_WRITE);
                         }
 
                         break;
 
+                case M_FULL:
+                        if (rw == UIO_WRITE) {
+                                error = ENOSPC;
+                                break;
+                        }
+                        /* else it's a read, fall through to zero case */
+                        /*FALLTHROUGH*/
+
                 case M_ZERO:
                         if (rw == UIO_READ) {
                                 label_t ljb;
 
                                 if (on_fault(&ljb)) {

@@ -825,10 +837,11 @@
         case M_KMEM:
         case M_ALLKMEM:
                 /* no longer supported with KPR */
                 return (-1);
 
+        case M_FULL:
         case M_ZERO:
                 /*
                  * We shouldn't be mmap'ing to /dev/zero here as
                  * mmsegmap() should have already converted
                  * a mapping request for this device to a mapping