static int init_device(struct sbd_context *st) { struct sector_header_s *s_header; struct sector_node_s *s_node; struct sector_mbox_s *s_mbox; struct stat s; char uuid[37]; int i; int rc = 0; s_header = sector_alloc(); s_node = sector_alloc(); s_mbox = sector_alloc(); memcpy(s_header->magic, sbd_magic, sizeof(s_header->magic)); s_header->version = sbd_version; s_header->slots = 255; s_header->sector_size = sector_size; s_header->timeout_watchdog = timeout_watchdog; s_header->timeout_allocate = timeout_allocate; s_header->timeout_loop = timeout_loop; s_header->timeout_msgwait = timeout_msgwait; s_header->minor_version = 1; uuid_generate(s_header->uuid); uuid_unparse_lower(s_header->uuid, uuid); fstat(st->devfd, &s); /* printf("st_size = %ld, st_blksize = %ld, st_blocks = %ld\n", s.st_size, s.st_blksize, s.st_blocks); */ cl_log(LOG_INFO, "Creating version %d.%d header on device %d (uuid: %s)", s_header->version, s_header->minor_version, st->devfd, uuid); fprintf(stdout, "Creating version %d.%d header on device %d (uuid: %s)\n", s_header->version, s_header->minor_version, st->devfd, uuid); if (header_write(st, s_header) < 0) { rc = -1; goto out; } cl_log(LOG_INFO, "Initializing %d slots on device %d", s_header->slots, st->devfd); fprintf(stdout, "Initializing %d slots on device %d\n", s_header->slots, st->devfd); for (i=0;i < s_header->slots;i++) { if (slot_write(st, i, s_node) < 0) { rc = -1; goto out; } if (mbox_write(st, i, s_mbox) < 0) { rc = -1; goto out; } } out: free(s_node); free(s_header); free(s_mbox); return(rc); }
void request_write(Request request, int fd) { char buf[MAXLINE]; sprintf(buf, "%s %s %s\r\n", request->method, request->uri, request->version); Rio_writen(fd, buf, strlen(buf)); header_write(request->header, buf, fd); Rio_writen(fd, "\r\n", 2); }
void response_write(Response response, int fd) { char buf[MAXLINE]; sprintf(buf, "%s %d %s\r\n", response->version, response->status_code, response->status_name); Rio_writen(fd, buf, strlen(buf)); header_write(response->header, buf, fd); Rio_writen(fd, "\r\n", 2); Rio_writen(fd, response->content, (size_t) response->content_length); }
int bbp_code_offset(uint8_t *in, uint8_t *out, int bs, int bs_r, int len, int offset) { int recursive; Block_Coder_Data b; Block_Coder_Data s; int len_c; int b_s_len; memset(&b, 0, sizeof(b)); memset(&s, 0, sizeof(b)); assert(len); assert(inits_count); #ifdef BBP_USE_SIMD assert(!((uintptr_t)in % BBP_ALIGNMENT)); assert(!((uintptr_t)out % BBP_ALIGNMENT)); #endif if (!bs) bs = DEFAULT_BLOCK_SIZE; if (!bs_r) { if (bs >= 128) bs_r = -1; else bs_r = DEFAULT_BLOCK_SIZE_S; } if (bs_r < 0) recursive = 0; else recursive = 1; b.block_size = bs; b.len = len; b.coder = CODER_OFFSET; b.offset = offset; b_s_len = offset_calc_signal_len(&b); if (recursive && b_s_len) { b.signal_buf = malloc(len/bs); b.block_buf = out + HEADER_SIZE; } else { b.signal_buf = out+HEADER_SIZE; b.block_buf = b.signal_buf+RU_N(b_s_len, BBP_ALIGNMENT); } code(&b, in, len); //remove or commen out? assert(b.cur_block_free_bits == 8); assert((b.cur_block-out)%BBP_ALIGNMENT == 0); assert(signal_len(&b) <= len/bs); assert(signal_len(&b) == offset_calc_signal_len(&b)); if (b_s_len && recursive) { s.block_size = bs_r; s.len = signal_len(&b); s.coder = CODER_OFFSET; s.offset = BBP_ALIGNMENT; s.signal_buf = out+HEADER_SIZE+b.len_c; s.block_buf = s.signal_buf + RU_N(offset_calc_signal_len(&s), BBP_ALIGNMENT); code(&s, b.signal_buf, signal_len(&b)); free(b.signal_buf); len_c = s.cur_block-out; header_write(out, &b, &s, len, len_c); } else { len_c = HEADER_SIZE+RU_N(b_s_len, BBP_ALIGNMENT)+b.len_c; header_write(out, &b, NULL, len, len_c); } assert(len_c % 16 == 0); //printf("comp size: %d-%d\n", len_c, b.len_c); //printf("enc positions: %d %d %d\n", b.block_buf-out, s.block_buf-out, s.signal_buf-out); return len_c; }
/* The normal CGI module passes the returned data through * ap_scan_script_header(). We can't do that directly, since we don't * have a constant stream of data, so we buffer the header into our own * structure, and call ap_scan_script_header_err_core() with our own * getline() function to walk the header buffer we have. We could * probably get some speed improvement by keeping the header buffer * between runs, instead of growing it every time... for later. Also, * we currently don't use the pool allocation routines here, so we have * to be very careful not to leak. We could probably at least use the * ap_register_cleanup() function to make sure we clean up our mess... */ static int wrap_write (void *data, const char *buf, size_t len) { WRAPPER_DATA *wrap = (WRAPPER_DATA *)data; int wl; int ret; #if ECS_DEBUG>1 fprintf (stderr, "wrap_write (%s, %d)\n", buf, len); #endif if (!wrap->end_of_header) { wl = header_write (&(wrap->hbuf), buf, len); if (wl == 0) { return len; } wrap->end_of_header = 1; wrap->hbuf.loc = 0; #if ECS_DEBUG>1 fprintf (stderr, "ap_scan_script_header_err_core\n%s\n", wrap->hbuf.buf); #endif wrap->returns = ap_scan_script_header_err_core(wrap->r, NULL, h_getline, (void *)&(wrap->hbuf)); #if ECS_DEBUG>1 fprintf (stderr, "ap_scan_script_header_err_core.. done\n"); #endif if (len >= wl) { len = len - wl; buf = buf + wl; } if (wrap->returns == OK) { const char* location = ap_table_get (wrap->r->headers_out, "Location"); if (location && location[0] == '/' && wrap->r->status == 200) { wrap->returns = INTERNAL_REDIRECT; } else if (location && wrap->r->status == 200) { /* XX Note that if a script wants to produce its own Redirect * body, it now has to explicitly *say* "Status: 302" */ wrap->returns = REDIRECT; } else { #ifdef ECS_DEBUG fprintf (stderr, "ap_send_http_header\n"); #endif ap_send_http_header(wrap->r); #ifdef ECS_DEBUG fprintf (stderr, "ap_send_http_header.. done\n"); #endif } } } /* if header didn't return OK, ignore the rest */ if ((wrap->returns != OK) || wrap->r->header_only) { return len; } #if ECS_DEBUG>1 fprintf (stderr, "ap_rwrite(%s,%d)\n", buf, len); #endif ret = ap_rwrite (buf, len, wrap->r); #if ECS_DEBUG>1 fprintf (stderr, "ap_rwrite.. done\n"); #endif return ret; }
void do_drive_cdrom_startstop_test(struct ide_controller *ide,unsigned char which) { struct menuboxbounds mbox; char backredraw=1; int select=-1; char redraw=1; int c; /* UI element vars */ menuboxbounds_set_def_list(&mbox,/*ofsx=*/4,/*ofsy=*/7,/*cols=*/1); menuboxbounds_set_item_strings_arraylen(&mbox,drive_cdrom_startstop_strings); /* most of the commands assume a ready controller. if it's stuck, * we'd rather the user have a visual indication that it's stuck that way */ c = do_ide_controller_user_wait_busy_controller(ide); if (c != 0) return; /* select the drive we want */ idelib_controller_drive_select(ide,which,/*head*/0,IDELIB_DRIVE_SELECT_MODE_CHS); /* in case the IDE controller is busy for that time */ c = do_ide_controller_user_wait_busy_controller(ide); if (c != 0) return; /* read back: did the drive select take effect? if not, it might not be there. another common sign is the head/drive select reads back 0xFF */ c = do_ide_controller_drive_check_select(ide,which); if (c < 0) return; /* it might be a CD-ROM drive, which in some cases might not raise the Drive Ready bit */ do_ide_controller_atapi_device_check_post_host_reset(ide); /* wait for the drive to indicate readiness */ /* NTS: If the drive never becomes ready even despite our reset hacks, there's a strong * possibility that the device doesn't exist. This can happen for example if there * is a master attached but no slave. */ c = do_ide_controller_user_wait_drive_ready(ide); if (c < 0) return; /* for completeness, clear pending IRQ */ idelib_controller_ack_irq(ide); while (1) { if (backredraw) { backredraw = 0; redraw = 1; background_draw(); vga_moveto(0,0); header_write("CD-ROM eject/load",ide,which); } if (redraw) { redraw = 0; vga_moveto(mbox.ofsx,mbox.ofsy - 2); vga_write_color((select == -1) ? 0x70 : 0x0F); vga_write("Back to IDE drive main menu"); while (vga_state.vga_pos_x < (mbox.width+mbox.ofsx) && vga_state.vga_pos_x != 0) vga_writec(' '); menuboxbound_redraw(&mbox,select); } c = getch(); if (c == 0) c = getch() << 8; if (c == 27) { break; } else if (c == 13) { if (select == -1) break; switch (select) { case 0: /* show IDE register taskfile */ do_common_show_ide_taskfile(ide,which); redraw = backredraw = 1; break; case 1: /*Eject*/ case 2: /*Load*/ case 3: /*Start*/ case 4: /*Stop*/ { static const unsigned char cmd[4] = {2/*eject*/,3/*load*/,1/*start*/,0/*stop*/}; do_drive_atapi_eject_load(ide,which,cmd[select-1]); } break; }; } else if (c == 0x4800) { if (--select < -1) select = mbox.item_max; redraw = 1; } else if (c == 0x4B00) { /* left */ redraw = 1; } else if (c == 0x4D00) { /* right */ redraw = 1; } else if (c == 0x5000) { if (++select > mbox.item_max) select = -1; redraw = 1; } } }