specify pathnames for includes
[unix-history] / usr / src / sys / stand.att / sys.c
index 494c9c6..7d93341 100644 (file)
@@ -1,17 +1,25 @@
 /*
 /*
- * Copyright (c) 1982 Regents of the University of California.
+ * Copyright (c) 1982, 1986 Regents of the University of California.
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)sys.c       6.6 (Berkeley) %G%
+ *     @(#)sys.c       7.8 (Berkeley) %G%
  */
 
  */
 
-#include "../h/param.h"
-#include "../h/inode.h"
-#include "../h/fs.h"
-#include "../h/dir.h"
+#include "sys/param.h"
+#include "sys/time.h"
+#include "sys/vnode.h"
+#include "ufs/inode.h"
+#include "ufs/fs.h"
+#include "ufs/dir.h"
+#include "sys/reboot.h"
 #include "saio.h"
 
 #include "saio.h"
 
+#define        isdigit(c)      ((u_int)((c) - '0') <= 9)
+#define        isspace(c)      ((c) == ' ' || (c) == '\t')
+#define        isupper(c)      ((u_int)((c) - 'A') <= 'Z' - 'A')
+#define        tolower(c)      ((c) - 'A' + 'a')
+
 ino_t  dlook();
 
 struct dirstuff {
 ino_t  dlook();
 
 struct dirstuff {
@@ -19,6 +27,8 @@ struct dirstuff {
        struct iob *io;
 };
 
        struct iob *io;
 };
 
+struct iob iob[NFILES];
+
 static
 openi(n, io)
        register struct iob *io;
 static
 openi(n, io)
        register struct iob *io;
@@ -42,10 +52,10 @@ find(path, file)
        struct iob *file;
 {
        register char *q;
        struct iob *file;
 {
        register char *q;
-       char c;
+       char *dir, c;
        int n;
 
        int n;
 
-       if (path==NULL || *path=='\0') {
+       if (path == NULL || *path == '\0') {
                printf("null path\n");
                return (0);
        }
                printf("null path\n");
                return (0);
        }
@@ -54,6 +64,7 @@ find(path, file)
                printf("can't read root inode\n");
                return (0);
        }
                printf("can't read root inode\n");
                return (0);
        }
+       dir = path;
        while (*path) {
                while (*path == '/')
                        path++;
        while (*path) {
                while (*path == '/')
                        path++;
@@ -64,7 +75,7 @@ find(path, file)
                *q = '\0';
                if (q == path) path = "." ;     /* "/" means "/." */
 
                *q = '\0';
                if (q == path) path = "." ;     /* "/" means "/." */
 
-               if ((n = dlook(path, file)) != 0) {
+               if ((n = dlook(path, file, dir)) != 0) {
                        if (c == '\0')
                                break;
                        if (openi(n, file) < 0)
                        if (c == '\0')
                                break;
                        if (openi(n, file) < 0)
@@ -80,6 +91,10 @@ find(path, file)
        return (n);
 }
 
        return (n);
 }
 
+#define        NBUFS   4
+static char    b[NBUFS][MAXBSIZE];
+static daddr_t blknos[NBUFS];
+
 static daddr_t
 sbmap(io, bn)
        register struct iob *io;
 static daddr_t
 sbmap(io, bn)
        register struct iob *io;
@@ -158,9 +173,10 @@ sbmap(io, bn)
 }
 
 static ino_t
 }
 
 static ino_t
-dlook(s, io)
+dlook(s, io, dir)
        char *s;
        register struct iob *io;
        char *s;
        register struct iob *io;
+       char *dir;
 {
        register struct direct *dp;
        register struct inode *ip;
 {
        register struct direct *dp;
        register struct inode *ip;
@@ -171,12 +187,11 @@ dlook(s, io)
                return (0);
        ip = &io->i_ino;
        if ((ip->i_mode&IFMT) != IFDIR) {
                return (0);
        ip = &io->i_ino;
        if ((ip->i_mode&IFMT) != IFDIR) {
-               printf("not a directory\n");
-               printf("%s: not a directory\n", s);
+               printf("%s: not a directory\n", dir);
                return (0);
        }
        if (ip->i_size == 0) {
                return (0);
        }
        if (ip->i_size == 0) {
-               printf("%s: zero length directory\n", s);
+               printf("%s: zero length directory\n", dir);
                return (0);
        }
        len = strlen(s);
                return (0);
        }
        len = strlen(s);
@@ -212,7 +227,7 @@ readdir(dirp)
                        lbn = lblkno(&io->i_fs, dirp->loc);
                        d = sbmap(io, lbn);
                        if(d == 0)
                        lbn = lblkno(&io->i_fs, dirp->loc);
                        d = sbmap(io, lbn);
                        if(d == 0)
-                               return NULL;
+                               return (NULL);
                        io->i_bn = fsbtodb(&io->i_fs, d) + io->i_boff;
                        io->i_ma = io->i_buf;
                        io->i_cc = blksize(&io->i_fs, &io->i_ino, lbn);
                        io->i_bn = fsbtodb(&io->i_fs, d) + io->i_boff;
                        io->i_ma = io->i_buf;
                        io->i_cc = blksize(&io->i_fs, &io->i_ino, lbn);
@@ -237,13 +252,13 @@ lseek(fdesc, addr, ptr)
 {
        register struct iob *io;
 
 {
        register struct iob *io;
 
-#ifndef        SMALL
-       if (ptr != 0) {
+#ifndef SMALL
+       if (ptr != L_SET) {
                printf("Seek not from beginning of file\n");
                errno = EOFFSET;
                return (-1);
        }
                printf("Seek not from beginning of file\n");
                errno = EOFFSET;
                return (-1);
        }
-#endif SMALL
+#endif
        fdesc -= 3;
        if (fdesc < 0 || fdesc >= NFILES ||
            ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) {
        fdesc -= 3;
        if (fdesc < 0 || fdesc >= NFILES ||
            ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) {
@@ -338,18 +353,19 @@ read(fdesc, buf, count)
                errno = EBADF;
                return (-1);
        }
                errno = EBADF;
                return (-1);
        }
-#ifndef        SMALL
+#ifndef SMALL
        if ((file->i_flgs & F_FILE) == 0) {
                file->i_cc = count;
                file->i_ma = buf;
                file->i_bn = file->i_boff + (file->i_offset / DEV_BSIZE);
                i = devread(file);
        if ((file->i_flgs & F_FILE) == 0) {
                file->i_cc = count;
                file->i_ma = buf;
                file->i_bn = file->i_boff + (file->i_offset / DEV_BSIZE);
                i = devread(file);
-               file->i_offset += count;
                if (i < 0)
                        errno = file->i_error;
                if (i < 0)
                        errno = file->i_error;
+               else
+                       file->i_offset += i;
                return (i);
        }
                return (i);
        }
-#endif SMALL
+#endif
        if (file->i_offset+count > file->i_ino.i_size)
                count = file->i_ino.i_size - file->i_offset;
        if ((i = count) <= 0)
        if (file->i_offset+count > file->i_ino.i_size)
                count = file->i_ino.i_size - file->i_offset;
        if ((i = count) <= 0)
@@ -389,7 +405,7 @@ read(fdesc, buf, count)
        return (count);
 }
 
        return (count);
 }
 
-#ifndef        SMALL
+#ifndef SMALL
 write(fdesc, buf, count)
        int fdesc, count;
        char *buf;
 write(fdesc, buf, count)
        int fdesc, count;
        char *buf;
@@ -423,181 +439,184 @@ write(fdesc, buf, count)
                errno = file->i_error;
        return (i);
 }
                errno = file->i_error;
        return (i);
 }
-#endif SMALL
+#endif
 
 int    openfirst = 1;
 
 int    openfirst = 1;
-#ifdef notyet
-int    opendev;        /* last device opened; for boot to set bootdev */
-extern int bootdev;
-#endif notyet
+u_int  opendev;                /* last device opened */
+extern u_int bootdev;
 
 open(str, how)
        char *str;
        int how;
 {
 
 open(str, how)
        char *str;
        int how;
 {
-       register char *cp;
-       int i;
+       register char *t;
+       register int cnt;
        register struct iob *file;
        register struct iob *file;
-       register struct devsw *dp;
-       int fdesc;
-       long atol();
+       int fdesc, args[8], *argp;
 
        if (openfirst) {
 
        if (openfirst) {
-               for (i = 0; i < NFILES; i++)
-                       iob[i].i_flgs = 0;
+               for (cnt = 0; cnt < NFILES; cnt++)
+                       iob[cnt].i_flgs = 0;
                openfirst = 0;
        }
 
                openfirst = 0;
        }
 
-       for (fdesc = 0; fdesc < NFILES; fdesc++)
-               if (iob[fdesc].i_flgs == 0)
-                       goto gotfile;
-       _stop("No more file slots");
-gotfile:
-       (file = &iob[fdesc])->i_flgs |= F_ALLOC;
-
-#ifdef notyet
-       for (cp = str; *cp && *cp != '/' && *cp != ':'; cp++)
-                       ;
-       if (*cp != ':') {
-               /* default bootstrap unit and device */
-               file->i_ino.i_dev = bootdev;
-               cp = str;
-       } else {
-# define isdigit(n)    ((n>='0') && (n<='9'))
-               /*
-                * syntax for possible device name:
-                *      <alpha-string><digit-string><letter>:
-                */
-               for (cp = str; *cp != ':' && !isdigit(*cp); cp++)
-                       ;
-               for (dp = devsw; dp->dv_name; dp++) {
-                       if (!strncmp(str, dp->dv_name,cp-str))
-                               goto gotdev;
-               }
-               printf("unknown device\n");
-               file->i_flgs = 0;
-               errno = EDEV;
-               return (-1);
-       gotdev:
-               i = 0;
-               while (*cp >= '0' && *cp <= '9')
-                       i = i * 10 + *cp++ - '0';
-               if (i < 0 || i > 255) {
-                       printf("minor device number out of range (0-255)\n");
-                       file->i_flgs = 0;
-                       errno = EUNIT;
-                       return (-1);
-               }
-               if (*cp >= 'a' && *cp <= 'h') {
-                       if (i > 31) {
-                               printf("unit number out of range (0-31)\n");
-                               file->i_flgs = 0;
-                               errno = EUNIT;
-                               return (-1);
-                       }
-                       i = make_minor(i, *cp++ - 'a');
+       for (fdesc = 0;; fdesc++) {
+               if (fdesc == NFILES)
+                       _stop("No more file slots");
+               if (iob[fdesc].i_flgs == 0) {
+                       file = &iob[fdesc];
+                       file->i_flgs |= F_ALLOC;
+                       file->i_adapt = file->i_ctlr = file->i_unit =
+                           file->i_part = 0;
+                       break;
                }
                }
+       }
 
 
-               if (*cp++ != ':') {
-                       printf("incorrect device specification\n");
-                       file->i_flgs = 0;
+       for (cnt = 0; cnt < sizeof(args)/sizeof(args[0]); args[cnt++] = 0);
+#ifndef SMALL
+       for (t = str; *t && *t != '/' && *t != ':' && *t != '('; ++t)
+               if (isupper(*t))
+                       *t = tolower(*t);
+       switch(*t) {
+       case '(':       /* type(adapt, ctlr, drive, partition)file */
+               if ((file->i_ino.i_dev = getdev(str, t - str)) == -1)
+                       goto bad;
+               for (argp = args + 4, cnt = 0; *t != ')'; ++cnt) {
+                       for (++t; isspace(*t); ++t);
+                       if (*t == ')')
+                               break;
+                       if (!isdigit(*t))
+                               goto badspec;
+                       *argp++ = atoi(t);
+                       for (++t; isdigit(*t); ++t);
+                       if (*t != ',' && *t != ')' || cnt == 4)
+                               goto badspec;
+               }
+               for (++t; isspace(*t); ++t);
+               argp -= 4;
+               file->i_adapt = *argp++;
+               file->i_ctlr = *argp++;
+               file->i_unit = *argp++;
+               file->i_part = *argp;
+               break;
+       case ':':       /* [A-Za-z]*[0-9]*[A-Za-z]:file */
+               for (t = str; *t != ':' && !isdigit(*t); ++t);
+               if ((file->i_ino.i_dev = getdev(str, t - str)) == -1)
+                       goto bad;
+               if ((file->i_unit = getunit(t)) == -1)
+                       goto bad;
+               for (; isdigit(*t); ++t);
+               if (*t >= 'a' && *t <= 'h')
+                       file->i_part = *t++ - 'a';
+               if (*t != ':') {
                        errno = EOFFSET;
                        errno = EOFFSET;
-                       return (-1);
+                       goto badspec;
                }
                }
-               opendev = file->i_ino.i_dev = makedev(dp-devsw, i);
-       }
-       file->i_boff = 0;
-       devopen(file);
-       if (cp != str && *cp == '\0') {
-               file->i_flgs |= how+1;
+               for (++t; isspace(*t); ++t);
+               break;
+       case '/':
+       default:                /* default bootstrap unit and device */
+#else
+       {
+#endif /* SMALL */
+               file->i_ino.i_dev = B_TYPE(bootdev);
+               file->i_adapt = B_ADAPTOR(bootdev);
+               file->i_ctlr = B_CONTROLLER(bootdev);
+               file->i_unit = B_UNIT(bootdev);
+               file->i_part = B_PARTITION(bootdev);
+               t = str;
+       }
+
+       opendev = MAKEBOOTDEV(file->i_ino.i_dev, file->i_adapt, file->i_ctlr,
+           file->i_unit, file->i_part);
+
+       if (errno = devopen(file))
+               goto bad;
+
+       if (*t == '\0') {
+               file->i_flgs |= how + 1;
                file->i_cc = 0;
                file->i_offset = 0;
                return (fdesc+3);
        }
                file->i_cc = 0;
                file->i_offset = 0;
                return (fdesc+3);
        }
-#else notyet
-       for (cp = str; *cp && *cp != '('; cp++)
-                       ;
-       if (*cp != '(') {
-               printf("Bad device\n");
-               file->i_flgs = 0;
-               errno = EDEV;
-               return (-1);
-       }
-       *cp++ = '\0';
-       for (dp = devsw; dp->dv_name; dp++) {
-               if (!strcmp(str, dp->dv_name))
-                       goto gotdev;
-       }
-       printf("Unknown device\n");
-       file->i_flgs = 0;
-       errno = ENXIO;
-       return (-1);
-gotdev:
-       *(cp-1) = '(';
-       file->i_ino.i_dev = dp-devsw;
-       file->i_unit = *cp++ - '0';
-       if (*cp >= '0' && *cp <= '9')
-               file->i_unit = file->i_unit * 10 + *cp++ - '0';
-       if (file->i_unit < 0 || file->i_unit > 63) {
-               printf("Bad unit specifier\n");
-               file->i_flgs = 0;
-               errno = EUNIT;
-               return (-1);
-       }
-       if (*cp++ != ',') {
-badoff:
-               printf("Missing offset specification\n");
-               file->i_flgs = 0;
-               errno = EOFFSET;
-               return (-1);
-       }
-       file->i_boff = atol(cp);
-       for (;;) {
-               if (*cp == ')')
-                       break;
-               if (*cp++)
-                       continue;
-               goto badoff;
-       }
-       devopen(file);
-       if (*++cp == '\0') {
-               file->i_flgs |= how+1;
-               file->i_cc = 0;
-               file->i_offset = 0;
-               return (fdesc+3);
+#ifndef SMALL
+       else if (how != 0) {
+               printf("Can't write files yet.. Sorry\n");
+               errno = EIO;
+               goto bad;
        }
        }
-#endif notyet
+#endif
        file->i_ma = (char *)(&file->i_fs);
        file->i_cc = SBSIZE;
        file->i_ma = (char *)(&file->i_fs);
        file->i_cc = SBSIZE;
-       file->i_bn = SBLOCK + file->i_boff;
+       file->i_bn = SBOFF / DEV_BSIZE + file->i_boff;
        file->i_offset = 0;
        if (devread(file) < 0) {
                errno = file->i_error;
                printf("super block read error\n");
        file->i_offset = 0;
        if (devread(file) < 0) {
                errno = file->i_error;
                printf("super block read error\n");
-               return (-1);
+               goto bad;
        }
        }
-       if ((i = find(cp, file)) == 0) {
-               file->i_flgs = 0;
+       if ((cnt = find(t, file)) == 0) {
                errno = ESRCH;
                errno = ESRCH;
-               return (-1);
+               goto bad;
        }
        }
-#ifndef        SMALL
-       if (how != 0) {
-               printf("Can't write files yet.. Sorry\n");
-               file->i_flgs = 0;
-               errno = EIO;
-               return (-1);
-       }
-#endif SMALL
-       if (openi(i, file) < 0) {
+       if (openi(cnt, file) < 0) {
                errno = file->i_error;
                errno = file->i_error;
-               return (-1);
+               goto bad;
        }
        file->i_offset = 0;
        file->i_cc = 0;
        file->i_flgs |= F_FILE | (how+1);
        return (fdesc+3);
        }
        file->i_offset = 0;
        file->i_cc = 0;
        file->i_flgs |= F_FILE | (how+1);
        return (fdesc+3);
+
+#ifndef SMALL
+badspec:
+       printf("malformed device specification\nusage: device(adaptor, controller, drive, partition)file\n");
+#endif
+bad:
+       file->i_flgs = 0;
+       return (-1);
+}
+
+#ifndef SMALL
+static
+getdev(str, len)
+       register char *str;
+       int len;
+{
+       register struct devsw *dp;
+       register int i;
+       char savedch = str[len];
+
+       str[len] = '\0';
+       for (dp = devsw, i = 0; i < ndevs; dp++, i++)
+               if (dp->dv_name && strcmp(str, dp->dv_name) == 0) {
+                       str[len] = savedch;
+                       return (i);
+               }
+       printf("Unknown device\nKnown devices are:\n");
+       for (dp = devsw, i = 0; i < ndevs; dp++, i++)
+               if (dp->dv_name)
+                       printf(" %s", dp->dv_name);
+       printf("\n");
+       errno = ENXIO;
+       return (-1);
+}
+
+static
+getunit(cp)
+       register char *cp;
+{
+       int unit;
+
+       unit = atoi(cp);
+       if ((u_int)unit > 255) {
+               printf("minor device number out of range (0-255)\n");
+               errno = EUNIT;
+               return (-1);
+       }
+       return (unit);
 }
 }
+#endif /* SMALL */
 
 close(fdesc)
        int fdesc;
 
 close(fdesc)
        int fdesc;
@@ -616,7 +635,7 @@ close(fdesc)
        return (0);
 }
 
        return (0);
 }
 
-#ifndef        SMALL
+#ifndef SMALL
 ioctl(fdesc, cmd, arg)
        int fdesc, cmd;
        char *arg;
 ioctl(fdesc, cmd, arg)
        int fdesc, cmd;
        char *arg;
@@ -660,7 +679,7 @@ ioctl(fdesc, cmd, arg)
                errno = file->i_error;
        return (error);
 }
                errno = file->i_error;
        return (error);
 }
-#endif SMALL
+#endif /* SMALL */
 
 exit()
 {
 
 exit()
 {