/* * gettty returns the user's tty number or ? if none. */ static char * gettty(psinfo_t *psinfo) { extern char *_ttyname_dev(dev_t, char *, size_t); static zoneid_t zid = -1; char devname[TTYNAME_MAX]; char *retval; if (zid == -1) zid = getzoneid(); if (psinfo->pr_ttydev == PRNODEV || psinfo->pr_zoneid != zid) return ("?"); if ((retval = devlookup(psinfo->pr_ttydev)) != NULL) return (retval); retval = _ttyname_dev(psinfo->pr_ttydev, devname, sizeof (devname)); return (devadd(retval, psinfo->pr_ttydev)); }
/* * Parse a device spec in one of two forms. * * dev(adapt, ctlr, unit, part)file * [A-Za-z]*[0-9]*[A-Za-z]:file * dev unit part */ int devparse(const char *fname, int *dev, int *adapt, int *ctlr, int *unit, int *part, char **file) { int i; char *s, *args[4]; /* get device name and make lower case */ for (s = (char *)fname; *s && *s != '/' && *s != ':' && *s != '('; s++) if (isupper(*s)) *s = tolower(*s); /* first form */ if (*s == '(') { /* lookup device and get index */ if ((*dev = devlookup(fname, s - fname)) < 0) goto baddev; /* tokenize device ident */ args[0] = ++s; for (args[0] = s, i = 1; *s && *s != ')'; s++) { if (*s == ',') args[i++] = ++s; } switch(i) { case 4: *adapt = atoi(args[0]); *ctlr = atoi(args[1]); *unit = atoi(args[2]); *part = atoi(args[3]); break; case 3: *ctlr = atoi(args[0]); *unit = atoi(args[1]); *part = atoi(args[2]); break; case 2: *unit = atoi(args[0]); *part = atoi(args[1]); break; case 1: *part = atoi(args[0]); break; case 0: break; } *file = ++s; } /* second form */ else if (*s == ':') { int temp; /* isolate device */ for (s = (char *)fname; *s != ':' && !isdigit(*s); s++); /* lookup device and get index */ if ((*dev = devlookup(fname, s - fname)) < 0) goto baddev; /* isolate unit */ if ((temp = atoi(s)) > 255) goto bad; *adapt = temp / 8; *ctlr = temp % 8; for (; isdigit(*s); s++); /* translate partition */ if (!ispart(*s)) goto bad; *part = *s++ - 'a'; if (*s != ':') goto bad; *file = ++s; } /* no device present */ else *file = (char *)fname; /* return the remaining unparsed part as the file to boot */ return(0); bad: usage(); baddev: return(-1); }