void vt_dev_init(void) { int i; if (VT_COUNT > 99) { kprintf("vt_dev_init(): error: too many vts requested!\n"); return; } if (!initialized) { vt_init(); } for (i = 0; i < VT_COUNT; ++i) { vt[i].std.name = vt[i].name; vt[i].std.dev_class = DEV_CLASS_OTHER; vt[i].std.dev_type = DEV_TYPE_VT; vt[i].std.devopen = (devopen_t) vt_open; vt[i].std.remove = (devrm_t) vt_remove; //kprintf("vt_init(): adding %s\n", vt[i].std.name); switch (device_insert(&vt[i].std)) { case 0: devices_not_removed_count++; break; case DEV_ERR_TOTAL_FAILURE: kprintf("vt_init(): unknown error inserting device %d\n", i); break; case DEV_ERR_BAD_NAME: kprintf("vt_init(): error inserting device %d: bad name\n", i); break; case DEV_ERR_EXISTS: kprintf("vt_init(): error inserting device %d: device exists\n", i); break; case DEV_ERR_BAD_STRUCT: kprintf("vt_init(): error inserting device %d: bad info struct\n", i); break; } } }
void floppy_init(void) { int i; uint8_t detect_floppy; if (floppy_params.bytes_per_sector > 2) { kprintf("FDD: ERROR: Sector size bigger than 512 bytes (disabled floppies)\n"); floppy_drives[0].type = 0; floppy_drives[1].type = 0; return; } outportb(0x70, 0x10); detect_floppy = inportb(0x71); floppy_drives[0].type = detect_floppy >> 4; floppy_drives[1].type = detect_floppy & 0xF; for (i = 0; i < MAX_DRIVES; ++i) { if (floppy_drives[i].type == 4) { device_insert(&floppy_drives[i].blockdev.std); /* with 1.44MB 3.5" floppy disk, 2 sides and 80 tracks per side */ floppy_drives[i].blockdev.block_size = 128 * (1 << floppy_params.bytes_per_sector); floppy_drives[i].blockdev.block_count = 2 * 80 * floppy_params.sectors_per_track; } else { if (floppy_drives[i].type) { kprintf("FDD: Found %s at %s, that's not supported.\n", floppy_drive_types[floppy_drives[i].type], floppy_drives[i].type); } floppy_drives[i].blockdev.std.dev_type = DEV_TYPE_NONE; } } install_irq_handler(FLOPPY_IRQ, floppy_handler); }
static void* pthread_a_work(void* args) { sorm_connection_t *_conn; int ret = sorm_open(DB_FILE, SORM_DB_SQLITE, 0, &rwlock, SORM_ENABLE_RWLOCK, &_conn); assert(ret == SORM_OK); device_t *device; sorm_iterator_t *iterator; ret = device_select_iterate_by_open(_conn, ALL_COLUMNS, NULL, &iterator); sorm_begin_read_transaction(_conn); int i; for (i = 0; i < 4; i ++) { device_select_iterate_by(iterator, &device); char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } sorm_begin_write_transaction(_conn); device = device_new(); device_set_id(device, 3); device_set_uuid(device, "uuid-3"); device_set_name(device, "name-3"); device_set_password(device, "passwd-3"); ret = device_insert(_conn, device); assert(ret == SORM_OK); device_free(device); printf("insert uuid-3\n"); pthread_mutex_lock(&mutex); condition_b = 1; pthread_mutex_unlock(&mutex); pthread_cond_signal(&cond_b); printf("wait for input\n"); ret = getchar(); printf("continue running\n"); sorm_commit_transaction(_conn); while (1) { device_select_iterate_by(iterator, &device); if (!device_select_iterate_more(iterator)) { break; } char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } sorm_commit_transaction(_conn); device_select_iterate_close(iterator); //sorm_commit_transaction(_conn); printf("a finish\n"); sorm_close(_conn); }
int main() { pthread_rwlock_init(&rwlock, NULL); pthread_t p1, p2; sorm_init(0); sorm_connection_t *_conn; int ret = sorm_open(DB_FILE, SORM_DB_SQLITE, 0, &rwlock, SORM_ENABLE_RWLOCK, &_conn); ret = device_create_table(_conn); assert(ret == SORM_OK); /* insert rows for select */ int i; device_t *device; for(i = 0; i < 10; i ++) { if (i == 3) { continue; } device = device_new(); device->id = i; device->id_stat = SORM_STAT_VALUED; sprintf(device->uuid,"uuid-%d", i); device->uuid_stat = SORM_STAT_VALUED; sprintf(device->name,"name-%d", i); device->name_stat = SORM_STAT_VALUED; sprintf(device->password, "passwd-%d", i); device->password_stat = SORM_STAT_VALUED; device_insert(_conn, device); device_free(device); } ret = pthread_create(&p1, NULL, pthread_a_work, (void*)_conn); assert(ret == 0); ret = pthread_create(&p2, NULL, pthread_b_work, (void*)_conn); assert(ret == 0); pthread_join(p1, NULL); pthread_join(p2, NULL); sorm_iterator_t *iterator; ret = device_select_iterate_by_open(_conn, ALL_COLUMNS, NULL, &iterator); while (1) { device_select_iterate_by(iterator, &device); if (!device_select_iterate_more(iterator)) { break; } char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } device_select_iterate_close(iterator); ret = device_delete_table(_conn); assert(ret == SORM_OK); sorm_close(_conn); }