{ -1, 1, 0 }, { NODEV, 0, 0 }, }; int dmmin, dmmax, dmtext; extern struct driver rddriver; extern struct driver sddriver; extern struct hp_ctlr hp_cinit[]; extern struct hp_device hp_dinit[]; struct genericconf { caddr_t gc_driver; char *gc_name; dev_t gc_root; } genericconf[] = { { (caddr_t)&rddriver, "rd", makedev(2, 0), }, { (caddr_t)&sddriver, "sd", makedev(4, 0), }, { 0 }, }; setconf() { register struct hp_ctlr *hc; register struct hp_device *hd; register struct genericconf *gc; register char *cp; int unit, swaponroot = 0; if (rootdev != NODEV) goto doswap; unit = 0;
int sysfs_disk_to_sg(int fd) { /* from an open block device, try find and open its corresponding * scsi_generic interface */ struct stat st; char path[256]; char sg_path[256]; char sg_major_minor[10]; char *c; DIR *dir; struct dirent *de; int major, minor, rv; if (fstat(fd, &st)) return -1; snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/device", major(st.st_rdev), minor(st.st_rdev)); dir = opendir(path); if (!dir) return -1; de = readdir(dir); while (de) { if (strncmp("scsi_generic:", de->d_name, strlen("scsi_generic:")) == 0) break; de = readdir(dir); } closedir(dir); if (!de) return -1; snprintf(sg_path, sizeof(sg_path), "%s/%s/dev", path, de->d_name); fd = open(sg_path, O_RDONLY); if (fd < 0) return fd; rv = read(fd, sg_major_minor, sizeof(sg_major_minor)); close(fd); if (rv < 0 || rv == sizeof(sg_major_minor)) return -1; else sg_major_minor[rv - 1] = '\0'; c = strchr(sg_major_minor, ':'); *c = '\0'; c++; major = strtol(sg_major_minor, NULL, 10); minor = strtol(c, NULL, 10); snprintf(path, sizeof(path), "/dev/.tmp.md.%d:%d:%d", (int) getpid(), major, minor); if (mknod(path, S_IFCHR|0600, makedev(major, minor))==0) { fd = open(path, O_RDONLY); unlink(path); return fd; } return -1; }
static int test_fn(int argc, char **argv) { FILE *f; int fd, tmpfs_fd; unsigned fs_cnt, fs_cnt_last = 0; again: fs_cnt = 0; f = fopen("/proc/self/mountinfo", "r"); if (!f) { fail("Can't open mountinfo"); return -1; } while (fgets(buf, sizeof(buf), f) != NULL) { char *mp = buf, *end; mp = strchr(mp, ' ') + 1; mp = strchr(mp, ' ') + 1; mp = strchr(mp, ' ') + 1; mp = strchr(mp, ' ') + 1; end = strchr(mp, ' '); *end = '\0'; if (!strcmp(mp, "/")) continue; if (!strcmp(mp, "/proc")) continue; umount(mp); fs_cnt++; } fclose(f); if (fs_cnt == 0) goto done; if (fs_cnt != fs_cnt_last) { fs_cnt_last = fs_cnt; goto again; } fail("Can't umount all the filesystems"); return -1; done: rmdir(MPTS_ROOT); if (mkdir(MPTS_ROOT, 0600) < 0) { fail("Can't make zdtm_sys"); return 1; } if (mount("none", MPTS_ROOT, "sysfs", 0, "") < 0) { fail("Can't mount sysfs"); return 1; } if (mount("none", MPTS_ROOT"/dev", "tmpfs", 0, "") < 0) { fail("Can't mount tmpfs"); return 1; } tmpfs_fd = open(MPTS_ROOT"/dev/test", O_WRONLY | O_CREAT); if (write(tmpfs_fd, "hello", 5) <= 0) { err("write() failed"); return 1; } if (mount("none", MPTS_ROOT"/kernel", "proc", 0, "") < 0) { fail("Can't mount proc"); return 1; } if (mount("none", MPTS_ROOT"/kernel/sys/fs/binfmt_misc", "binfmt_misc", 0, "") < 0) { fail("Can't mount proc"); return 1; } mknod("/dev/null", 0777 | S_IFCHR, makedev(1, 3)); setup_outfile(); fd = open(MPTS_ROOT"/kernel/meminfo", O_RDONLY); if (fd == -1) return 1; test_daemon(); test_waitsig(); /* this checks both -- sys and proc presence */ if (access(MPTS_ROOT"/kernel/meminfo", F_OK)) { fail("No proc after restore"); return 1; } pass(); return 0; }
/* * This is to fake out the console routines, while booting. * We could use directly the bugtty console, but we want to be able to * configure a kernel without bugtty since we do not necessarily need a * full-blown console driver. */ cons_decl(boot); struct consdev bootcons = { NULL, NULL, bootcngetc, bootcnputc, nullcnpollc, NULL, makedev(14, 0), CN_LOWPRI }; /* * Early console initialization: called early on from main, before vm init. * We want to stick to the BUG routines for now, and we'll switch to the * real console in cpu_startup(). */ void consinit() { cn_tab = NULL; cninit(); #if defined(DDB)
gboolean vfs_parse_ls_lga (const char *p, struct stat * s, char **filename, char **linkname, size_t * num_spaces) { int idx, idx2, num_cols; int i; char *p_copy = NULL; char *t = NULL; const char *line = p; size_t skipped; if (strncmp (p, "total", 5) == 0) return FALSE; if (!vfs_parse_filetype (p, &skipped, &s->st_mode)) goto error; p += skipped; if (*p == ' ') /* Notwell 4 */ p++; if (*p == '[') { if (strlen (p) <= 8 || p[8] != ']') goto error; /* Should parse here the Notwell permissions :) */ if (S_ISDIR (s->st_mode)) s->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP | S_IXOTH); else s->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR); p += 9; } else { size_t lc_skipped; mode_t perms; if (!vfs_parse_fileperms (p, &lc_skipped, &perms)) goto error; p += lc_skipped; s->st_mode |= perms; } p_copy = g_strdup (p); num_cols = vfs_split_text (p_copy); s->st_nlink = atol (columns[0]); if (s->st_nlink <= 0) goto error; if (!is_num (1)) s->st_uid = vfs_finduid (columns[1]); else s->st_uid = (uid_t) atol (columns[1]); /* Mhm, the ls -lg did not produce a group field */ for (idx = 3; idx <= 5; idx++) if (is_month (columns[idx], NULL) || is_week (columns[idx], NULL) || is_dos_date (columns[idx]) || is_localized_month (columns[idx])) break; if (idx == 6 || (idx == 5 && !S_ISCHR (s->st_mode) && !S_ISBLK (s->st_mode))) goto error; /* We don't have gid */ if (idx == 3 || (idx == 4 && (S_ISCHR (s->st_mode) || S_ISBLK (s->st_mode)))) idx2 = 2; else { /* We have gid field */ if (is_num (2)) s->st_gid = (gid_t) atol (columns[2]); else s->st_gid = vfs_findgid (columns[2]); idx2 = 3; } /* This is device */ if (S_ISCHR (s->st_mode) || S_ISBLK (s->st_mode)) { int maj, min; /* Corner case: there is no whitespace(s) between maj & min */ if (!is_num (idx2) && idx2 == 2) { /* cppcheck-suppress invalidscanf */ if (!is_num (++idx2) || sscanf (columns[idx2], " %d,%d", &maj, &min) != 2) goto error; } else { /* cppcheck-suppress invalidscanf */ if (!is_num (idx2) || sscanf (columns[idx2], " %d,", &maj) != 1) goto error; /* cppcheck-suppress invalidscanf */ if (!is_num (++idx2) || sscanf (columns[idx2], " %d", &min) != 1) goto error; } #ifdef HAVE_STRUCT_STAT_ST_RDEV s->st_rdev = makedev (maj, min); #endif s->st_size = 0; } else { /* Common file size */ if (!is_num (idx2)) goto error; s->st_size = (off_t) g_ascii_strtoll (columns[idx2], NULL, 10); #ifdef HAVE_STRUCT_STAT_ST_RDEV s->st_rdev = 0; #endif } idx = vfs_parse_filedate (idx, &s->st_mtime); if (!idx) goto error; /* Use resulting time value */ s->st_atime = s->st_ctime = s->st_mtime; /* s->st_dev and s->st_ino must be initialized by vfs_s_new_inode () */ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE s->st_blksize = 512; #endif #ifdef HAVE_STRUCT_STAT_ST_BLOCKS s->st_blocks = (s->st_size + 511) / 512; #endif if (num_spaces != NULL) { *num_spaces = column_ptr[idx] - column_ptr[idx - 1] - strlen (columns[idx - 1]); if (DIR_IS_DOTDOT (columns[idx])) vfs_parce_ls_final_num_spaces = *num_spaces; } for (i = idx + 1, idx2 = 0; i < num_cols; i++) if (strcmp (columns[i], "->") == 0) { idx2 = i; break; } if (((S_ISLNK (s->st_mode) || (num_cols == idx + 3 && s->st_nlink > 1))) /* Maybe a hardlink? (in extfs) */ && idx2) { if (filename) { *filename = g_strndup (p + column_ptr[idx], column_ptr[idx2] - column_ptr[idx] - 1); } if (linkname) { t = g_strdup (p + column_ptr[idx2 + 1]); *linkname = t; } } else { /* Extract the filename from the string copy, not from the columns * this way we have a chance of entering hidden directories like ". ." */ if (filename) { /* * filename = g_strdup (columns [idx++]); */ t = g_strdup (p + column_ptr[idx]); *filename = t; } if (linkname) *linkname = NULL; } if (t) { int p2 = strlen (t); if ((--p2 > 0) && (t[p2] == '\r' || t[p2] == '\n')) t[p2] = 0; if ((--p2 > 0) && (t[p2] == '\r' || t[p2] == '\n')) t[p2] = 0; } g_free (p_copy); return TRUE; error: { static int errorcount = 0; if (++errorcount < 5) { message (D_ERROR, _("Cannot parse:"), "%s", (p_copy && *p_copy) ? p_copy : line); } else if (errorcount == 5) message (D_ERROR, MSG_ERROR, _("More parsing errors will be ignored.")); } g_free (p_copy); return FALSE; }
static int bpf_movein(struct uio *uio, int linktype, struct mbuf **mp, struct sockaddr *sockp, int *datlen) { struct mbuf *m; int error; int len; uint8_t sa_family; int hlen; switch (linktype) { #if SLIP case DLT_SLIP: sa_family = AF_INET; hlen = 0; break; #endif /* SLIP */ case DLT_EN10MB: sa_family = AF_UNSPEC; /* XXX Would MAXLINKHDR be better? */ hlen = sizeof(struct ether_header); break; #if FDDI case DLT_FDDI: #if defined(__FreeBSD__) || defined(__bsdi__) sa_family = AF_IMPLINK; hlen = 0; #else sa_family = AF_UNSPEC; /* XXX 4(FORMAC)+6(dst)+6(src)+3(LLC)+5(SNAP) */ hlen = 24; #endif break; #endif /* FDDI */ case DLT_RAW: case DLT_NULL: sa_family = AF_UNSPEC; hlen = 0; break; #ifdef __FreeBSD__ case DLT_ATM_RFC1483: /* * en atm driver requires 4-byte atm pseudo header. * though it isn't standard, vpi:vci needs to be * specified anyway. */ sa_family = AF_UNSPEC; hlen = 12; /* XXX 4(ATM_PH) + 3(LLC) + 5(SNAP) */ break; #endif case DLT_PPP: sa_family = AF_UNSPEC; hlen = 4; /* This should match PPP_HDRLEN */ break; case DLT_APPLE_IP_OVER_IEEE1394: sa_family = AF_UNSPEC; hlen = sizeof(struct firewire_header); break; case DLT_IEEE802_11: /* IEEE 802.11 wireless */ sa_family = AF_IEEE80211; hlen = 0; break; default: return (EIO); } // LP64todo - fix this! len = uio_resid(uio); *datlen = len - hlen; if ((unsigned)len > MCLBYTES) return (EIO); if (sockp) { /* * Build a sockaddr based on the data link layer type. * We do this at this level because the ethernet header * is copied directly into the data field of the sockaddr. * In the case of SLIP, there is no header and the packet * is forwarded as is. * Also, we are careful to leave room at the front of the mbuf * for the link level header. */ if ((hlen + SOCKADDR_HDR_LEN) > sockp->sa_len) { return (EIO); } sockp->sa_family = sa_family; } else { /* * We're directly sending the packet data supplied by * the user; we don't need to make room for the link * header, and don't need the header length value any * more, so set it to 0. */ hlen = 0; } MGETHDR(m, M_WAIT, MT_DATA); if (m == 0) return (ENOBUFS); if ((unsigned)len > MHLEN) { #if BSD >= 199103 MCLGET(m, M_WAIT); if ((m->m_flags & M_EXT) == 0) { #else MCLGET(m); if (m->m_len != MCLBYTES) { #endif error = ENOBUFS; goto bad; } } m->m_pkthdr.len = m->m_len = len; m->m_pkthdr.rcvif = NULL; *mp = m; /* * Make room for link header. */ if (hlen != 0) { m->m_pkthdr.len -= hlen; m->m_len -= hlen; #if BSD >= 199103 m->m_data += hlen; /* XXX */ #else m->m_off += hlen; #endif error = UIOMOVE((caddr_t)sockp->sa_data, hlen, UIO_WRITE, uio); if (error) goto bad; } error = UIOMOVE(mtod(m, caddr_t), len - hlen, UIO_WRITE, uio); if (!error) return (0); bad: m_freem(m); return (error); } #ifdef __APPLE__ /* * The dynamic addition of a new device node must block all processes that are opening * the last device so that no process will get an unexpected ENOENT */ static void bpf_make_dev_t(int maj) { static int bpf_growing = 0; unsigned int cur_size = nbpfilter, i; if (nbpfilter >= bpf_maxdevices) return; while (bpf_growing) { /* Wait until new device has been created */ (void)tsleep((caddr_t)&bpf_growing, PZERO, "bpf_growing", 0); } if (nbpfilter > cur_size) { /* other thread grew it already */ return; } bpf_growing = 1; /* need to grow bpf_dtab first */ if (nbpfilter == bpf_dtab_size) { int new_dtab_size; struct bpf_d **new_dtab = NULL; struct bpf_d **old_dtab = NULL; new_dtab_size = bpf_dtab_size + NBPFILTER; new_dtab = (struct bpf_d **)_MALLOC(sizeof(struct bpf_d *) * new_dtab_size, M_DEVBUF, M_WAIT); if (new_dtab == 0) { printf("bpf_make_dev_t: malloc bpf_dtab failed\n"); goto done; } if (bpf_dtab) { bcopy(bpf_dtab, new_dtab, sizeof(struct bpf_d *) * bpf_dtab_size); } bzero(new_dtab + bpf_dtab_size, sizeof(struct bpf_d *) * NBPFILTER); old_dtab = bpf_dtab; bpf_dtab = new_dtab; bpf_dtab_size = new_dtab_size; if (old_dtab != NULL) _FREE(old_dtab, M_DEVBUF); } i = nbpfilter++; (void) devfs_make_node(makedev(maj, i), DEVFS_CHAR, UID_ROOT, GID_WHEEL, 0600, "bpf%d", i); done: bpf_growing = 0; wakeup((caddr_t)&bpf_growing); } #endif /* * Attach file to the bpf interface, i.e. make d listen on bp. */ static errno_t bpf_attachd(struct bpf_d *d, struct bpf_if *bp) { int first = bp->bif_dlist == NULL; int error = 0; /* * Point d at bp, and add d to the interface's list of listeners. * Finally, point the driver's bpf cookie at the interface so * it will divert packets to bpf. */ d->bd_bif = bp; d->bd_next = bp->bif_dlist; bp->bif_dlist = d; if (first) { /* Find the default bpf entry for this ifp */ if (bp->bif_ifp->if_bpf == NULL) { struct bpf_if *primary; for (primary = bpf_iflist; primary && primary->bif_ifp != bp->bif_ifp; primary = primary->bif_next) ; bp->bif_ifp->if_bpf = primary; } /* Only call dlil_set_bpf_tap for primary dlt */ if (bp->bif_ifp->if_bpf == bp) dlil_set_bpf_tap(bp->bif_ifp, BPF_TAP_INPUT_OUTPUT, bpf_tap_callback); if (bp->bif_tap) error = bp->bif_tap(bp->bif_ifp, bp->bif_dlt, BPF_TAP_INPUT_OUTPUT); } return error; }
int main(int argc, char **argv) { struct fwr rule; int fd, ret, f = 0; exec = argv[0]; if (argc < 2) { print_usage(); return -1; } if (!strcmp(argv[1], "mknod") && argc == 2) { if (mknod(IPFIREWALL_DEV, S_IFCHR, makedev(IPFIREWALL_MAJOR, 0)) < 0) { perror("mknod " IPFIREWALL_DEV); return -1; } return 0; } if (!strcmp(argv[1], "unlink") && argc == 2) { if (unlink(IPFIREWALL_DEV) < 0) { perror("unlink " IPFIREWALL_DEV); return -1; } return 0; } if (!strcmp(argv[1], "insmod") && argc == 2) { if (system_check("insmod " IPFIREWALL_MOD IPFIREWALL_MOD_EXT) < 0) return -1; return 0; } if (!strcmp(argv[1], "rmmod") && argc == 2) { if (system_check("rmmod " IPFIREWALL_MOD) < 0) return -1; return 0; } fd = open(IPFIREWALL_DEV, O_RDWR); if (fd < 0) { perror("open " IPFIREWALL_DEV); return -1; } if (!strcmp(argv[1], "test") && argc == 2) { close(fd); return 0; } if (!strcmp(argv[1], "invalid") && argc == 2) { if (ioctl(fd, 42, NULL) < 0) { if (errno != ENOTTY) { perror("ioctl 42"); close(fd); return -1; } close(fd); return 0; } perror("ioctl 42"); close(fd); return -1; } if (!strcmp(argv[1], "enable") && argc == 2) { if (ioctl(fd, FW_ENABLE, NULL) < 0) { perror("ioctl FW_ENABLE"); close(fd); return -1; } close(fd); return 0; } if (!strcmp(argv[1], "disable") && argc == 2) { if (ioctl(fd, FW_DISABLE, NULL) < 0) { perror("ioctl FW_DISABLE"); close(fd); return -1; } close(fd); return 0; } if ((!strcmp(argv[1], "add") || !strcmp(argv[1], "find")) && argc == 6) { parse_ip(argv[2], &rule.ip_src, &rule.ip_src_mask); parse_ip(argv[3], &rule.ip_dst, &rule.ip_dst_mask); parse_range(argv[4], &rule.port_src[0], &rule.port_src[1]); parse_range(argv[5], &rule.port_dst[0], &rule.port_dst[1]); if (argv[1][0] == 'a') { /* add rule */ if (ioctl(fd, FW_ADD_RULE, &rule) < 0) { perror("ioctl FW_ADD_RULE"); close(fd); return -1; } close(fd); return 0; } f = 1; } if (f || (!strcmp(argv[1], "list") && argc == 2)) { struct fwr *fwr = NULL; int size, i; do { size = 0; if (ioctl(fd, FW_LIST, &size) < 0 && errno != ENOSPC) { perror("ioctl FW_LIST"); close(fd); return -1; } fwr = (struct fwr *) realloc(fwr, size * sizeof(struct fwr)); if (!fwr) { fprintf(stderr, "out of memory\n"); close(fd); return -1; } *(int*) fwr = size; size = ioctl(fd, FW_LIST, fwr); if (size < 0 && errno != ENOSPC) { perror("ioctl FW_LIST"); close(fd); return -1; } } while (size < 0); close(fd); if (f) { /* find rule */ ret = -1; for (i = 0; i < size && ret; i++) if (!memcmp(&fwr[i], &rule, sizeof(struct fwr))) ret = 0; if (ret) fprintf(stderr, "rule not found\n"); } else { /* list rules */ ret = size; for (i = 0; i < size; i++) printf(NIPQUAD_FMT "/%d " NIPQUAD_FMT "/%d %d:%d %d:%d\n", NIPQUAD(fwr[i].ip_src), mask_len(fwr[i].ip_src_mask), NIPQUAD(fwr[i].ip_dst), mask_len(fwr[i].ip_dst_mask), ntohs(fwr[i].port_src[0]), ntohs(fwr[i].port_src[1]), ntohs(fwr[i].port_dst[0]), ntohs(fwr[i].port_dst[1])); } if (fwr) free(fwr); return ret; } print_usage(); close(fd); return -1; }
int tusbopen() { dev_t devt; struct stat st; int rc = 0; devt = makedev(TUSB_MAJOR, 0); if (rc) { if (errno == ENOENT) { /* dev node does not exist. */ rc = mkdir(DEVICE_NAME, (S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)); } else { printf("ERROR: Problem with Base dev directory. Error code from stat() is %d\n\n", errno); } } else { if (!(st.st_mode & S_IFDIR)) { rc = unlink(DEVICE_NAME); if (!rc) { rc = mkdir(DEVICE_NAME, (S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)); } } } /* * Check for the /dev/tbase node, and create if it does not * exist. */ rc = stat(DEVICE_NAME, &st); if (rc) { if (errno == ENOENT) { /* dev node does not exist */ rc = mknod(DEVICE_NAME, (S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP), devt); } else { printf("ERROR:Problem with tbase device node directory. Error code form stat() is %d\n\n", errno); } } else { /* * /dev/tbase CHR device exists. Check to make sure it is for a * block device and that it has the right major and minor. */ if ((!(st.st_mode & S_IFCHR)) || (st.st_rdev != devt)) { /* Recreate the dev node. */ rc = unlink(DEVICE_NAME); if (!rc) { rc = mknod(DEVICE_NAME, (S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP), devt); } } } tusb_fd = open(DEVICE_NAME, O_RDWR); if (tusb_fd < 0) { printf("ERROR: Open of device %s failed %d errno = %d\n", DEVICE_NAME,tusb_fd, errno); return errno; } else { printf("Device opened successfully \n"); return 0; } }
static bool rm_mounts_create_tables(RmMountTable *self) { /* partition dev_t to disk dev_t */ self->part_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)rm_part_info_free); /* disk dev_t to boolean indication if disk is rotational */ self->disk_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)rm_disk_info_free); self->nfs_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); /* Mapping dev_t => true (used as set) */ self->evilfs_table = g_hash_table_new(NULL, NULL); RmMountEntry *entry = NULL; RmMountEntries *mnt_entries = rm_mount_list_open(self); if(mnt_entries == NULL) { return false; } while((entry = rm_mount_list_next(mnt_entries))) { RmStat stat_buf_folder; if(rm_sys_stat(entry->dir, &stat_buf_folder) == -1) { continue; } dev_t whole_disk = 0; gchar is_rotational = true; char diskname[PATH_MAX]; memset(diskname, 0, sizeof(diskname)); RmStat stat_buf_dev; if(rm_sys_stat(entry->fsname, &stat_buf_dev) == -1) { char *nfs_marker = NULL; /* folder rm_sys_stat() is ok but devname rm_sys_stat() is not; this happens for example * with tmpfs and with nfs mounts. Try to handle a few such cases. * */ if(rm_mounts_is_ramdisk(entry->fsname)) { strncpy(diskname, entry->fsname, sizeof(diskname)); is_rotational = false; whole_disk = stat_buf_folder.st_dev; } else if((nfs_marker = strstr(entry->fsname, ":/")) != NULL) { size_t until_slash = MIN((int)sizeof(entry->fsname), nfs_marker - entry->fsname); strncpy(diskname, entry->fsname, until_slash); is_rotational = true; /* Assign different dev ids (with major id 0) to different nfs servers */ if(!g_hash_table_contains(self->nfs_table, diskname)) { g_hash_table_insert(self->nfs_table, g_strdup(diskname), NULL); } whole_disk = makedev(0, g_hash_table_size(self->nfs_table)); } else { strncpy(diskname, "unknown", sizeof(diskname)); is_rotational = true; whole_disk = 0; } } else { if(rm_mounts_devno_to_wholedisk( entry, stat_buf_dev.st_rdev, diskname, sizeof(diskname), &whole_disk ) == -1) { /* folder and devname rm_sys_stat() are ok but blkid failed; this happens when? * Treat as a non-rotational device using devname dev as whole_disk key * */ rm_log_debug(RED"devno_to_wholedisk failed for %s\n"RESET, entry->fsname); whole_disk = stat_buf_dev.st_dev; strncpy(diskname, entry->fsname, sizeof(diskname)); is_rotational = false; } else { is_rotational = rm_mounts_is_rotational_blockdev(diskname); } } g_hash_table_insert( self->part_table, GUINT_TO_POINTER(stat_buf_folder.st_dev), rm_part_info_new (entry->dir, whole_disk)); /* small hack, so also the full disk id can be given to the api below */ if (!g_hash_table_contains(self->part_table, GINT_TO_POINTER(whole_disk))) { g_hash_table_insert( self->part_table, GUINT_TO_POINTER(whole_disk), rm_part_info_new (entry->dir, whole_disk)); } if (!g_hash_table_contains(self->disk_table, GINT_TO_POINTER(whole_disk))) { g_hash_table_insert( self->disk_table, GINT_TO_POINTER(whole_disk), rm_disk_info_new(diskname, is_rotational)); } rm_log_info("%02u:%02u %50s -> %02u:%02u %-12s (underlying disk: %s; rotational: %3s\n)", major(stat_buf_folder.st_dev), minor(stat_buf_folder.st_dev), entry->dir, major(whole_disk), minor(whole_disk), entry->fsname, diskname, is_rotational ? "yes" : "no" ); } #if HAVE_SYSCTL if(DISK_TABLE) { g_hash_table_unref(DISK_TABLE); } #endif rm_mount_list_close(mnt_entries); return true; }
vaddr_t mips_init(uint64_t, uint64_t, uint64_t, uint64_t, char *); extern void loongson2e_setup(u_long, u_long); extern void loongson2f_setup(u_long, u_long); extern void loongson3a_setup(u_long, u_long); cons_decl(pmon); struct consdev pmoncons = { NULL, NULL, pmoncngetc, pmoncnputc, nullcnpollc, NULL, makedev(0, 0), CN_DEAD }; /* * List of supported system types, from the ``Version'' environment * variable. */ struct bonito_flavour { const char *prefix; const struct platform *platform; }; extern const struct platform ebenton_platform; extern const struct platform fuloong_platform;
static void s_mknod(const char *pathname, mode_t type, unsigned int maj, unsigned int min) { mknod(pathname, type, makedev(maj, min)); }
/* * Try to detect the real device(s) used for the system console * /dev/console if but only if /dev/console is used. On Linux * this can be more than one device, e.g. a serial line as well * as a virtual console as well as a simple printer. * * Returns 1 if stdout and stderr should be reconnected and 0 * otherwise. */ int detect_consoles(const char *device, int fallback) { int fd, ret = 0; #ifdef __linux__ char *attrib, *cmdline; FILE *fc; #endif if (!device || *device == '\0') fd = dup(fallback); else { fd = open(device, O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC); ret = 1; } if (fd >= 0) { DIR *dir; char *name; struct stat st; #ifdef TIOCGDEV unsigned int devnum; #endif if (fstat(fd, &st) < 0) { close(fd); goto fallback; } comparedev = st.st_rdev; if (ret && (fstat(fallback, &st) < 0 || comparedev != st.st_rdev)) dup2(fd, fallback); #ifdef __linux__ /* * Check if the device detection for Linux system console should be used. */ if (comparedev == makedev(TTYAUX_MAJOR, 0)) { /* /dev/tty */ close(fd); device = "/dev/tty"; goto fallback; } if (comparedev == makedev(TTYAUX_MAJOR, 1)) { /* /dev/console */ close(fd); goto console; } if (comparedev == makedev(TTYAUX_MAJOR, 2)) { /* /dev/ptmx */ close(fd); device = "/dev/tty"; goto fallback; } if (comparedev == makedev(TTY_MAJOR, 0)) { /* /dev/tty0 */ struct vt_stat vt; if (ioctl(fd, VT_GETSTATE, &vt) < 0) { close(fd); goto fallback; } comparedev = makedev(TTY_MAJOR, (int)vt.v_active); } #endif #ifdef TIOCGDEV if (ioctl (fd, TIOCGDEV, &devnum) < 0) { close(fd); goto fallback; } comparedev = (dev_t)devnum; #endif close(fd); dir = opendir("/dev"); if (!dir) goto fallback; name = scandev(dir); if (name) consalloc(name); closedir(dir); if (!consoles) goto fallback; return ret; } #ifdef __linux__ console: /* * Detection of devices used for Linux system consolei using * the /proc/consoles API with kernel 2.6.38 and higher. */ if ((fc = fopen("/proc/consoles", "re"))) { char fbuf[16]; int maj, min; DIR *dir; dir = opendir("/dev"); if (!dir) { fclose(fc); goto fallback; } while ((fscanf(fc, "%*s %*s (%[^)]) %d:%d", &fbuf[0], &maj, &min) == 3)) { char * name; if (!strchr(fbuf, 'E')) continue; comparedev = makedev(maj, min); name = scandev(dir); if (!name) continue; consalloc(name); } closedir(dir); fclose(fc); return ret; } /* * Detection of devices used for Linux system console using * the sysfs /sys/class/tty/ API with kernel 2.6.37 and higher. */ if ((attrib = actattr("console"))) { char *words = attrib, *token; DIR *dir; dir = opendir("/dev"); if (!dir) { free(attrib); goto fallback; } while ((token = strsep(&words, " \t\r\n"))) { char * name; if (*token == '\0') continue; comparedev = devattr(token); if (comparedev == makedev(TTY_MAJOR, 0)) { char *tmp = actattr(token); if (!tmp) continue; comparedev = devattr(tmp); free(tmp); } name = scandev(dir); if (!name) continue; consalloc(name); } closedir(dir); free(attrib); if (!consoles) goto fallback; return ret; } /* * Detection of devices used for Linux system console using * kernel parameter on the kernels command line. */ if ((cmdline = oneline("/proc/cmdline"))) { char *words= cmdline, *token; DIR *dir; dir = opendir("/dev"); if (!dir) { free(cmdline); goto fallback; } while ((token = strsep(&words, " \t\r\n"))) { #ifdef TIOCGDEV unsigned int devnum; #else struct vt_stat vt; struct stat st; #endif char *colon, *name; if (*token != 'c') continue; if (strncmp(token, "console=", 8) != 0) continue; token += 8; if (strcmp(token, "brl") == 0) token += 4; if ((colon = strchr(token, ','))) *colon = '\0'; if (asprintf(&name, "/dev/%s", token) < 0) continue; if ((fd = open(name, O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC)) < 0) { free(name); continue; } free(name); #ifdef TIOCGDEV if (ioctl (fd, TIOCGDEV, &devnum) < 0) { close(fd); continue; } comparedev = (dev_t)devnum; #else if (fstat(fd, &st) < 0) { close(fd); continue; } comparedev = st.st_rdev; if (comparedev == makedev(TTY_MAJOR, 0)) { if (ioctl(fd, VT_GETSTATE, &vt) < 0) { close(fd); continue; } comparedev = makedev(TTY_MAJOR, (int)vt.v_active); } #endif close(fd); name = scandev(dir); if (!name) continue; consalloc(name); } closedir(dir); free(cmdline); /* * Detection of the device used for Linux system console using * the ioctl TIOCGDEV if available (e.g. official 2.6.38). */ if (!consoles) { #ifdef TIOCGDEV unsigned int devnum; const char *name; if (!device || *device == '\0') fd = dup(fallback); else fd = open(device, O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC); if (fd < 0) goto fallback; if (ioctl (fd, TIOCGDEV, &devnum) < 0) { close(fd); goto fallback; } comparedev = (dev_t)devnum; close(fd); if (device && *device != '\0') name = device; else name = ttyname(fallback); if (!name) name = "/dev/tty1"; consalloc(strdup(name)); if (consoles) { if (!device || *device == '\0') consoles->fd = fallback; return ret; } #endif goto fallback; } return ret; } #endif /* __linux __ */ fallback: if (fallback >= 0) { const char *name; if (device && *device != '\0') name = device; else name = ttyname(fallback); if (!name) name = "/dev/tty"; consalloc(strdup(name)); if (consoles) consoles->fd = fallback; } return ret; }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; mknod("/dev/gpio",S_IFCHR|0644,makedev(127,0)); mkdir("/usr/local",0700); mkdir("/usr/local/nvram",0700); install_sdcard(); cprintf("sysinit() setup console\n"); eval("insmod", "ks8695_wdt", "wdt_time=30"); // load watchdog module with 30 seconds timeout if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); /* * network drivers */ eval("ifconfig", "eth0", "up"); eval("ifconfig", "eth1", "up"); eval("ifconfig", "eth2", "up"); eval("ifconfig", "eth3", "up"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); system2("echo 1 >/proc/sys/dev/wifi0/softled"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); //disable led's return; cprintf("done\n"); }
int openCharacterDevice (const char *name, int flags, int major, int minor) { char *path = getDevicePath(name); int descriptor; if (!path) { descriptor = -1; } else if ((descriptor = open(path, flags)) != -1) { logMessage(LOG_DEBUG, "device opened: %s: fd=%d", path, descriptor); } else { logMessage(LOG_DEBUG, "cannot open device: %s: %s", path, strerror(errno)); if (errno == ENOENT) { free(path); if ((path = makeWritablePath(locatePathName(name)))) { if ((descriptor = open(path, flags)) != -1) { logMessage(LOG_DEBUG, "device opened: %s: fd=%d", path, descriptor); } else { logMessage(LOG_DEBUG, "cannot open device: %s: %s", path, strerror(errno)); if (errno == ENOENT) { mode_t mode = S_IFCHR | S_IRUSR | S_IWUSR; if (mknod(path, mode, makedev(major, minor)) == -1) { logMessage(LOG_DEBUG, "cannot create device: %s: %s", path, strerror(errno)); } else { logMessage(LOG_DEBUG, "device created: %s mode=%06o major=%d minor=%d", path, mode, major, minor); if ((descriptor = open(path, flags)) != -1) { logMessage(LOG_DEBUG, "device opened: %s: fd=%d", path, descriptor); } else { logMessage(LOG_DEBUG, "cannot open device: %s: %s", path, strerror(errno)); } } } } } } } if (descriptor != -1) { int ok = 0; struct stat status; if (fstat(descriptor, &status) == -1) { logMessage(LOG_DEBUG, "cannot fstat device: %d [%s]: %s", descriptor, path, strerror(errno)); } else if (!S_ISCHR(status.st_mode)) { logMessage(LOG_DEBUG, "not a character device: %s: fd=%d", path, descriptor); } else { ok = 1; } if (!ok) { close(descriptor); logMessage(LOG_DEBUG, "device closed: %s: fd=%d", path, descriptor); descriptor = -1; } } if (path) free(path); return descriptor; }
int fstat(int fd, struct stat *st) { int ret; struct linux_stat lst; struct ifreq ifr; ret = syscall(SYS_fstat, fd, &lst); if (ret == -1) { errno = EBADF; return -1; } st->st_size = lst.st_size; switch (lst.st_mode & LINUX_S_IFMT) { case LINUX_S_IFSOCK: __platform_socket_fd = fd; /* currently no support for raw socket networking */ lst.st_mode = 0; break; case LINUX_S_IFBLK: syscall(SYS_ioctl, fd, BLKGETSIZE64, &st->st_size); break; case LINUX_S_IFCHR: /* macvtap has a dynamic major number, so hard to test */ if (lst.st_rdev != makedev(10, 200) && major(lst.st_rdev) < 128) break; ret = syscall(SYS_ioctl, fd, TUNGETIFF, &ifr); if (ret == 0) { /* we do not yet support macvtap offload facilities */ if (ifr.ifr_flags & IFF_VNET_HDR) { ifr.ifr_flags &= ~IFF_VNET_HDR; syscall(SYS_ioctl, fd, TUNSETIFF, &ifr); } /* use sock type to tell config we are network */ lst.st_mode = LINUX_S_IFSOCK; /* find mac address */ ret = syscall(SYS_ioctl, fd, SIOCGIFHWADDR, &ifr); if (ret == -1 && __platform_socket_fd != -1) ret = syscall(SYS_ioctl, __platform_socket_fd, SIOCGIFHWADDR, &ifr); if (ret == 0) { memcpy(st->st_hwaddr, ifr.ifr_addr.sa_data, 6); } __platform_pollfd[__platform_npoll].fd = fd; __platform_pollfd[__platform_npoll].events = POLLIN | POLLPRI; __platform_npoll++; } break; } st->st_mode = (LINUX_S_ISDIR (lst.st_mode) ? S_IFDIR : 0) | (LINUX_S_ISCHR (lst.st_mode) ? S_IFCHR : 0) | (LINUX_S_ISBLK (lst.st_mode) ? S_IFBLK : 0) | (LINUX_S_ISREG (lst.st_mode) ? S_IFREG : 0) | (LINUX_S_ISFIFO(lst.st_mode) ? S_IFIFO : 0) | (LINUX_S_ISLNK (lst.st_mode) ? S_IFLNK : 0) | (LINUX_S_ISSOCK(lst.st_mode) ? S_IFSOCK : 0); /* if we are passed in /dev/urandom use as a random source */ if (LINUX_S_ISCHR(lst.st_mode) && lst.st_rdev == makedev(1, 9)) __platform_random_fd = fd; return 0; }
int dmmin, dmmax, dmtext; extern struct mba_driver hpdriver; extern struct uba_driver scdriver; extern struct uba_driver hkdriver; extern struct uba_driver idcdriver; extern struct uba_driver hldriver; extern struct uba_driver udadriver; extern struct uba_driver kdbdriver; struct genericconf { caddr_t gc_driver; char *gc_name; dev_t gc_root; } genericconf[] = { { (caddr_t)&hpdriver, "hp", makedev(0, 0), }, { (caddr_t)&scdriver, "up", makedev(2, 0), }, { (caddr_t)&udadriver, "ra", makedev(9, 0), }, { (caddr_t)&idcdriver, "rb", makedev(11, 0), }, { (caddr_t)&hldriver, "rl", makedev(14, 0), }, { (caddr_t)&hkdriver, "hk", makedev(3, 0), }, { (caddr_t)&hkdriver, "rk", makedev(3, 0), }, { (caddr_t)&kdbdriver, "kra", makedev(16, 0), }, { 0 }, }; setconf() { #if NMBA > 0 register struct mba_device *mi; #endif
int makedevs_main(int argc UNUSED_PARAM, char **argv) { parser_t *parser; char *line = (char *)"-"; int ret = EXIT_SUCCESS; opt_complementary = "=1"; /* exactly one param */ getopt32(argv, "d:", &line); argv += optind; xchdir(*argv); /* ensure root dir exists */ umask(0); printf("rootdir=%s\ntable=", *argv); if (NOT_LONE_DASH(line)) { printf("'%s'\n", line); } else { puts("<stdin>"); } parser = config_open(line); while (config_read(parser, &line, 1, 1, "# \t", PARSE_NORMAL)) { int linenum; char type; unsigned mode = 0755; unsigned major = 0; unsigned minor = 0; unsigned count = 0; unsigned increment = 0; unsigned start = 0; char name[41]; char user[41]; char group[41]; char *full_name = name; uid_t uid; gid_t gid; linenum = parser->lineno; if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", name, &type, &mode, user, group, &major, &minor, &start, &increment, &count)) || ((unsigned)(major | minor | start | count | increment) > 255) ) { bb_error_msg("invalid line %d: '%s'", linenum, line); ret = EXIT_FAILURE; continue; } gid = (*group) ? get_ug_id(group, xgroup2gid) : getgid(); uid = (*user) ? get_ug_id(user, xuname2uid) : getuid(); /* We are already in the right root dir, * so make absolute paths relative */ if ('/' == *full_name) full_name++; if (type == 'd') { bb_make_directory(full_name, mode | S_IFDIR, FILEUTILS_RECUR); if (chown(full_name, uid, gid) == -1) { chown_fail: bb_perror_msg("line %d: can't chown %s", linenum, full_name); ret = EXIT_FAILURE; continue; } if (chmod(full_name, mode) < 0) { chmod_fail: bb_perror_msg("line %d: can't chmod %s", linenum, full_name); ret = EXIT_FAILURE; continue; } } else if (type == 'f') { struct stat st; if ((stat(full_name, &st) < 0 || !S_ISREG(st.st_mode))) { bb_perror_msg("line %d: regular file '%s' does not exist", linenum, full_name); ret = EXIT_FAILURE; continue; } if (chown(full_name, uid, gid) < 0) goto chown_fail; if (chmod(full_name, mode) < 0) goto chmod_fail; } else { dev_t rdev; unsigned i; char *full_name_inc; if (type == 'p') { mode |= S_IFIFO; } else if (type == 'c') { mode |= S_IFCHR; } else if (type == 'b') { mode |= S_IFBLK; } else { bb_error_msg("line %d: unsupported file type %c", linenum, type); ret = EXIT_FAILURE; continue; } full_name_inc = xmalloc(strlen(full_name) + sizeof(int)*3 + 2); if (count) count--; for (i = start; i <= start + count; i++) { sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i); rdev = makedev(major, minor + (i - start) * increment); if (mknod(full_name_inc, mode, rdev) < 0) { bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc); ret = EXIT_FAILURE; } else if (chown(full_name_inc, uid, gid) < 0) { bb_perror_msg("line %d: can't chown %s", linenum, full_name_inc); ret = EXIT_FAILURE; } else if (chmod(full_name_inc, mode) < 0) { bb_perror_msg("line %d: can't chmod %s", linenum, full_name_inc); ret = EXIT_FAILURE; } } free(full_name_inc); } } if (ENABLE_FEATURE_CLEAN_UP) config_close(parser); return ret; }
setconf() { #if NMBA > 0 register struct mba_device *mi; #endif register struct uba_device *ui; register struct genericconf *gc; register char *cp, *gp; int unit, swaponroot = 0; if (rootdev != NODEV) goto doswap; unit = 0; if (boothowto & RB_ASKNAME) { char name[128]; retry: printf("root device? "); gets(name); for (gc = genericconf; gc->gc_driver; gc++) for (cp = name, gp = gc->gc_name; *cp == *gp; cp++) if (*++gp == 0) goto gotit; printf( "use hp%%d, up%%d, ra%%d, rb%%d, rl%%d, hk%%d or kra%%d\n"); goto retry; gotit: if (*++cp < '0' || *cp > '9') { printf("bad/missing unit number\n"); goto retry; } while (*cp >= '0' && *cp <= '9') unit = 10 * unit + *cp++ - '0'; if (*cp == '*') swaponroot++; goto found; } for (gc = genericconf; gc->gc_driver; gc++) { #if NMBA > 0 for (mi = mbdinit; mi->mi_driver; mi++) { if (mi->mi_alive == 0) continue; if (mi->mi_unit == unit && mi->mi_driver == (struct mba_driver *)gc->gc_driver) { printf("root on %s%d\n", mi->mi_driver->md_dname, unit); goto found; } } #endif for (ui = ubdinit; ui->ui_driver; ui++) { if (ui->ui_alive == 0) continue; if (ui->ui_unit == unit && ui->ui_driver == (struct uba_driver *)gc->gc_driver) { printf("root on %s%d\n", ui->ui_driver->ud_dname, unit); goto found; } } } printf("no suitable root\n"); asm("halt"); found: gc->gc_root = makedev(major(gc->gc_root), unit*8); rootdev = gc->gc_root; doswap: swdevt[0].sw_dev = argdev = dumpdev = makedev(major(rootdev), minor(rootdev)+1); /* swap size and dumplo set during autoconfigure */ if (swaponroot) rootdev = dumpdev; }
int cpio_read(const struct logcb *log, struct zstream *z, struct cpio_host *cpio, const char *prefix) { struct cpio_header header; int n, trailer=0; char buf[16]; cpio->uncompressed_size = 0; n = z->read(z, &header, sizeof(header)); if(n <= 0) { if(log) log->logln("Failed reading the cpio_header. EOF?"); return -1; } cpio->uncompressed_size += n; if(strncmp(header.c_magic, CPIOMAGIC, 6)) { if(log) log->logln("Wrong cpio magic"); return -1; } strncpy(cpio->c_magic, header.c_magic, 6); strncpy(buf, header.c_mode, 8); buf[8] = 0; cpio->c_mode = strtoul(buf, (void*)0, 16); cpio->mode = "?"; if(S_ISREG(cpio->c_mode)) cpio->mode = "f"; if(S_ISDIR(cpio->c_mode)) cpio->mode = "d"; if(S_ISLNK(cpio->c_mode)) cpio->mode = "l"; if(S_ISCHR(cpio->c_mode)) cpio->mode = "c"; if(S_ISBLK(cpio->c_mode)) cpio->mode = "b"; strncpy(buf, header.c_nlink, 8); buf[8] = 0; cpio->c_nlink = strtoull(buf, (void*)0, 16); strncpy(buf, header.c_rdevmajor, 8); buf[8] = 0; cpio->c_rdevmajor = strtoull(buf, (void*)0, 16); strncpy(buf, header.c_rdevminor, 8); buf[8] = 0; cpio->c_rdevminor = strtoull(buf, (void*)0, 16); cpio->rdev = makedev(cpio->c_rdevmajor, cpio->c_rdevminor); strncpy(buf, header.c_uid, 8); buf[8] = 0; cpio->c_uid = strtoull(buf, (void*)0, 16); strncpy(buf, header.c_gid, 8); buf[8] = 0; cpio->c_gid = strtoull(buf, (void*)0, 16); strncpy(buf, header.c_mtime, 8); buf[8] = 0; cpio->c_mtime = strtoull(buf, (void*)0, 16); strncpy(buf, header.c_filesize, 8); buf[8] = 0; cpio->c_filesize = strtoull(buf, (void*)0, 16); cpio->c_filesize_a = (cpio->c_filesize+3)&~0x3; strncpy(buf, header.c_namesize, 8); buf[8] = 0; cpio->c_namesize = strtoul(buf, (void*)0, 16); cpio->c_namesize += (((sizeof(header)+cpio->c_namesize+3)&~0x3) - (sizeof(header)+cpio->c_namesize)); cpio->name = malloc(cpio->c_namesize+1+strlen("./")); if(!cpio->name) { if(log) { log->pre(); log->log("Failed to malloc memory for cpio name "); log->log("of length %d", cpio->c_namesize); log->post(); } return -1; } n = z->read(z, cpio->name+2, cpio->c_namesize); if(n>0) cpio->name[n+2] = 0; else { if(log) log->logln("Error reading name from cpio."); return -1; } if(log && log->level > 3) log->logln("raw cpioname: [%s]", cpio->name+2); if(strcmp(cpio->name+2, "TRAILER!!!")==0) trailer=1; if(cpio->name[2] == '/') { cpio->name[1] = '.'; cpio->name++; } else { if(strncmp(cpio->name+2, "./", 2)) { if(trailer) { cpio->name += 2; } else { cpio->name[0] = '.'; cpio->name[1] = '/'; } } else { cpio->name += 2; } } if(prefix && (trailer==0) ) { char *p; if(strncmp(cpio->name, "./", 2)==0) cpio->name+=2; p = malloc(strlen(prefix)+strlen(cpio->name)+1); if(!p) { if(log) log->logln("Failed to allocate memory for prefixed name of %s", cpio->name); return -1; } strcpy(p, prefix); strcat(p, cpio->name); cpio->name = p; } cpio->uncompressed_size += n; return 0; }
static int ufs_create_special(Spfid *fid, char *path, u32 perm, Spstr *extension) { int nfid, err; int nmode, major, minor; char ctype; mode_t umode; Spfid *ofid; Fid *f, *of; char *ext; f = fid->aux; if (!perm&Dmnamedpipe && !extension->len) { sp_werror(Enoextension, EIO); return -1; } umode = np2umode(perm, extension, fid->conn->dotu); ext = sp_strdup(extension); if (perm & Dmsymlink) { if (symlink(ext, path) < 0) { err = errno; fprintf(stderr, "symlink %s %s %d\n", ext, path, err); create_rerror(err); goto error; } } else if (perm & Dmlink) { if (sscanf(ext, "%d", &nfid) == 0) { sp_werror(Eformat, EIO); goto error; } ofid = sp_fid_find(fid->conn, nfid); if (!ofid) { sp_werror(Eunknownfid, EIO); goto error; } of = ofid->aux; if (link(of->path, path) < 0) { create_rerror(errno); goto error; } } else if (perm & Dmdevice) { if (sscanf(ext, "%c %u %u", &ctype, &major, &minor) != 3) { sp_werror(Eformat, EIO); goto error; } nmode = 0; switch (ctype) { case 'c': nmode = S_IFCHR; break; case 'b': nmode = S_IFBLK; break; default: sp_werror(Eformat, EIO); goto error; } nmode |= perm & 0777; if (mknod(path, nmode, makedev(major, minor)) < 0) { create_rerror(errno); goto error; } } else if (perm & Dmnamedpipe) { if (mknod(path, S_IFIFO | (umode&0777), 0) < 0) { create_rerror(errno); goto error; } } f->omode = 0; if (!perm&Dmsymlink && chmod(path, umode)<0) { create_rerror(errno); goto error; } free(ext); return 0; error: free(ext); return -1; }
// mknod in /dev based on a path like "/sys/block/hda/hda1" static void make_device(char *path) { char *device_name, *s, *temp; int major, minor, type, len, fd; int mode = 0660; uid_t uid = 0; gid_t gid = 0; // Try to read major/minor string temp = strrchr(path, '/'); fd = open(path, O_RDONLY); *temp=0; temp = toybuf; len = read(fd, temp, 64); close(fd); if (len<1) return; temp[len] = 0; // Determine device name, type, major and minor device_name = strrchr(path, '/') + 1; type = path[5]=='c' ? S_IFCHR : S_IFBLK; major = minor = 0; sscanf(temp, "%u:%u", &major, &minor); // If we have a config file, look up permissions for this device if (CFG_MDEV_CONF) { char *conf, *pos, *end; // mmap the config file if (-1!=(fd = open("/etc/mdev.conf", O_RDONLY))) { len = fdlength(fd); conf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); if (conf) { int line = 0; // Loop through lines in mmaped file for (pos = conf; pos-conf<len;) { int field; char *end2; line++; // find end of this line for(end = pos; end-conf<len && *end!='\n'; end++); // Three fields: regex, uid:gid, mode for (field = 3; field; field--) { // Skip whitespace while (pos<end && isspace(*pos)) pos++; if (pos==end || *pos=='#') break; for (end2 = pos; end2<end && !isspace(*end2) && *end2!='#'; end2++); switch(field) { // Regex to match this device case 3: { char *regex = strndup(pos, end2-pos); regex_t match; regmatch_t off; int result; // Is this it? xregcomp(&match, regex, REG_EXTENDED); result=regexec(&match, device_name, 1, &off, 0); regfree(&match); free(regex); // If not this device, skip rest of line if (result || off.rm_so || off.rm_eo!=strlen(device_name)) goto end_line; break; } // uid:gid case 2: { char *s2; // Find : for(s = pos; s<end2 && *s!=':'; s++); if (s==end2) goto end_line; // Parse UID uid = strtoul(pos,&s2,10); if (s!=s2) { struct passwd *pass; char *str = strndup(pos, s-pos); pass = getpwnam(str); free(str); if (!pass) goto end_line; uid = pass->pw_uid; } s++; // parse GID gid = strtoul(s,&s2,10); if (end2!=s2) { struct group *grp; char *str = strndup(s, end2-s); grp = getgrnam(str); free(str); if (!grp) goto end_line; gid = grp->gr_gid; } break; } // mode case 1: { mode = strtoul(pos, &pos, 8); if (pos!=end2) goto end_line; goto found_device; } } pos=end2; } end_line: // Did everything parse happily? if (field && field!=3) error_exit("Bad line %d", line); // Next line pos = ++end; } found_device: munmap(conf, len); } close(fd); } } sprintf(temp, "/dev/%s", device_name); if (mknod(temp, mode | type, makedev(major, minor)) && errno != EEXIST) perror_exit("mknod %s failed", temp); if (CFG_MDEV_CONF) mode=chown(temp, uid, gid); }
/* mknod in /dev based on a path like "/sys/block/hda/hda1" */ static void make_device(char *path) { char *device_name,*s; int major,minor,type,len,fd; int mode=0660; uid_t uid=0; gid_t gid=0; RESERVE_CONFIG_BUFFER(temp,PATH_MAX); /* Try to read major/minor string */ snprintf(temp, PATH_MAX, "%s/dev", path); fd = open(temp, O_RDONLY); len = read(fd, temp, PATH_MAX-1); if (len<1) goto end; temp[len] = 0; close(fd); /* Determine device name, type, major and minor */ device_name = strrchr(path, '/') + 1; type = strncmp(path+5, "block/" ,6) ? S_IFCHR : S_IFBLK; major = minor = 0; for (s = temp; *s; s++) { if (*s == ':') { major = minor; minor = 0; } else { minor *= 10; minor += (*s) - '0'; } } /* If we have a config file, look up permissions for this device */ if (ENABLE_FEATURE_MDEV_CONF) { char *conf,*pos,*end; /* mmap the config file */ if (-1!=(fd=open("/etc/mdev.conf",O_RDONLY))) { len=lseek(fd,0,SEEK_END); conf=mmap(NULL,len,PROT_READ,MAP_PRIVATE,fd,0); if (conf) { int line=0; /* Loop through lines in mmaped file*/ for (pos=conf;pos-conf<len;) { int field; char *end2; line++; /* find end of this line */ for(end=pos;end-conf<len && *end!='\n';end++); /* Three fields: regex, uid:gid, mode */ for (field=3;field;field--) { /* Skip whitespace */ while (pos<end && isspace(*pos)) pos++; if (pos==end || *pos=='#') break; for (end2=pos; end2<end && !isspace(*end2) && *end2!='#'; end2++); switch(field) { /* Regex to match this device */ case 3: { char *regex=strndupa(pos,end2-pos); regex_t match; regmatch_t off; int result; /* Is this it? */ xregcomp(&match,regex,REG_EXTENDED); result=regexec(&match,device_name,1,&off,0); regfree(&match); /* If not this device, skip rest of line */ if(result || off.rm_so || off.rm_eo!=strlen(device_name)) goto end_line; break; } /* uid:gid */ case 2: { char *s2; /* Find : */ for(s=pos;s<end2 && *s!=':';s++); if(s==end2) goto end_line; /* Parse UID */ uid=strtoul(pos,&s2,10); if(s!=s2) { struct passwd *pass; pass=getpwnam(strndupa(pos,s-pos)); if(!pass) goto end_line; uid=pass->pw_uid; } s++; /* parse GID */ gid=strtoul(s,&s2,10); if(end2!=s2) { struct group *grp; grp=getgrnam(strndupa(s,end2-s)); if(!grp) goto end_line; gid=grp->gr_gid; } break; } /* mode */ case 1: { mode=strtoul(pos,&pos,8); if(pos!=end2) goto end_line; goto found_device; } } pos=end2; } end_line: /* Did everything parse happily? */ if (field && field!=3) bb_error_msg_and_die("Bad line %d",line); /* Next line */ pos=++end; } found_device: munmap(conf,len); } close(fd); } } sprintf(temp, "%s/%s", DEV_PATH, device_name); umask(0); if (mknod(temp, mode | type, makedev(major, minor)) && errno != EEXIST) bb_perror_msg_and_die("mknod %s failed", temp); if (ENABLE_FEATURE_MDEV_CONF) chown(temp,uid,gid); end: RELEASE_CONFIG_BUFFER(temp); }
cdev_notdef(), /* 72: was USB scanners */ cdev_fuse_init(NFUSE,fuse), /* 73: fuse */ }; int nchrdev = nitems(cdevsw); /* * Swapdev is a fake device implemented * in sw.c used only internally to get to swstrategy. * It cannot be provided to the users, because the * swstrategy routine munches the b_dev and b_blkno entries * before calling the appropriate driver. This would horribly * confuse, e.g. the hashing routines. Instead, /dev/drum is * provided as a character (raw) device. */ dev_t swapdev = makedev(1, 0); /* * Routine that identifies /dev/mem and /dev/kmem. * * A minimal stub routine can always return 0. */ int iskmemdev(dev) dev_t dev; { if (major(dev) == 3 && (minor(dev) == 0 || minor(dev) == 1)) return (1); return (0); }
dev_t pty_makedev(char ms, int minor) { return makedev(ms == 't' ? pts_major : ptc_major, minor); }
int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int resume) { char dv[PATH_MAX]; char nm[PATH_MAX]; char *dname; int rv; int i; sprintf(dv, "%d:%d", sd->disk.major, sd->disk.minor); rv = sysfs_set_str(sra, NULL, "new_dev", dv); if (rv) return rv; memset(nm, 0, sizeof(nm)); dname = devid2kname(makedev(sd->disk.major, sd->disk.minor)); strcpy(sd->sys_name, "dev-"); strcpy(sd->sys_name+4, dname); /* test write to see if 'recovery_start' is available */ if (resume && sd->recovery_start < MaxSector && sysfs_set_num(sra, sd, "recovery_start", 0)) { sysfs_set_str(sra, sd, "state", "remove"); return -1; } rv = sysfs_set_num(sra, sd, "offset", sd->data_offset); rv |= sysfs_set_num(sra, sd, "size", (sd->component_size+1) / 2); if (sra->array.level != LEVEL_CONTAINER) { if (sd->recovery_start == MaxSector) /* This can correctly fail if array isn't started, * yet, so just ignore status for now. */ sysfs_set_str(sra, sd, "state", "insync"); if (sd->disk.raid_disk >= 0) rv |= sysfs_set_num(sra, sd, "slot", sd->disk.raid_disk); if (resume) sysfs_set_num(sra, sd, "recovery_start", sd->recovery_start); } if (sd->bb.supported) { if (sysfs_set_str(sra, sd, "state", "external_bbl")) { /* * backward compatibility - if kernel doesn't support * bad blocks for external metadata, let it continue * as long as there are none known so far */ if (sd->bb.count) { pr_err("The kernel has no support for bad blocks in external metadata\n"); return -1; } } for (i = 0; i < sd->bb.count; i++) { char s[30]; const struct md_bb_entry *entry = &sd->bb.entries[i]; snprintf(s, sizeof(s) - 1, "%llu %d\n", entry->sector, entry->length); rv |= sysfs_set_str(sra, sd, "bad_blocks", s); } } return rv; }
cdev_pppx_init(NPPPX,pppx), /* 80: pppx */ }; int nchrdev = nitems(cdevsw); int mem_no = 3; /* major device number of memory special file */ /* * Swapdev is a fake device implemented * in sw.c used only internally to get to swstrategy. * It cannot be provided to the users, because the * swstrategy routine munches the b_dev and b_blkno entries * before calling the appropriate driver. This would horribly * confuse, e.g. the hashing routines. Instead, /dev/drum is * provided as a character (raw) device. */ dev_t swapdev = makedev(4, 0); int chrtoblktbl[] = { NODEV, /* 0 */ NODEV, /* 1 */ NODEV, /* 2 */ NODEV, /* 3 */ 0, /* 4 */ NODEV, /* 5 */ NODEV, /* 6 */ NODEV, /* 7 */ NODEV, /* 8 */ 9, /* 9 */ NODEV, /* 10 */ 3, /* 11 */ NODEV, /* 12 */
static int imap_master_client_parse_input(const char *const *args, pool_t pool, struct mail_storage_service_input *input_r, struct imap_master_input *master_input_r, const char **error_r) { const char *key, *value; unsigned int peer_dev_major = 0, peer_dev_minor = 0; i_zero(input_r); i_zero(master_input_r); master_input_r->client_input = buffer_create_dynamic(pool, 64); master_input_r->client_output = buffer_create_dynamic(pool, 16); master_input_r->state = buffer_create_dynamic(pool, 512); input_r->module = input_r->service = "imap"; /* we never want to do userdb lookup again when restoring the client. we have the userdb_fields cached already. */ input_r->flags_override_remove = MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP; if (args[0] == NULL) { *error_r = "Missing username in input"; return -1; } input_r->username = args[0]; for (args++; *args != NULL; args++) { value = strchr(*args, '='); if (value != NULL) key = t_strdup_until(*args, value++); else { key = *args; value = ""; } if (strcmp(key, "lip") == 0) { if (net_addr2ip(value, &input_r->local_ip) < 0) { *error_r = t_strdup_printf( "Invalid lip value: %s", value); return -1; } } else if (strcmp(key, "rip") == 0) { if (net_addr2ip(value, &input_r->remote_ip) < 0) { *error_r = t_strdup_printf( "Invalid rip value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { if (str_to_uint(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { if (str_to_uint(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; } } else if (strcmp(key, "peer_ino") == 0) { if (str_to_ino(value, &master_input_r->peer_ino) < 0) { *error_r = t_strdup_printf( "Invalid peer_ino value: %s", value); return -1; } } else if (strcmp(key, "session") == 0) { input_r->session_id = value; } else if (strcmp(key, "session_created") == 0) { if (str_to_time(value, &input_r->session_create_time) < 0) { *error_r = t_strdup_printf( "Invalid session_created value: %s", value); return -1; } } else if (strcmp(key, "userdb_fields") == 0) { input_r->userdb_fields = t_strsplit_tabescaped(value); } else if (strcmp(key, "client_input") == 0) { if (base64_decode(value, strlen(value), NULL, master_input_r->client_input) < 0) { *error_r = t_strdup_printf( "Invalid client_input base64 value: %s", value); return -1; } } else if (strcmp(key, "client_output") == 0) { if (base64_decode(value, strlen(value), NULL, master_input_r->client_output) < 0) { *error_r = t_strdup_printf( "Invalid client_output base64 value: %s", value); return -1; } } else if (strcmp(key, "state") == 0) { if (base64_decode(value, strlen(value), NULL, master_input_r->state) < 0) { *error_r = t_strdup_printf( "Invalid state base64 value: %s", value); return -1; } } else if (strcmp(key, "tag") == 0) { master_input_r->tag = t_strdup(value); } else if (strcmp(key, "bad-done") == 0) { master_input_r->state_import_bad_idle_done = TRUE; } else if (strcmp(key, "idle-continue") == 0) { master_input_r->state_import_idle_continue = TRUE; } } if (peer_dev_major != 0 || peer_dev_minor != 0) { master_input_r->peer_dev = makedev(peer_dev_major, peer_dev_minor); } return 0; }
/* * Create the device nodes for vinum objects * * XXX - Obsolete, vinum kernel module now creates is own devices. */ void make_devices(void) { #if 0 int volno; int plexno; int sdno; int driveno; #endif if (hist) { timestamp(); fprintf(hist, "*** Created devices ***\n"); } #if 0 system("rm -rf " VINUM_DIR); /* remove the old directories */ system("mkdir -p " VINUM_DIR "/drive " /* and make them again */ VINUM_DIR "/plex " VINUM_DIR "/sd " VINUM_DIR "/vol"); if (mknod(VINUM_SUPERDEV_NAME, S_IRUSR | S_IWUSR | S_IFCHR, /* user only */ makedev(VINUM_CDEV_MAJOR, VINUM_SUPERDEV)) < 0) fprintf(stderr, "Can't create %s: %s\n", VINUM_SUPERDEV_NAME, strerror(errno)); if (mknod(VINUM_WRONGSUPERDEV_NAME, S_IRUSR | S_IWUSR | S_IFCHR, /* user only */ makedev(VINUM_CDEV_MAJOR, VINUM_WRONGSUPERDEV)) < 0) fprintf(stderr, "Can't create %s: %s\n", VINUM_WRONGSUPERDEV_NAME, strerror(errno)); superdev = open(VINUM_SUPERDEV_NAME, O_RDWR); /* open the super device */ if (mknod(VINUM_DAEMON_DEV_NAME, /* daemon super device */ S_IRUSR | S_IWUSR | S_IFCHR, /* user only */ makedev(VINUM_CDEV_MAJOR, VINUM_DAEMON_DEV)) < 0) fprintf(stderr, "Can't create %s: %s\n", VINUM_DAEMON_DEV_NAME, strerror(errno)); #endif if (ioctl(superdev, VINUM_GETCONFIG, &vinum_conf) < 0) { perror("Can't get vinum config"); return; } #if 0 for (volno = 0; volno < vinum_conf.volumes_allocated; volno++) make_vol_dev(volno, 0); for (plexno = 0; plexno < vinum_conf.plexes_allocated; plexno++) make_plex_dev(plexno, 0); for (sdno = 0; sdno < vinum_conf.subdisks_allocated; sdno++) make_sd_dev(sdno); /* Drives. Do this later (both logical and physical names) XXX */ for (driveno = 0; driveno < vinum_conf.drives_allocated; driveno++) { char filename[PATH_MAX]; /* for forming file names */ get_drive_info(&drive, driveno); if (drive.state > drive_referenced) { sprintf(filename, "ln -s %s " VINUM_DIR "/drive/%s", drive.devicename, drive.label.name); system(filename); } } #endif }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; mknod("/dev/mmc", S_IFBLK | 0660, makedev(126, 0)); mknod("/dev/mmc0", S_IFBLK | 0660, makedev(126, 1)); mknod("/dev/mmc1", S_IFBLK | 0660, makedev(126, 2)); mknod("/dev/mmc2", S_IFBLK | 0660, makedev(126, 3)); mknod("/dev/mmc3", S_IFBLK | 0660, makedev(126, 4)); eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); if (in != NULL) { fclose(in); eval("/usr/sbin/convertnvram"); eval("/sbin/mtd", "erase", "nvram"); nvram_commit(); } if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); #ifdef HAVE_RTG32 insmod("slhc"); insmod("ppp_generic"); insmod("ppp_async"); insmod("ppp_synctty"); insmod("ppp_mppe_mppc "); insmod("pppox"); insmod("pppoe"); #endif /* * network drivers */ #ifdef HAVE_HOTPLUG2 insmod("ar231x"); #else insmod("ar2313"); #endif detect_wireless_devices(); eval("ifconfig", "eth0", "up"); // wan system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 1"); #ifdef HAVE_RTG32 system("swconfig dev eth0 vlan 1 set ports \"0t 1 2 3 4\""); system("swconfig dev eth0 vlan 2 set ports \"0t 5\""); #else system("swconfig dev eth0 vlan 1 set ports \"0t 2 3 4 5\""); system("swconfig dev eth0 vlan 2 set ports \"0t 1\""); #endif system("swconfig dev eth0 set apply"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); eval("vconfig", "add", "eth0", "2"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", macaddr); MAC_ADD(macaddr); ether_atoe(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data); strncpy(ifr.ifr_name, "vlan2", IFNAMSIZ); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } eval("gpio", "enable", "1"); #ifdef HAVE_RTG32 writeproc("/proc/sys/dev/wifi0/ledpin", "7"); writeproc("/proc/sys/dev/wifi0/softled", "1"); #else writeproc("/proc/sys/dev/wifi0/ledpin", "0"); writeproc("/proc/sys/dev/wifi0/softled", "1"); #endif /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; }
void sabtty_attach(device_t parent, device_t self, void *aux) { struct sabtty_softc *sc = device_private(self); struct sabtty_attach_args *sa = aux; int r; int maj; int is_kgdb = 0; sc->sc_dev = self; #ifdef KGDB is_kgdb = sab_kgdb_check(sc); #endif if (!is_kgdb) { sc->sc_tty = tty_alloc(); if (sc->sc_tty == NULL) { aprint_normal(": failed to allocate tty\n"); return; } tty_attach(sc->sc_tty); sc->sc_tty->t_oproc = sabtty_start; sc->sc_tty->t_param = sabtty_param; } sc->sc_parent = device_private(parent); sc->sc_bt = sc->sc_parent->sc_bt; sc->sc_portno = sa->sbt_portno; sc->sc_rend = sc->sc_rbuf + SABTTY_RBUF_SIZE; switch (sa->sbt_portno) { case 0: /* port A */ sc->sc_pvr_dtr = SAB_PVR_DTR_A; sc->sc_pvr_dsr = SAB_PVR_DSR_A; r = bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh, SAB_CHAN_A, SAB_CHANLEN, &sc->sc_bh); break; case 1: /* port B */ sc->sc_pvr_dtr = SAB_PVR_DTR_B; sc->sc_pvr_dsr = SAB_PVR_DSR_B; r = bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh, SAB_CHAN_B, SAB_CHANLEN, &sc->sc_bh); break; default: aprint_normal(": invalid channel: %u\n", sa->sbt_portno); return; } if (r != 0) { aprint_normal(": failed to allocate register subregion\n"); return; } sabtty_console_flags(sc); if (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) { struct termios t; const char *acc; /* Let residual prom output drain */ DELAY(100000); switch (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) { case SABTTYF_CONS_IN: acc = "input"; break; case SABTTYF_CONS_OUT: acc = "output"; break; case SABTTYF_CONS_IN|SABTTYF_CONS_OUT: default: acc = "i/o"; break; } t.c_ispeed= 0; if (sc->sc_flags & SABTTYF_IS_RSC) t.c_ospeed = 115200; else t.c_ospeed = 9600; t.c_cflag = CREAD | CS8 | HUPCL; sc->sc_tty->t_ospeed = 0; sabttyparam(sc, sc->sc_tty, &t); if (sc->sc_flags & SABTTYF_CONS_IN) { sabtty_cons_input = sc; cn_tab->cn_pollc = sab_cnpollc; cn_tab->cn_getc = sab_cngetc; maj = cdevsw_lookup_major(&sabtty_cdevsw); cn_tab->cn_dev = makedev(maj, device_unit(self)); shutdownhook_establish(sabtty_shutdown, sc); cn_init_magic(&sabtty_cnm_state); cn_set_magic("\047\001"); /* default magic is BREAK */ } if (sc->sc_flags & SABTTYF_CONS_OUT) { sabtty_tec_wait(sc); sabtty_cons_output = sc; cn_tab->cn_putc = sab_cnputc; maj = cdevsw_lookup_major(&sabtty_cdevsw); cn_tab->cn_dev = makedev(maj, device_unit(self)); } aprint_normal(": console %s", acc); } else { /* Not a console... */ sabtty_reset(sc); #ifdef KGDB if (is_kgdb) { sab_kgdb_init(sc); aprint_normal(": kgdb"); } #endif } aprint_normal("\n"); aprint_naive(": Serial port\n"); }