Changed a few EFAIL to proper errno codes.
authorDavide Libenzi <dlibenzi@google.com>
Wed, 7 Oct 2015 17:37:24 +0000 (10:37 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 14 Oct 2015 18:51:21 +0000 (14:51 -0400)
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/x86/devarch.c
kern/drivers/dev/acpi.c
kern/drivers/dev/eventfd.c
kern/drivers/dev/pipe.c
kern/src/net/arp.c
kern/src/net/iproute.c
kern/src/net/nullmedium.c
kern/src/ns/dev.c
kern/src/ns/qio.c
kern/src/ns/sysfile.c
user/parlib/asynccall.c

index 071046c..777133c 100644 (file)
@@ -444,13 +444,13 @@ static long archwrite(struct chan *c, void *a, long n, int64_t offset)
                case Qgdb:
                        p = a;
                        if (n != 1)
-                               error(EFAIL, "Gdb: Write one byte, '1' or '0'");
+                               error(EINVAL, "Gdb: Write one byte, '1' or '0'");
                        if (*p == '1')
                                gdbactive = 1;
                        else if (*p == '0')
                                gdbactive = 0;
                        else
-                               error(EFAIL, "Gdb: must be 1 or 0");
+                               error(EINVAL, "Gdb: must be 1 or 0");
                        return 1;
 
                case Qiob:
@@ -517,7 +517,8 @@ static long cputyperead(struct chan *unused, void *a, long n, int64_t off)
 {
        char buf[512], *s, *e;
        int i, k;
-       error(EFAIL, "unimplemented");
+
+       error(ENOSYS, NULL);
 #if 0
        e = buf + sizeof buf;
        s = seprintf(buf, e, "%s %d\n", "AMD64", 0);
@@ -535,21 +536,21 @@ static long cputyperead(struct chan *unused, void *a, long n, int64_t off)
 static long rmemrw(int isr, void *a, long n, int64_t off)
 {
        if (off < 0)
-               error(EFAIL, "offset must be >= 0");
+               error(EINVAL, "offset must be >= 0");
        if (n < 0)
-               error(EFAIL, "count must be >= 0");
+               error(EINVAL, "count must be >= 0");
        if (isr) {
                if (off >= MB)
-                       error(EFAIL, "offset must be < 1MB");
+                       error(EINVAL, "offset must be < 1MB");
                if (off + n >= MB)
                        n = MB - off;
                memmove(a, KADDR((uint32_t) off), n);
        } else {
                /* realmode buf page ok, allow vga framebuf's access */
                if (off >= MB)
-                       error(EFAIL, "offset must be < 1MB");
+                       error(EINVAL, "offset must be < 1MB");
                if (off + n > MB && (off < 0xA0000 || off + n > 0xB0000 + 0x10000))
-                       error(EFAIL, "bad offset/count in write");
+                       error(EINVAL, "bad offset/count in write");
                memmove(KADDR((uint32_t) off), a, n);
        }
        return n;
index a7f96a4..7d15582 100644 (file)
@@ -1494,9 +1494,8 @@ static struct chan *acpiattach(char *spec)
         * This was written for the stock kernel.
         * This code must use 64 registers to be acpi ready in nix.
         */
-       if (acpiinit() < 0) {
-               error(EFAIL, "no acpi");
-       }
+       if (acpiinit() < 0)
+               error(ENOSYS, "no acpi");
 
        /*
         * should use fadt->xpm* and fadt->xgpe* registers for 64 bits.
@@ -1562,9 +1561,8 @@ static long acpiread(struct chan *c, void *a, long n, int64_t off)
                tlen = 32768;
                ttext = kzmalloc(tlen, 0);
        }
-       if (ttext == NULL) {
-               error(EFAIL, "acpiread: no memory");
-       }
+       if (ttext == NULL)
+               error(ENOMEM, "acpiread: no memory");
        q = c->qid.path;
        switch (q) {
                case Qdir:
@@ -1676,7 +1674,7 @@ static long acpiwrite(struct chan *c, void *a, long n, int64_t off)
                case CMgpe:
                        i = strtoul(cb->f[1], NULL, 0);
                        if (i >= ngpes)
-                               error(EFAIL, "gpe out of range");
+                               error(ERANGE, "gpe out of range");
                        kstrdup(&gpes[i].obj, cb->f[2]);
                        setgpeen(i, 1);
                        break;
index e914cdd..9155cf0 100644 (file)
@@ -161,10 +161,8 @@ static unsigned long efd_read_efd(struct eventfd *efd, struct chan *c)
        while (1) {
                old_count = atomic_read(&efd->counter);
                if (!old_count) {
-                       if (c->flag & O_NONBLOCK) {
-                               set_errno(EAGAIN);
-                               error(EFAIL, "Would block on #%s read", devname());
-                       }
+                       if (c->flag & O_NONBLOCK)
+                               error(EAGAIN, "Would block on #%s read", devname());
                        rendez_sleep(&efd->rv_readers, has_counts, efd);
                } else {
                        if (efd->flags & EFD_SEMAPHORE) {
@@ -219,10 +217,8 @@ static void efd_write_efd(struct eventfd *efd, unsigned long add_to,
                old_count = atomic_read(&efd->counter);
                new_count = old_count + add_to;
                if (new_count > EFD_MAX_VAL) {
-                       if (c->flag & O_NONBLOCK) {
-                               set_errno(EAGAIN);
-                               error(EFAIL, "Would block on #%s write", devname());
-                       }
+                       if (c->flag & O_NONBLOCK)
+                               error(EAGAIN, "Would block on #%s write", devname());
                        rendez_sleep(&efd->rv_writers, has_room, efd);
                } else {
                        if (atomic_cas(&efd->counter, old_count, new_count))
index 495a614..7928f96 100644 (file)
@@ -220,7 +220,8 @@ static struct chan *pipeopen(struct chan *c, int omode)
 
        if (c->qid.type & QTDIR) {
                if (omode & O_WRITE)
-                       error(EFAIL, "Can only open directories O_READ, mode is %o oct", omode);
+                       error(EINVAL, "Can only open directories O_READ, mode is %o oct",
+                                 omode);
                c->mode = openmode(omode);
                c->flag |= COPEN;
                c->offset = 0;
index 845cbe1..597c0a1 100644 (file)
@@ -462,7 +462,7 @@ int arpwrite(struct Fs *fs, char *s, int len)
                                else
                                        r = v6lookup(fs, ip, NULL);
                                if (r == NULL)
-                                       error(EFAIL, "Destination unreachable");
+                                       error(EHOSTUNREACH, "Destination unreachable");
                                m = r->rt.ifc->m;
                                n = parsemac(mac, f[2], m->maclen);
                                break;
index fed2487..093207f 100644 (file)
@@ -794,7 +794,7 @@ long routewrite(struct Fs *f, struct chan *c, char *p, int n)
                nexterror();
        }
        if (cb->nf < 1)
-               error(EFAIL, "short control request");
+               error(EINVAL, "short control request");
 
        if (strcmp(cb->f[0], "flush") == 0) {
                tag = cb->f[1];
index 4a175e8..452ccac 100644 (file)
@@ -13,8 +13,8 @@
 #include <smp.h>
 #include <ip.h>
 
-static void
-nullbind(struct Ipifc *unused_ipifc, int unused_int, char **unused_char_pp_t)
+static void nullbind(struct Ipifc *unused_ipifc, int unused_int,
+                                        char **unused_char_pp_t)
 {
        error(EFAIL, "cannot bind null device");
 }
@@ -23,9 +23,8 @@ static void nullunbind(struct Ipifc *unused_ipifc)
 {
 }
 
-static void
-nullbwrite(struct Ipifc *unused_ipifc, struct block *b, int unused_int,
-                  uint8_t * unused_uint8_p_t)
+static void nullbwrite(struct Ipifc *unused_ipifc, struct block *b,
+                                          int unused_int, uint8_t * unused_uint8_p_t)
 {
        error(EFAIL, "nullbwrite");
 }
index 9fa47e0..33d994f 100644 (file)
@@ -388,7 +388,7 @@ struct chan *devopen(struct chan *c, int omode, struct dirtab *tab, int ntab,
 Return:
        c->offset = 0;
        if ((c->qid.type & QTDIR) && (omode & O_WRITE))
-               error(EFAIL, "Tried opening dir with non-read-only mode %o", omode);
+               error(EACCES, "Tried opening dir with non-read-only mode %o", omode);
        c->mode = openmode(omode);
        c->flag |= COPEN;
        return c;
index 263abb7..d727a0f 100644 (file)
@@ -1282,8 +1282,7 @@ static bool qwait(struct queue *q)
                q->state |= Qstarve;
                if (q->state & Qnonblock) {
                        spin_unlock_irqsave(&q->lock);
-                       set_errno(EAGAIN);
-                       error(EFAIL, "queue empty");
+                       error(EAGAIN, "queue empty");
                }
                spin_unlock_irqsave(&q->lock);
                /* may throw an error() */
@@ -1658,8 +1657,7 @@ long qbwrite(struct queue *q, struct block *b)
                if (q->state & Qnonblock) {
                        spin_unlock_irqsave(&q->lock);
                        freeb(b);
-                       set_errno(EAGAIN);
-                       error(EFAIL, "queue full");
+                       error(EAGAIN, "queue full");
                }
        }
 
index 192481a..6aeb3d6 100644 (file)
@@ -75,7 +75,7 @@ long kchanio(void *vc, void *buf, int n, int mode)
        else if (mode == O_WRITE)
                r = devtab[c->type].write(c, buf, n, c->offset);
        else
-               error(EFAIL, "kchanio: use only O_READ xor O_WRITE");
+               error(ENOSYS, "kchanio: use only O_READ xor O_WRITE");
 
        spin_lock(&c->lock);
        c->offset += r;
index 29b3ef1..da73ba7 100644 (file)
@@ -186,7 +186,7 @@ int waiton_syscall(syscall_desc_t* desc)
 {
        int retval = 0;
        if (desc == NULL || desc->channel == NULL){
-               errno = EFAIL;
+               errno = EFAULT;
                return -1;
        }
        // Make sure we were given a desc with a non-NULL frontring.  This could
@@ -194,7 +194,7 @@ int waiton_syscall(syscall_desc_t* desc)
        syscall_front_ring_t *fr =  &desc->channel->sysfr;
        
        if (!fr){
-               errno = EFAIL;
+               errno = EFAULT;
                return -1;
        }
        printf("waiting %d\n", vcore_id());