static void setupdevs() { int dirno = 0; char **srch_dirs; hashtab = malloc(NDEVS * sizeof (struct devhash)); if (hashtab == NULL) { (void) fprintf(stderr, gettext("No memory for device table\n")); return; } srch_dirs = get_pri_dirs(); while (srch_dirs[dirno] != NULL) { if (srch_dir(srch_dirs[dirno]) < 0) return; dirno++; } dirno = 0; while (srch_dirs[dirno] != NULL) { if (strcmp("/dev", srch_dirs[dirno]) == 0) /* * Don't search /dev twice. */ return; dirno++; } }
static char * _ttyname_common(struct stat64 *fsp, char *buffer, uint_t match_mask) { struct stat64 tfsb; const entry_t *srch_dirs; /* priority directories */ spcl_t *spclp; int i; int found = 0; int dirno = 0; int is_pts = 0; char *retval = NULL; char *pt = NULL; /* * We can't use lmutex_lock() here because we call malloc()/free() * and _libc_gettext(). Use the brute-force fork_lock_enter(). */ (void) fork_lock_enter(NULL); /* * match special cases */ for (spclp = special_case, i = 0; i < NUMSPECIAL; spclp++, i++) { if ((spclp->spcl_inum | spclp->spcl_fsdev | spclp->spcl_rdev) == 0) { if (stat64(spclp->spcl_name, &tfsb) != 0) continue; spclp->spcl_rdev = tfsb.st_rdev; spclp->spcl_fsdev = tfsb.st_dev; spclp->spcl_inum = tfsb.st_ino; } if (match_mask == MATCH_MM) { if (spclp->spcl_rdev == fsp->st_rdev) { retval = strcpy(rbuf, spclp->spcl_name); goto out; } } else if (spclp->spcl_fsdev == fsp->st_dev && spclp->spcl_rdev == fsp->st_rdev && spclp->spcl_inum == fsp->st_ino) { retval = strcpy(rbuf, spclp->spcl_name); goto out; } } /* * additional special case: ptm clone device * ptm devs have no entries in /dev * if major number matches, just short circuit any further lookup * NOTE: the minor number of /dev/ptmx is the ptm major number */ spclp = &ptmspecial; if ((spclp->spcl_inum | spclp->spcl_fsdev | spclp->spcl_rdev) == 0) { if (stat64(spclp->spcl_name, &tfsb) == 0) { spclp->spcl_rdev = tfsb.st_rdev; spclp->spcl_fsdev = tfsb.st_dev; spclp->spcl_inum = tfsb.st_ino; } } if ((spclp->spcl_rdev != 0) && (minor(spclp->spcl_rdev) == major(fsp->st_rdev))) goto out; /* * additional special case: pty dev * one of the known default pairs of /dev/ptyXX or /dev/ttyXX */ if ((retval = ispty(fsp, match_mask)) != NULL) goto out; /* * search the priority directories */ srch_dirs = get_pri_dirs(); dev_flag = 0; while ((!found) && (srch_dirs[dirno].name != NULL)) { /* * if /dev is one of the priority directories, only * search its top level(set depth = MAX_SEARCH_DEPTH) */ /* * Is /dev/pts then just do a quick check. We don't have * to stat the entire /dev/pts dir. */ if (strcmp(PTS, srch_dirs[dirno].name) == NULL) { if ((pt = ispts(fsp, match_mask)) != NULL) { is_pts = 1; found = 1; } } else { found = srch_dir(srch_dirs[dirno], match_mask, ((strcmp(srch_dirs[dirno].name, dev_dir.name) == 0) ? MAX_SRCH_DEPTH : 1), 0, fsp); } dirno++; } /* * search the /dev/ directory, skipping priority directories */ if (!found) found = srch_dir(dev_dir, match_mask, 0, srch_dirs, fsp); /* * return */ if (found) { if (is_pts) retval = pt; else retval = rbuf; } else if (dev_flag) retval = dev_rbuf; else retval = NULL; out: retval = (retval ? strcpy(buffer, retval) : NULL); fork_lock_exit(); return (retval); }