void mbr_rec(device_t *dev, int32_t id_base, uint64_t off, uint64_t base) { /* partition counter */ int32_t i; /* extended boot record? */ int32_t is_ext = !!base; /* create buffer */ mbr_t *buf = kmalloc(512); /* read partition table */ dev_read(dev, off*512, 512, (char *) buf); /* make sure signature is valid */ if (buf->signature == 0xAA55) { /* loop over partition entries */ for (i = 0; i < 4; i++) { /* partition existing? */ if (buf->partents[i].parttype) { /* calc new_id */ int32_t new_id = id_base+i; /* calc new base */ int64_t new_base = is_ext ? base : buf->partents[i].first_lba; /* calc new off */ int64_t new_off; if (is_ext && i == 1) { new_off = buf->partents[i].first_lba + base; } else { new_off = buf->partents[i].first_lba + off; } /* add if primary partition or logical drive (not ebr ptr) */ if (!is_ext || !i) { device_t *t; class_t cls; reslist_t reslist = {0, NULL}; /* setup partition class */ cls.bus = BUS_DISK; cls.base = BASE_DISK_PARTITION; cls.sub = new_id; cls.progif = dev->devid; /* print info */ printk("Entry %d: %d (size: %d)\n", new_id, (int32_t) new_off, buf->partents[i].sectcount); /* add device */ dev_add(&t, dev->child_bus, cls, reslist, &new_off); } /* if extended partition, go into */ if (buf->partents[i].parttype == 0x05 || buf->partents[i].parttype == 0x0F) { mbr_rec(dev, new_id<5?5:new_id, new_off, new_base); } } } } /* deallocate buffer */ kfree(buf); }
uint32_t root_probe(device_t* dev, void* config) { bus_t *genesis; device_t *t; class_t cls; reslist_t reslist = {0, NULL}; /* Create genesis bus: */ dev_mkbus(&genesis, BUS_GENESIS, dev); /* Add the "memory" device driver: */ cls.bus = BUS_GENESIS; cls.base = BASE_GENESIS_MEMORY; cls.sub = SUB_GENESIS_MEMORY; cls.progif = IF_ANY; dev_add(&t, genesis, cls, reslist, NULL); /* Add a "tty" device driver to act as a system console: */ cls.bus = BUS_GENESIS; cls.base = BASE_GENESIS_TTY; cls.sub = SUB_GENESIS_TTY_VIRTUAL; cls.progif = IF_ANY; dev_add(&t, genesis, cls, reslist, NULL); /* Add the "host" device driver: */ cls.bus = BUS_GENESIS; cls.base = BASE_GENESIS_MACHINE; #ifdef SUBARCH_IBMPC cls.sub = SUB_GENESIS_MACHINE_IBMPC; #endif #ifdef SUBARCH_MIPS cls.sub = SUB_GENESIS_MACHINE_MIPS; #endif cls.progif = IF_ANY; dev_add(&t, genesis, cls, reslist, NULL); return ESUCCESS; }
uint32_t vtty_ioctl(device_t *dev, uint32_t cmd, void *data) { device_t *t; class_t cls; reslist_t reslist = {0, NULL}; pstty_init_t pstty_config; switch (cmd) { case TTY_PRESS: press(*((uint8_t *) data)); if (blocked_pid != -1) { unblock(blocked_pid); blocked_pid = -1; } break; case TTY_ATTR: legacy_video_attr(*((uint8_t *) data)); break; case TTY_GETCURSOR: legacy_get_cursor(((char *)data)+0, ((char *)data)+1); break; case TTY_SETATTRATOFF: legacy_set_attr_at_off(((char *)data)[0], ((char *)data)[1], ((char *)data)[2]); break; case TTY_SETCHARATOFF: legacy_set_char_at_off(((char *)data)[0], ((char *)data)[1], ((char *)data)[2]); break; case TTY_SETCURSOR: legacy_set_cursor(((char *)data)[0], ((char *)data)[1]); break; case TTY_NOECHO: echo = 0; break; case TTY_SETECHO: echo = 1; break; case TTY_NOBUF: buffront = 0; bufback = 0; buflines = 0; bufbyline = 0; break; case TTY_SETBUF: buffront = 0; bufback = 0; buflines = 0; bufbyline = 1; break; case TTY_DISABLE: legacy_lfb_enabled = 0; break; case TTY_ENABLE: legacy_lfb_enabled = 1; legacy_redraw(); break; case TTY_FORK: cls.bus = BUS_GENESIS; cls.base = BASE_GENESIS_TTY; cls.sub = SUB_GENESIS_TTY_PSEUDO; pstty_config.pid = curproc->pid; pstty_config.prefix = ((tty_fork_t *) data)->prefix; dev_add(&t, dev->parent_bus, cls, reslist, &pstty_config); ((tty_fork_t *) data)->devid = t->devid; break; default: break; } return ESUCCESS; }