/* * Routine: * Purpose: * Algorithm: * Data Structures: * * Params: * Returns: * Called By: * Calls: * Assumptions: * Side Effects: * TODO: None */ int pr_s_web_return(void *pSrc) { struct S_WEB_RETURNS_TBL *r; if (pSrc == NULL) r = &g_s_web_returns; else r = pSrc; print_start(S_WEB_RETURNS); print_id(S_WRET_SITE_ID, r->kSiteID, 1); print_key(S_WRET_ORDER_ID,r->kOrderID, 1); print_integer(S_WRET_LINE_NUMBER, r->nLineNumber, 1); print_id(S_WRET_ITEM_ID, r->kItemID, 1); print_id(S_WRET_RETURN_CUST_ID, r->kReturningCustomerID, 1); print_id(S_WRET_REFUND_CUST_ID,r->kRefundedCustomerID, 1); print_date(S_WRET_RETURN_DATE, r->dtReturnDate.julian, 1); print_time(S_WRET_RETURN_TIME, r->kReturnTime, 1); print_integer(S_WRET_PRICING, r->Pricing.quantity, 1); print_decimal(S_WRET_PRICING, &r->Pricing.ext_sales_price, 1); print_decimal(S_WRET_PRICING, &r->Pricing.ext_tax, 1); print_decimal(S_WRET_PRICING, &r->Pricing.fee, 1); print_decimal(S_WRET_PRICING, &r->Pricing.ext_ship_cost, 1); print_decimal(S_WRET_PRICING, &r->Pricing.refunded_cash, 1); print_decimal(S_WRET_PRICING, &r->Pricing.reversed_charge, 1); print_decimal(S_WRET_PRICING, &r->Pricing.store_credit, 1); print_id(S_WRET_REASON_ID, r->kReasonID, 0); print_end(S_WEB_RETURNS); return(0); }
int main(int argc, char *argv[]) { fprintf(stderr, "bootimg-id by Chainfire\n\n"); if ((argc == 2) || (argc == 3)) { unsigned char buffer[BLOCK_SIZE]; if (read_block(argv[1], buffer)) return 1; print_id(buffer, ID_INDEX); if (argc == 2) return 0; char* parse = argv[2]; if (!strncmp(parse, "0x", 2)) parse = &parse[2]; if (strlen(parse) != ID_LENGTH * 2) { fprintf(stderr, "id length mismatch, expected %d, got %d (excluding 0x)\n", ID_LENGTH, strlen(parse)); } unsigned char id[ID_LENGTH]; char hex[3]; int i; for (i = 0; i < ID_LENGTH; i++) { memcpy(hex, &parse[i * 2], 2); id[i] = strtol(hex, NULL, 16); } print_id(id, 0); memcpy(&buffer[ID_INDEX], id, ID_LENGTH); if (write_block(argv[1], buffer)) return 1; return 0; } else { fprintf(stderr, "bootimg-id blockdev # get\n"); fprintf(stderr, "bootimg-id blockdev id # set\n"); return 0; } }
int check_bin_op(ast::BinOp* bin_op) { assert(bin_op != nullptr); auto lhs = bin_op->left.get(); auto rhs = bin_op->right.get(); check_operation(lhs); check_operation(rhs); check_coercion(bin_op->from, lhs->type, bin_op->operator_, bin_op->id); check_coercion(bin_op->from, rhs->type, bin_op->operator_, bin_op->id); auto operators_without_coercion = std::set<std::string> {"add", "sub", "mul", "div", "and", "or"}; if(operators_without_coercion.count(bin_op->operator_) > 0) { return check_coercion(bin_op->type, bin_op->from, bin_op->operator_, bin_op->id); } auto operators_with_coercion_to_bool = std::set<std::string> {"eq", "lt"}; if(operators_with_coercion_to_bool.count(bin_op->operator_) > 0) { return check_coercion(bin_op->type, ast::types::Bool, bin_op->operator_, bin_op->id); } std::cout << "Unknown binary operation " << bin_op->operator_ << " of type "; pretty_print::type(std::cout, lhs->type); std::cout << " * "; pretty_print::type(std::cout, rhs->type); std::cout << " -> "; pretty_print::type(std::cout, bin_op->type); print_id(bin_op->id); std::cout << std::endl; return EXIT_FAILURE; }
int print_struct_def(struct struct_def *sdef, long long offset, char *data) { struct struct_member *member; struct type_info *tinfo; int end; if (sdef->type == TYPE_ENUM) { my_printf("0x%lx",*((int*)data)); return 4; } if (sdef->type != TYPE_STRUCTURE) return 0; if (!sdef) { my_printf("Structure not found\n"); return 0; } my_printf("\n"); indent_struct(offset); my_printf("struct %s size=%d {\n", sdef->name, sdef->size); indent++; member = sdef->members; while(member != NULL) { indent_struct(member->offset + offset); col += my_printf("%s",member->name); spaces(); tinfo = member->type; print_id(tinfo->id, offset + member->offset, data + (member->offset / 8)); end = member->offset + offset + member->size; member = member->next; my_printf("\n"); } indent--; indent_struct(end); my_printf("}"); return sdef->size; }
int print_array(struct type_info *tinfo, long long offset, char *data) { int id ; int btype; int start, end; int i; char *ptr; int len=0; if (tinfo->type != ARRAY) return 0; id = tinfo->id; btype = base_type(id); if (btype == TYPE_STRUCT || btype == TYPE_BASIC_UNION || btype == TYPE_ENUM) return 0; start = tinfo->info.atype.start_index; end = tinfo->info.atype.end_index; ptr = data; my_printf("[ "); for (i = start; i <= end ; i ++) { len = print_id(id, offset, ptr); if (i != end ) my_printf(" , "); ptr += len; } my_printf(" ]"); if (btype == CHAR || btype == UCHAR) { my_printf(" \"%s\"", data); } return 0; }
// callback for timer void timer_callback(int fd, short ev, void *arg) { int n1, n2; n1 = abs(mrand48()) % max_node; n2 = abs(mrand48()) % max_node; // send datagram const char *str = "Hello, world!"; uint8_t id[CAGE_ID_LEN]; cage[n2].get_id(id); printf("send datagram: to = "); print_id(id); cage[n1].send_dgram(str, strlen(str), id); // reschedule timeval tval; tval.tv_sec = 1; tval.tv_usec = 0; evtimer_add(::ev, &tval); }
/* * Print the truth table */ static void print_tt(void) { uint32_t i, j, n; uint32_t mask, b; n = ttsize; // print headers for (i=0; i<n; i++) { if (! fresh[i]) { print_id(i); } } printf("\n\n"); // print bits mask = 0x1; for (j=0; j<32; j++) { for (i=0; i<n; i++) { if (! fresh[i]) { b = ((mask & tt[i]) != 0); printf(" %"PRIu32" ", b); } } printf("\n"); mask <<= 1; } printf("\n"); }
static int display_entry(int offset) { lseek(dbase_fd, offset + HDRSIZE, L_SET); if (read(dbase_fd, &pre, sizeof(struct prentry)) < 0) { fprintf(stderr, "pt_util: error reading entry %d: %s\n", offset, strerror(errno)); exit(1); } fix_pre(&pre); if ((pre.flags & PRFREE) == 0) { if (pre.flags & PRGRP) { if (flags & DO_GRP) add_group(pre.id); } else { if (print_id(pre.id) && (flags & DO_USR)) fprintf(dfp, FMT_BASE, pre.name, pre.flags, pre.ngroups, pre.id, pre.owner, pre.creator); checkin(&pre); } } return (nflag ? pre.nextName : pre.nextID); }
int check_un_op(ast::UnOp* un_op) { assert(un_op != nullptr); auto value = un_op->value.get(); check_operation(value); switch(un_op->type) { case ast::types::Int32: if(un_op->operator_ == "neg") { return assert_type(un_op->type, value->type, un_op->operator_, un_op->id); } break; case ast::types::Float32: if(un_op->operator_ == "neg") { return assert_type(un_op->type, value->type, un_op->operator_, un_op->id); } break; case ast::types::Bool: if(un_op->operator_ == "not") { return assert_type(un_op->type, value->type, un_op->operator_, un_op->id); } break; default: break; } std::cout << "Unknown unary operation " << un_op->operator_ << " of type "; pretty_print::type(std::cout, value->type); std::cout << " -> "; pretty_print::type(std::cout, un_op-> type); print_id(un_op->id); std::cout << std::endl; return EXIT_FAILURE; }
void assert_existing_variable(llvm::StringMapIterator<ast::Variable> ptr, std::string identifier, int id = -1) { if(ptr == variables.end()) { std::cout << "Unknown variable " << identifier; print_id(id); std::cout << std::endl; } }
int main(){ pid_t child1_pid, child2_pid, child3_pid, child4_pid; int status = 0; child1_pid = print_if_error(fork()); if (child1_pid == 0) { print_id(); printf("Computing binomial coefficient"); } child2_pid = print_if_error(fork()); if (child2_pid == 0){ sleep(1); print_id(); process(2, 2); } else { waitpid(child1_pid, &status, 0); printf("child1 terminated\n"); child3_pid = print_if_error(fork()); if(child3_pid == 0){ sleep(2); print_id(); process(3, 3); } else{ waitpid(child3_pid, &status, 0); printf("child 3 terminated\n"); } waitpid(child2_pid, &status, 0); printf("child2 terminated\n"); child4_pid = print_if_error(fork()); if(child4_pid == 0){ sleep(1); print_id(); system("ls -l"); } else { waitpid(child4_pid, &status, 0); printf("child4 terminated\n"); } } return 0; }
void* child(void * arg) { printf("[child] started\n"); printf("[child] tls fs: %p\n", (void*) get_fs()); printf("[child] tls gs: %p\n", (void*) get_gs()); print_id("child", 0, &thread_i); usleep(500000); return NULL; }
int declare_variable(ast::Variable& it) { if(variables.find(it.identifier) != variables.end()) { std::cout << "Variable shadowing of " << it.identifier; print_id(it.id); std::cout << std::endl; } variables.insert(std::pair<llvm::StringRef, ast::Variable>(it.identifier, it)); return EXIT_SUCCESS; }
int assert_type(ast::types::Type ltype, ast::types::Type rtype, std::string operation, int id = -1) { if(ltype != rtype) { std::cout << "Bad type of " << operation; print_id(id); std::cout << std::endl; type_mismatch(ltype, rtype); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int declare_extern(ast::Extern* extrn) { assert(extrn != nullptr); if(functions.find(extrn->identifier) != functions.end()) { std::cout << "Double declaration of " << extrn->identifier; print_id(extrn->id); std::cout << std::endl; } functions.insert(std::pair<llvm::StringRef, ast::Extern>(extrn->identifier, *extrn)); return EXIT_SUCCESS; }
int main(void) { int tid, status; printf("[main_] started\n"); printf("[main_] tls fs: %p\n", (void*) get_fs()); printf("[main_] tls gs: %p\n", (void*) get_gs()); tid = new_thread(&child); printf("[main_] child launched: %d\n", tid); print_id("main_", 1, &thread_i); usleep(500000); return EXIT_SUCCESS; }
static int display_entry(int offset) { lseek(dbase_fd, offset + HDRSIZE, L_SET); read(dbase_fd, &pre, sizeof(struct prentry)); fix_pre(&pre); if ((pre.flags & PRFREE) == 0) { if (pre.flags & PRGRP) { if (flags & DO_GRP) add_group(pre.id); } else { if (print_id(pre.id) && (flags & DO_USR)) fprintf(dfp, FMT_BASE, pre.name, pre.flags, pre.ngroups, pre.id, pre.owner, pre.creator); checkin(&pre); } } return (nflag ? pre.nextName : pre.nextID); }
/* * Routine: * Purpose: * Algorithm: * Data Structures: * * Params: * Returns: * Called By: * Calls: * Assumptions: * Side Effects: * TODO: None */ int pr_s_customer (void *pSrc) { struct S_CUSTOMER_TBL *r; char szTemp[6]; if (pSrc == NULL) r = &g_s_customer; else r = pSrc; print_start (S_CUSTOMER); print_id (S_CUST_ID, r->kID, 1); print_varchar (S_CUST_SALUTATION, r->pSalutation, 1); print_varchar (S_CUST_LAST_NAME, r->pLastName, 1); print_varchar (S_CUST_FIRST_NAME, r->pFirstName, 1); print_boolean (S_CUST_PREFERRED_FLAG, r->bPreferredFlag, 1); print_date (S_CUST_BIRTH_DATE, r->dtBirthDate.julian, 1); print_varchar (S_CUST_BIRTH_COUNTRY, r->pBirthCountry, 1); print_varchar (S_CUST_LOGIN, r->szLogin, 1); print_varchar (S_CUST_EMAIL, r->szEmail, 1); print_date (S_CUST_LAST_LOGIN, r->dtLastLogin.julian, 1); print_date (S_CUST_FIRST_SHIPTO_DATE, r->dtFirstShipToDate.julian, 1); print_date (S_CUST_FIRST_PURCHASE_DATE, r->dtFirstPurchaseDate.julian, 1); print_date (S_CUST_LAST_REVIEW, r->dtReview.julian, 1); print_varchar (S_CUST_PRIMARY_MACHINE, r->szPrimaryMachine, 1); print_varchar (S_CUST_SECONDARY_MACHINE, r->szSecondaryMachine, 1); print_integer (S_CUST_ADDRESS_STREET_NUM, g_w_customer_address.ca_address.street_num, 1); print_varchar (S_CUST_ADDRESS_SUITE_NUM, g_w_customer_address.ca_address.suite_num, 1); print_varchar (S_CUST_ADDRESS_STREET_NAME1, g_w_customer_address.ca_address.street_name1, 1); print_varchar (S_CUST_ADDRESS_STREET_NAME2, g_w_customer_address.ca_address.street_name2, 1); print_varchar (S_CUST_ADDRESS_STREET_TYPE, g_w_customer_address.ca_address.street_type, 1); print_varchar (S_CUST_ADDRESS_CITY, g_w_customer_address.ca_address.city, 1); sprintf (szTemp, "%05d", g_w_customer_address.ca_address.zip); print_varchar (S_CUST_ADDRESS_ZIP, szTemp, 1); print_varchar (S_CUST_ADDRESS_COUNTY, g_w_customer_address.ca_address.county, 1); print_varchar (S_CUST_ADDRESS_STATE, g_w_customer_address.ca_address.state, 1); print_varchar (S_CUST_ADDRESS_COUNTRY, g_w_customer_address.ca_address.country, 1); print_varchar (S_CUST_LOCATION_TYPE, r->pLocationType, 1); print_varchar (S_CUST_GENDER, r->sGender, 1); print_varchar (S_CUST_MARITAL_STATUS, r->pMaritalStatus, 1); print_varchar (S_CUST_EDUCATION, r->pEducation, 1); print_varchar (S_CUST_CREDIT_RATING, r->pCreditRating, 1); print_integer (S_CUST_PURCHASE_ESTIMATE, r->nPurchaseEstimate, 1); print_varchar (S_CUST_BUY_POTENTIAL, r->pBuyPotential, 1); print_integer (S_CUST_DEPENDENT_CNT, r->nDependents, 1); print_integer (S_CUST_EMPLOYED_CNT, r->nEmployed, 1); print_integer (S_CUST_COLLEGE_CNT, r->nCollege, 1); print_integer (S_CUST_VEHICLE_CNT, r->nVehicle, 1); print_decimal (S_CUST_INCOME, &r->dIncome, 0); print_end (S_CUSTOMER); return (0); }
int main(int argc, char **argv) { /** Port offset is used when you want to start multiple sets of i3 servers * on the same set of planetlab nodes. The port numbers of the different * i3 servers running on the same planetlab node should not clash. * So we specificy an offset. */ int port_offset = 0; int get_addr_ok_flag = 0; int i, j, k, i3_port, validate_port; Node *nodes; char filename[100], name[100]; FILE *fp, *fd, *i3clientconf_fd; #ifdef NEWS FILE *newsconf_fd; #endif struct in_addr ia; #define MAX_NUM_NODES 1000 if (argc < 3) { fprintf(stderr, "usage: %s server_list cfg_file_prefix [port_offset]\n", argv[0]); exit(-1); } if (argc > 3) { //Read the optional port offset which has been specified. port_offset = atoi(argv[3]); } else { port_offset = 0; } srandom(getpid() ^ time(0)); nodes = (Node *) malloc(MAX_NUM_NODES * sizeof(Node)); fd = fopen(argv[1], "r"); k = 0; while (!feof(fd)) { if (k == MAX_NUM_NODES) break; fscanf(fd, "%s\n", name); nodes[k].id = rand_ID(); //set_loworder_bits(&(nodes[k].id)); nodes[k].addr = ntohl(get_addr1(name, &get_addr_ok_flag)); nodes[k].port = (4710 + port_offset) + k; if (get_addr_ok_flag) { //advance counter only if we were able to successfully lookup the address //This is equivalent to ignoring this node. k++; } } fclose(fd); //create a directory to hold the configuration files mkdir (argv[2], S_IRUSR|S_IWUSR|S_IEXEC); sprintf(filename, "%s/%s_i3client.conf", argv[2], argv[2]); i3clientconf_fd = fopen(filename, "w"); #ifdef NEWS sprintf(filename, "%s/%s_i3news.conf", argv[2], argv[2]); newsconf_fd = fopen(filename, "w"); #endif for (i = 0; i < k; i++) { i3_port = nodes[i].port - (4710 + port_offset) + (5610 + port_offset); validate_port = nodes[i].port - (4710 + port_offset) + (7810 + port_offset); ia.s_addr = htonl(nodes[i].addr); fprintf(i3clientconf_fd, "%s %d\n", inet_ntoa(ia), i3_port); #ifdef NEWS fprintf(newsconf_fd, "%s %d %d ", inet_ntoa(ia), i3_port, validate_port); print_id(newsconf_fd, &nodes[i].id); fprintf(newsconf_fd, "\n"); #endif #ifdef NEWS sprintf(filename, "%s/%s_%s_%d_%d_%d.cfg", argv[2], argv[2], inet_ntoa(ia), i3_port, validate_port, nodes[i].port); #else sprintf(filename, "%s/%s_%s_%d_%d.cfg", argv[2], argv[2], inet_ntoa(ia), i3_port, nodes[i].port); #endif fp = fopen(filename, "w"); fprintf(fp, "%d ", nodes[i].port); print_id(fp, &nodes[i].id); fprintf(fp, "\n"); for (j = 0; j < k; j++) { if (j == i) continue; ia.s_addr = htonl(nodes[j].addr); fprintf(fp, "%s:%d ", inet_ntoa(ia), nodes[j].port); fprintf(fp, "\n"); } fclose(fp); } fclose(i3clientconf_fd); #ifdef NEWS fclose(newsconf_fd); #endif return 0; }
int main(int argc, char **argv) { boot_img_hdr hdr; char *kernel_fn = NULL; void *kernel_data = NULL; char *ramdisk_fn = NULL; void *ramdisk_data = NULL; char *second_fn = NULL; void *second_data = NULL; char *cmdline = ""; char *bootimg = NULL; char *board = ""; char *dt_fn = NULL; void *dt_data = NULL; uint32_t pagesize = 2048; int fd; SHA_CTX ctx; const uint8_t* sha; uint32_t base = 0x10000000U; uint32_t kernel_offset = 0xFE208100; uint32_t ramdisk_offset = 0x00200100; uint32_t second_offset = 0xFF100100; uint32_t tags_offset = 0x00000100U; size_t cmdlen; argc--; argv++; memset(&hdr, 0, sizeof(hdr)); bool get_id = false; while(argc > 0){ char *arg = argv[0]; if (!strcmp(arg, "--id")) { get_id = true; argc -= 1; argv += 1; } else if(argc >= 2) { char *val = argv[1]; argc -= 2; argv += 2; if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) { bootimg = val; } else if(!strcmp(arg, "--kernel")) { kernel_fn = val; } else if(!strcmp(arg, "--ramdisk")) { ramdisk_fn = val; } else if(!strcmp(arg, "--second")) { second_fn = val; } else if(!strcmp(arg, "--cmdline")) { cmdline = val; } else if(!strcmp(arg, "--base")) { base = strtoul(val, 0, 16); } else if(!strcmp(arg, "--kernel_offset")) { kernel_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--ramdisk_offset")) { ramdisk_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--second_offset")) { second_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--tags_offset")) { tags_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--board")) { board = val; } else if(!strcmp(arg,"--pagesize")) { pagesize = strtoul(val, 0, 10); if ((pagesize != 2048) && (pagesize != 4096) && (pagesize != 8192) && (pagesize != 16384) && (pagesize != 32768) && (pagesize != 65536) && (pagesize != 131072)) { fprintf(stderr,"error: unsupported page size %d\n", pagesize); return -1; } } else if(!strcmp(arg, "--dt")) { dt_fn = val; } else { return usage(); } } else { return usage(); } } hdr.page_size = pagesize; hdr.kernel_addr = base + kernel_offset; hdr.ramdisk_addr = base + ramdisk_offset; hdr.second_addr = base + second_offset; hdr.tags_addr = base + tags_offset; if(bootimg == 0) { fprintf(stderr,"error: no output filename specified\n"); return usage(); } if(kernel_fn == 0) { fprintf(stderr,"error: no kernel image specified\n"); return usage(); } if(ramdisk_fn == 0) { fprintf(stderr,"error: no ramdisk image specified\n"); return usage(); } if(strlen(board) >= BOOT_NAME_SIZE) { fprintf(stderr,"error: board name too large\n"); return usage(); } strcpy((char *) hdr.name, board); memcpy(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE); cmdlen = strlen(cmdline); if(cmdlen > (BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE - 2)) { fprintf(stderr,"error: kernel commandline too large\n"); return 1; } /* Even if we need to use the supplemental field, ensure we * are still NULL-terminated */ strncpy((char *)hdr.cmdline, cmdline, BOOT_ARGS_SIZE - 1); hdr.cmdline[BOOT_ARGS_SIZE - 1] = '\0'; if (cmdlen >= (BOOT_ARGS_SIZE - 1)) { cmdline += (BOOT_ARGS_SIZE - 1); strncpy((char *)hdr.extra_cmdline, cmdline, BOOT_EXTRA_ARGS_SIZE); } kernel_data = load_file(kernel_fn, &hdr.kernel_size); if(kernel_data == 0) { fprintf(stderr,"error: could not load kernel '%s'\n", kernel_fn); return 1; } if(!strcmp(ramdisk_fn,"NONE")) { ramdisk_data = 0; hdr.ramdisk_size = 0; } else { ramdisk_data = load_file(ramdisk_fn, &hdr.ramdisk_size); if(ramdisk_data == 0) { fprintf(stderr,"error: could not load ramdisk '%s'\n", ramdisk_fn); return 1; } } if(second_fn) { second_data = load_file(second_fn, &hdr.second_size); if(second_data == 0) { fprintf(stderr,"error: could not load secondstage '%s'\n", second_fn); return 1; } } if(dt_fn) { dt_data = load_file(dt_fn, &hdr.dt_size); if (dt_data == 0) { fprintf(stderr,"error: could not load device tree image '%s'\n", dt_fn); return 1; } } /* put a hash of the contents in the header so boot images can be * differentiated based on their first 2k. */ SHA_init(&ctx); SHA_update(&ctx, kernel_data, hdr.kernel_size); SHA_update(&ctx, &hdr.kernel_size, sizeof(hdr.kernel_size)); SHA_update(&ctx, ramdisk_data, hdr.ramdisk_size); SHA_update(&ctx, &hdr.ramdisk_size, sizeof(hdr.ramdisk_size)); SHA_update(&ctx, second_data, hdr.second_size); SHA_update(&ctx, &hdr.second_size, sizeof(hdr.second_size)); if(dt_data) { SHA_update(&ctx, dt_data, hdr.dt_size); SHA_update(&ctx, &hdr.dt_size, sizeof(hdr.dt_size)); } sha = SHA_final(&ctx); memcpy(hdr.id, sha, SHA_DIGEST_SIZE > sizeof(hdr.id) ? sizeof(hdr.id) : SHA_DIGEST_SIZE); fd = open(bootimg, O_CREAT | O_TRUNC | O_WRONLY, 0644); if(fd < 0) { fprintf(stderr,"error: could not create '%s'\n", bootimg); return 1; } if(write(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) goto fail; if(write_padding(fd, pagesize, sizeof(hdr))) goto fail; if(write(fd, kernel_data, hdr.kernel_size) != (ssize_t) hdr.kernel_size) goto fail; if(write_padding(fd, pagesize, hdr.kernel_size)) goto fail; if(write(fd, ramdisk_data, hdr.ramdisk_size) != (ssize_t) hdr.ramdisk_size) goto fail; if(write_padding(fd, pagesize, hdr.ramdisk_size)) goto fail; if(second_data) { if(write(fd, second_data, hdr.second_size) != (ssize_t) hdr.second_size) goto fail; if(write_padding(fd, pagesize, hdr.second_size)) goto fail; } if(dt_data) { if(write(fd, dt_data, hdr.dt_size) != (ssize_t) hdr.dt_size) goto fail; if(write_padding(fd, pagesize, hdr.dt_size)) goto fail; } if (get_id) { print_id((uint8_t *) hdr.id, sizeof(hdr.id)); } return 0; fail: unlink(bootimg); close(fd); fprintf(stderr,"error: failed writing '%s': %s\n", bootimg, strerror(errno)); return 1; }
int main(int argc, char **argv) { const char * newkeyfile = NULL; int keyswanted = 0; char * tok, * brkb = NULL, * eptr; long keynum; uint64_t machinenum = (uint64_t)(-1); uint64_t kfmachinenum; const char * missingkey; int passphrased = 0; uint64_t maxmem = 0; double maxtime = 1.0; char * passphrase; const char * print_key_id_file = NULL; const char * print_key_permissions_file = NULL; const char * ch; char * optarg_copy; /* for strtok_r. */ WARNP_INIT; /* Initialize key cache. */ if (crypto_keys_init()) { warnp("Key cache initialization failed"); exit(1); } /* Parse arguments. */ while ((ch = GETOPT(argc, argv)) != NULL) { GETOPT_SWITCH(ch) { GETOPT_OPTARG("--outkeyfile"): if (newkeyfile != NULL) usage(); newkeyfile = optarg; break; GETOPT_OPT("-r"): keyswanted |= CRYPTO_KEYMASK_READ; break; GETOPT_OPT("-w"): keyswanted |= CRYPTO_KEYMASK_WRITE; break; GETOPT_OPT("-d"): /* * Deleting data requires both delete authorization * and being able to read archives -- we need to be * able to figure out which bits are part of the * archive. */ keyswanted |= CRYPTO_KEYMASK_READ; keyswanted |= CRYPTO_KEYMASK_AUTH_DELETE; break; GETOPT_OPT("--nuke"): keyswanted |= CRYPTO_KEYMASK_AUTH_DELETE; break; GETOPT_OPTARG("--keylist"): /* * This is a deliberately undocumented option used * mostly for testing purposes; it allows a list of * keys to be specified according to their numbers in * crypto/crypto.h instead of using the predefined * sets of "read", "write" and "delete" keys. */ if ((optarg_copy = strdup(optarg)) == NULL) { warn0("Out of memory"); exit(0); } for (tok = strtok_r(optarg_copy, ",", &brkb); tok; tok = strtok_r(NULL, ",", &brkb)) { keynum = strtol(tok, &eptr, 0); if ((eptr == tok) || (keynum < 0) || (keynum > 31)) { warn0("Not a valid key number: %s", tok); free(optarg_copy); exit(1); } keyswanted |= (uint32_t)(1) << keynum; } free(optarg_copy); break; GETOPT_OPTARG("--passphrase-mem"): if (maxmem != 0) usage(); if (humansize_parse(optarg, &maxmem)) { warnp("Cannot parse --passphrase-mem" " argument: %s", optarg); exit(1); } break; GETOPT_OPTARG("--passphrase-time"): if (maxtime != 1.0) usage(); maxtime = strtod(optarg, NULL); if ((maxtime < 0.05) || (maxtime > 86400)) { warn0("Invalid --passphrase-time argument: %s", optarg); exit(1); } break; GETOPT_OPT("--passphrased"): if (passphrased != 0) usage(); passphrased = 1; break; GETOPT_OPTARG("--print-key-id"): if (print_key_id_file != NULL) usage(); print_key_id_file = optarg; break; GETOPT_OPTARG("--print-key-permissions"): if (print_key_permissions_file != NULL) usage(); print_key_permissions_file = optarg; break; GETOPT_MISSING_ARG: warn0("Missing argument to %s\n", ch); /* FALLTHROUGH */ GETOPT_DEFAULT: usage(); } } argc -= optind; argv += optind; /* We can't print ID and permissions at the same time. */ if ((print_key_id_file != NULL) && (print_key_permissions_file != NULL)) usage(); if ((print_key_id_file != NULL) || (print_key_permissions_file != NULL)) { /* We can't combine printing info with generating a new key. */ if (newkeyfile != NULL) usage(); /* We should have processed all arguments. */ if (argc != 0) usage(); /* Print info. */ if (print_key_id_file != NULL) print_id(print_key_id_file); if (print_key_permissions_file != NULL) print_permissions(print_key_permissions_file); } /* We should have an output key file. */ if (newkeyfile == NULL) usage(); /* * It doesn't make sense to specify --passphrase-mem or * --passphrase-time if we're not using a passphrase. */ if (((maxmem != 0) || (maxtime != 1.0)) && (passphrased == 0)) usage(); /* Warn the user if they're being silly. */ if (keyswanted == 0) { warn0("None of {-r, -w, -d, --nuke} options are specified." " This will create a key file with no keys, which is" " probably not what you intended."); } /* Read the specified key files. */ while (argc-- > 0) { /* * Suck in the key file. We could mask this to only load the * keys we want to copy, but there's no point really since we * export keys selectively. */ if (keyfile_read(argv[0], &kfmachinenum, ~0)) { warnp("Cannot read key file: %s", argv[0]); exit(1); } /* * Check that we're not using key files which belong to * different machines. */ if (machinenum == (uint64_t)(-1)) { machinenum = kfmachinenum; } else if (machinenum != kfmachinenum) { warn0("Keys from %s do not belong to the " "same machine as earlier keys", argv[0]); exit(1); } /* Move on to the next file. */ argv++; } /* Make sure that we have the necessary keys. */ if ((missingkey = crypto_keys_missing(keyswanted)) != NULL) { warn0("The %s key is required but not in any input key files", missingkey); exit(1); } /* If the user wants to passphrase the keyfile, get the passphrase. */ if (passphrased != 0) { if (readpass(&passphrase, "Please enter passphrase for keyfile encryption", "Please confirm passphrase for keyfile encryption", 1)) { warnp("Error reading password"); exit(1); } } else { passphrase = NULL; } /* Write out new key file. */ if (keyfile_write(newkeyfile, machinenum, keyswanted, passphrase, maxmem, maxtime)) exit(1); /* Success! */ return (0); }
void chord_main(char *conf_file, int parent_sock) { fd_set interesting, readable; int nfound, nfds; struct in_addr ia; char id[4*ID_LEN]; FILE *fp; int64_t stabilize_wait; struct timeval timeout; setprogname("chord"); srandom(getpid() ^ time(0)); memset(&srv, 0, sizeof(Server)); srv.to_fix_finger = NFINGERS-1; fp = fopen(conf_file, "r"); if (fp == NULL) eprintf("fopen(%s,\"r\") failed:", conf_file); if (fscanf(fp, "%hd", (short*)&srv.node.port) != 1) eprintf("Didn't find port in \"%s\"", conf_file); if (fscanf(fp, " %s\n", id) != 1) eprintf("Didn't find id in \"%s\"", conf_file); srv.node.id = atoid(id); /* Figure out one's own address somehow */ srv.node.addr = ntohl(get_addr()); ia.s_addr = htonl(srv.node.addr); fprintf(stderr, "Chord started.\n"); fprintf(stderr, "id="); print_id(stderr, &srv.node.id); fprintf(stderr, "\n"); fprintf(stderr, "ip=%s\n", inet_ntoa(ia)); fprintf(stderr, "port=%d\n", srv.node.port); initialize(&srv); srv_ref = &srv; join(&srv, fp); fclose(fp); FD_ZERO(&interesting); FD_SET(srv.in_sock, &interesting); FD_SET(parent_sock, &interesting); nfds = MAX(srv.in_sock, parent_sock) + 1; NumKeys = read_keys(ACCLIST_FILE, KeyArray, MAX_KEY_NUM); if (NumKeys == -1) { printf("Error opening file: %s\n", ACCLIST_FILE); } if (NumKeys == 0) { printf("No key found in %s\n", ACCLIST_FILE); } /* Loop on input */ for (;;) { readable = interesting; stabilize_wait = (int64_t)(srv.next_stabilize_us - wall_time()); stabilize_wait = MAX(stabilize_wait,0); timeout.tv_sec = stabilize_wait / 1000000UL; timeout.tv_usec = stabilize_wait % 1000000UL; nfound = select(nfds, &readable, NULL, NULL, &timeout); if (nfound < 0 && errno == EINTR) { continue; } if (nfound == 0) { stabilize_wait = (int64_t)(srv.next_stabilize_us - wall_time()); if( stabilize_wait <= 0 ) { stabilize( &srv ); } continue; } if (FD_ISSET(srv.in_sock, &readable)) { handle_packet(srv.in_sock); } else if (FD_ISSET(parent_sock, &readable)) { handle_packet(parent_sock); } else { assert(0); } } }
int main(int argc, char **argv) { boot_img_hdr_v2 hdr; char *kernel_fn = NULL; void *kernel_data = NULL; char *ramdisk_fn = NULL; void *ramdisk_data = NULL; char *second_fn = NULL; void *second_data = NULL; char *dtb_fn = NULL; void *dtb_data = NULL; char *recovery_dtbo_fn = NULL; void *recovery_dtbo_data = NULL; char *cmdline = ""; char *bootimg = NULL; char *board = ""; int os_version = 0; int os_patch_level = 0; int header_version = 0; char *dt_fn = NULL; void *dt_data = NULL; uint32_t pagesize = 2048; int fd; uint32_t base = 0x10000000U; uint32_t kernel_offset = 0x00008000U; uint32_t ramdisk_offset = 0x01000000U; uint32_t second_offset = 0x00f00000U; uint32_t tags_offset = 0x00000100U; uint32_t kernel_sz = 0; uint32_t ramdisk_sz = 0; uint32_t second_sz = 0; uint32_t dt_sz = 0; uint32_t rec_dtbo_sz = 0; uint64_t rec_dtbo_offset= 0; uint32_t header_sz = 0; uint32_t dtb_sz = 0; uint64_t dtb_offset = 0x01f00000U; size_t cmdlen; enum hash_alg hash_alg = HASH_SHA1; argc--; argv++; memset(&hdr, 0, sizeof(hdr)); bool get_id = false; while(argc > 0){ char *arg = argv[0]; if(!strcmp(arg, "--id")) { get_id = true; argc -= 1; argv += 1; } else if(argc >= 2) { char *val = argv[1]; argc -= 2; argv += 2; if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) { bootimg = val; } else if(!strcmp(arg, "--kernel")) { kernel_fn = val; } else if(!strcmp(arg, "--ramdisk")) { ramdisk_fn = val; } else if(!strcmp(arg, "--second")) { second_fn = val; } else if(!strcmp(arg, "--dtb")) { dtb_fn = val; } else if(!strcmp(arg, "--recovery_dtbo") || !strcmp(arg, "--recovery_acpio")) { recovery_dtbo_fn = val; } else if(!strcmp(arg, "--cmdline")) { cmdline = val; } else if(!strcmp(arg, "--base")) { base = strtoul(val, 0, 16); } else if(!strcmp(arg, "--kernel_offset")) { kernel_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--ramdisk_offset")) { ramdisk_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--second_offset")) { second_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--tags_offset")) { tags_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--dtb_offset")) { dtb_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--board")) { board = val; } else if(!strcmp(arg,"--pagesize")) { pagesize = strtoul(val, 0, 10); if((pagesize != 2048) && (pagesize != 4096) && (pagesize != 8192) && (pagesize != 16384) && (pagesize != 32768) && (pagesize != 65536) && (pagesize != 131072)) { fprintf(stderr,"error: unsupported page size %d\n", pagesize); return -1; } } else if(!strcmp(arg, "--dt")) { dt_fn = val; } else if(!strcmp(arg, "--os_version")) { os_version = parse_os_version(val); } else if(!strcmp(arg, "--os_patch_level")) { os_patch_level = parse_os_patch_level(val); } else if(!strcmp(arg, "--header_version")) { header_version = strtoul(val, 0, 10); } else if(!strcmp(arg, "--hash")) { hash_alg = parse_hash_alg(val); if(hash_alg == HASH_UNKNOWN) { fprintf(stderr, "error: unknown hash algorithm '%s'\n", val); return -1; } } else { return usage(); } } else { return usage(); } } hdr.page_size = pagesize; hdr.kernel_addr = base + kernel_offset; hdr.ramdisk_addr = base + ramdisk_offset; hdr.second_addr = base + second_offset; hdr.tags_addr = base + tags_offset; hdr.header_version = header_version; hdr.os_version = (os_version << 11) | os_patch_level; if(bootimg == 0) { fprintf(stderr,"error: no output filename specified\n"); return usage(); } if(kernel_fn == 0) { fprintf(stderr,"error: no kernel image specified\n"); return usage(); } if(strlen(board) >= BOOT_NAME_SIZE) { fprintf(stderr,"error: board name too large\n"); return usage(); } strcpy((char *) hdr.name, board); memcpy(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE); cmdlen = strlen(cmdline); if(cmdlen <= BOOT_ARGS_SIZE) { strcpy((char *)hdr.cmdline, cmdline); } else if(cmdlen <= BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE) { /* exceeds the limits of the base command-line size, go for the extra */ memcpy(hdr.cmdline, cmdline, BOOT_ARGS_SIZE); strcpy((char *)hdr.extra_cmdline, cmdline+BOOT_ARGS_SIZE); } else { fprintf(stderr,"error: kernel commandline too large\n"); return 1; } kernel_data = load_file(kernel_fn, &kernel_sz); if(kernel_data == 0) { fprintf(stderr,"error: could not load kernel '%s'\n", kernel_fn); return 1; } hdr.kernel_size = kernel_sz; if(ramdisk_fn == NULL) { ramdisk_data = 0; } else { ramdisk_data = load_file(ramdisk_fn, &ramdisk_sz); if(ramdisk_data == 0) { fprintf(stderr,"error: could not load ramdisk '%s'\n", ramdisk_fn); return 1; } } hdr.ramdisk_size = ramdisk_sz; if(second_fn) { second_data = load_file(second_fn, &second_sz); if(second_data == 0) { fprintf(stderr,"error: could not load secondstage '%s'\n", second_fn); return 1; } } hdr.second_size = second_sz; if(header_version == 0) { if(dt_fn) { dt_data = load_file(dt_fn, &dt_sz); if(dt_data == 0) { fprintf(stderr,"error: could not load device tree image '%s'\n", dt_fn); return 1; } } hdr.dt_size = dt_sz; /* overrides hdr.header_version */ } else { if(recovery_dtbo_fn) { recovery_dtbo_data = load_file(recovery_dtbo_fn, &rec_dtbo_sz); if(recovery_dtbo_data == 0) { fprintf(stderr,"error: could not load recovery dtbo image '%s'\n", recovery_dtbo_fn); return 1; } /* header occupies a page */ rec_dtbo_offset = pagesize * (1 + \ (kernel_sz + pagesize - 1) / pagesize + \ (ramdisk_sz + pagesize - 1) / pagesize + \ (second_sz + pagesize - 1) / pagesize); } if(header_version == 1) { header_sz = 1648; } else { header_sz = sizeof(hdr); } if(header_version > 1) { if(dtb_fn) { dtb_data = load_file(dtb_fn, &dtb_sz); if(dtb_data == 0) { fprintf(stderr,"error: could not load recovery dtb image '%s'\n", dtb_fn); return 1; } } } } hdr.recovery_dtbo_size = rec_dtbo_sz; hdr.recovery_dtbo_offset = rec_dtbo_offset; hdr.header_size = header_sz; hdr.dtb_size = dtb_sz; if(header_version > 1) { hdr.dtb_addr = base + dtb_offset; } else { hdr.dtb_addr = 0; } /* put a hash of the contents in the header so boot images can be * differentiated based on their first 2k. */ generate_id(hash_alg, &hdr, kernel_data, ramdisk_data, second_data, dt_data, recovery_dtbo_data, dtb_data); fd = open(bootimg, O_CREAT | O_TRUNC | O_WRONLY, 0644); if(fd < 0) { fprintf(stderr,"error: could not create '%s'\n", bootimg); return 1; } if(write(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) goto fail; if(write_padding(fd, pagesize, sizeof(hdr))) goto fail; if(write(fd, kernel_data, hdr.kernel_size) != (ssize_t) hdr.kernel_size) goto fail; if(write_padding(fd, pagesize, hdr.kernel_size)) goto fail; if(write(fd, ramdisk_data, hdr.ramdisk_size) != (ssize_t) hdr.ramdisk_size) goto fail; if(write_padding(fd, pagesize, hdr.ramdisk_size)) goto fail; if(second_data) { if(write(fd, second_data, hdr.second_size) != (ssize_t) hdr.second_size) goto fail; if(write_padding(fd, pagesize, hdr.second_size)) goto fail; } if(dt_data) { if(write(fd, dt_data, hdr.dt_size) != (ssize_t) hdr.dt_size) goto fail; if(write_padding(fd, pagesize, hdr.dt_size)) goto fail; } else { if(recovery_dtbo_data) { if(write(fd, recovery_dtbo_data, hdr.recovery_dtbo_size) != (ssize_t) hdr.recovery_dtbo_size) goto fail; if(write_padding(fd, pagesize, hdr.recovery_dtbo_size)) goto fail; } if(dtb_data) { if(write(fd, dtb_data, hdr.dtb_size) != (ssize_t) hdr.dtb_size) goto fail; if(write_padding(fd, pagesize, hdr.dtb_size)) goto fail; } } if(get_id) { print_id((uint8_t *) hdr.id, sizeof(hdr.id)); } return 0; fail: unlink(bootimg); close(fd); fprintf(stderr,"error: failed writing '%s': %s\n", bootimg, strerror(errno)); return 1; }
void recv_dgram(void *buf, size_t len, uint8_t *id) { printf("recv datagram: from = "); print_id(id); }
static int probe(struct usb_interface *intf, const struct usb_device_id *id) { int r; struct usb_device *udev = interface_to_usbdev(intf); struct net_device *netdev = NULL; print_id(udev); if (id->driver_info & DEVICE_INSTALLER) return eject_installer(intf); switch (udev->speed) { case USB_SPEED_LOW: case USB_SPEED_FULL: case USB_SPEED_HIGH: break; default: dev_dbg_f(&intf->dev, "Unknown USB speed\n"); r = -ENODEV; goto error; } usb_reset_device(interface_to_usbdev(intf)); netdev = zd_netdev_alloc(intf); if (netdev == NULL) { r = -ENOMEM; goto error; } r = upload_firmware(udev, id->driver_info); if (r) { dev_err(&intf->dev, "couldn't load firmware. Error number %d\n", r); goto error; } r = usb_reset_configuration(udev); if (r) { dev_dbg_f(&intf->dev, "couldn't reset configuration. Error number %d\n", r); goto error; } /* At this point the interrupt endpoint is not generally enabled. We * save the USB bandwidth until the network device is opened. But * notify that the initialization of the MAC will require the * interrupts to be temporary enabled. */ r = zd_mac_init_hw(zd_netdev_mac(netdev), id->driver_info); if (r) { dev_dbg_f(&intf->dev, "couldn't initialize mac. Error number %d\n", r); goto error; } r = register_netdev(netdev); if (r) { dev_dbg_f(&intf->dev, "couldn't register netdev. Error number %d\n", r); goto error; } dev_dbg_f(&intf->dev, "successful\n"); dev_info(&intf->dev,"%s\n", netdev->name); return 0; error: usb_reset_device(interface_to_usbdev(intf)); zd_netdev_free(netdev); return r; }
int print_type_info(struct type_info *tinfo, long long offset, char *data) { int btype; int ret; GElf_Sym sym; switch(tinfo->type) { case BASIC_TYPE : if (tinfo->info.btype.sign) { switch (tinfo->info.btype.size) { case 1 : my_printf("0x%x", (char)*data); return 1; case 2 : my_printf("0x%hx", *((short*)data)); return 2; case 4 : my_printf("0x%lx",*((int*)data)); return 4; case 8 : my_printf("0x%llx", *((long*)data)); return 8; } } else { switch (tinfo->info.btype.size) { case 1 : my_printf("0x%x", (unsigned char)*data); return 1; case 2 : my_printf("0x%hx", *((unsigned short*)data)); return 2; case 4 : my_printf("0x%lx",*((unsigned int*)data)); return 4; case 8 : my_printf("0x%llx", *((unsigned long*)data)); return 8; } } break; case FLOAT_TYPE : switch(tinfo->info.ftype.size) { case 4 : my_printf(" float "); return 4; case 8 : my_printf(" double "); return 8; } break; case EQUAL : return print_id(tinfo->id, offset, data); case POINTER : /* print strings for char data type else print %p */ if (sizeof(void*) == 8) my_printf("0x%llx", *((long*)data)); else my_printf("0x%x", *((long*)data)); btype = base_type(tinfo->id); if (btype == CHAR || btype == UCHAR) { if (*(long*)data == 0) return 8; memset(str, 0, MAX_STR_LEN); ret = mdb_readstr(str, MAX_STR_LEN, *((long*)data)); if (ret <= 0) return 8; my_printf(" \"%s\"", str); } if (btype == TYPE_FUNCTION_PTR) { memset(str, 0, MAX_STR_LEN); ret= mdb_lookup_by_addr(*(long*)data, MDB_SYM_EXACT, str, MAX_STR_LEN, &sym); if (ret != -1) my_printf(" \"%s\" ", str); } return 8; case ARRAY : return print_array(tinfo, offset, data); case FORWARD_REF : return print_id(tinfo->id, offset, data); default : my_printf("error"); } }
int main(int argc, char **argv) { boot_img_hdr hdr; char *kernel_fn = NULL; void *kernel_data = NULL; char *ramdisk_fn = NULL; void *ramdisk_data = NULL; char *second_fn = NULL; void *second_data = NULL; char *dt_dir = NULL; uint32_t dt_version = 0; void *dt_data = NULL; char *cmdline = ""; char *bootimg = NULL; char *board = ""; uint32_t pagesize = 2048; int fd; SHA_CTX ctx; uint32_t base = 0x10000000U; uint32_t kernel_offset = 0x00008000U; uint32_t ramdisk_offset = 0x01000000U; uint32_t second_offset = 0x00f00000U; uint32_t tags_offset = 0x00000100U; argc--; argv++; memset(&hdr, 0, sizeof(hdr)); bool get_id = false; while(argc > 0){ char *arg = argv[0]; if (!strcmp(arg, "--id")) { get_id = true; argc -= 1; argv += 1; } else if(argc >= 2) { char *val = argv[1]; argc -= 2; argv += 2; if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) { bootimg = val; } else if(!strcmp(arg, "--kernel")) { kernel_fn = val; } else if(!strcmp(arg, "--ramdisk")) { ramdisk_fn = val; } else if(!strcmp(arg, "--second")) { second_fn = val; } else if (!strcmp(arg, "--dt_dir")) { dt_dir = val; } else if (!strcmp(arg, "--dt_version")) { dt_version = strtoul(val, 0, 10); } else if(!strcmp(arg, "--cmdline")) { cmdline = val; } else if(!strcmp(arg, "--base")) { base = strtoul(val, 0, 16); } else if(!strcmp(arg, "--kernel_offset")) { kernel_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--ramdisk_offset")) { ramdisk_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--second_offset")) { second_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--tags_offset")) { tags_offset = strtoul(val, 0, 16); } else if(!strcmp(arg, "--board")) { board = val; } else if(!strcmp(arg,"--pagesize")) { pagesize = strtoul(val, 0, 10); if ((pagesize != 2048) && (pagesize != 4096) && (pagesize != 8192) && (pagesize != 16384)) { fprintf(stderr,"error: unsupported page size %d\n", pagesize); return -1; } } else { return usage(); } } else { return usage(); } } hdr.page_size = pagesize; hdr.kernel_addr = base + kernel_offset; hdr.ramdisk_addr = base + ramdisk_offset; hdr.second_addr = base + second_offset; hdr.tags_addr = base + tags_offset; if(bootimg == 0) { fprintf(stderr,"error: no output filename specified\n"); return usage(); } if(kernel_fn == 0) { fprintf(stderr,"error: no kernel image specified\n"); return usage(); } if(strlen(board) >= BOOT_NAME_SIZE) { fprintf(stderr,"error: board name too large\n"); return usage(); } strcpy(hdr.name, board); memcpy(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE); if(strlen(cmdline) > (BOOT_ARGS_SIZE - 1)) { fprintf(stderr,"error: kernel commandline too large\n"); return 1; } strcpy((char*)hdr.cmdline, cmdline); kernel_data = load_file(kernel_fn, &hdr.kernel_size); if(kernel_data == 0) { fprintf(stderr,"error: could not load kernel '%s'\n", kernel_fn); return 1; } if(ramdisk_fn == 0) { ramdisk_data = 0; hdr.ramdisk_size = 0; } else { ramdisk_data = load_file(ramdisk_fn, &hdr.ramdisk_size); if(ramdisk_data == 0) { fprintf(stderr,"error: could not load ramdisk '%s'\n", ramdisk_fn); return 1; } } if(second_fn) { second_data = load_file(second_fn, &hdr.second_size); if(second_data == 0) { fprintf(stderr,"error: could not load secondstage '%s'\n", second_fn); return 1; } } if (dt_dir) { dt_data = load_dtqc_block(dt_dir, pagesize, &hdr.dt_size, dt_version); if (dt_data == 0) { fprintf(stderr, "error: could not load device tree blobs '%s'\n", dt_dir); return 1; } } /* put a hash of the contents in the header so boot images can be * differentiated based on their first 2k. */ SHA_init(&ctx); SHA_update(&ctx, kernel_data, hdr.kernel_size); SHA_update(&ctx, &hdr.kernel_size, sizeof(hdr.kernel_size)); SHA_update(&ctx, ramdisk_data, hdr.ramdisk_size); SHA_update(&ctx, &hdr.ramdisk_size, sizeof(hdr.ramdisk_size)); SHA_update(&ctx, second_data, hdr.second_size); SHA_update(&ctx, &hdr.second_size, sizeof(hdr.second_size)); if (dt_data) { SHA_update(&ctx, dt_data, hdr.dt_size); SHA_update(&ctx, &hdr.dt_size, sizeof(hdr.dt_size)); } _SHA_final((uint8_t *)hdr.id, &ctx); fd = open(bootimg, O_CREAT | O_TRUNC | O_WRONLY, 0644); if(fd < 0) { fprintf(stderr,"error: could not create '%s'\n", bootimg); return 1; } if(write(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) goto fail; if(write_padding(fd, pagesize, sizeof(hdr))) goto fail; if(write(fd, kernel_data, hdr.kernel_size) != hdr.kernel_size) goto fail; if(write_padding(fd, pagesize, hdr.kernel_size)) goto fail; if(write(fd, ramdisk_data, hdr.ramdisk_size) != hdr.ramdisk_size) goto fail; if(write_padding(fd, pagesize, hdr.ramdisk_size)) goto fail; if(second_data) { if(write(fd, second_data, hdr.second_size) != hdr.second_size) goto fail; if(write_padding(fd, pagesize, hdr.ramdisk_size)) goto fail; } if (dt_data) { if (write(fd, dt_data, hdr.dt_size) != hdr.dt_size) goto fail; if (write_padding(fd, pagesize, hdr.dt_size)) goto fail; } if (get_id) { print_id((uint8_t *) hdr.id, sizeof(hdr.id)); } return 0; fail: unlink(bootimg); close(fd); fprintf(stderr,"error: failed writing '%s': %s\n", bootimg, strerror(errno)); return 1; }
int main(void) { uint32_t i; uint32_t id; bitmap_info_t binfo; uint32_t buffer[100000] = {0}; bitmap_info_init(&binfo, 100); bitmap_t *bitmap = NULL; bitmap = (bitmap_t *)malloc(bitmap_size(&binfo)); bitmap_init(bitmap, &binfo); for (i = 1; i < binfo.nlevels; i++) { printf("group_offset%d:%6d %6d\n", i, \ binfo.levels[i].group_offset - \ binfo.levels[i-1].group_offset, \ binfo.levels[i].group_offset); } /* register */ printf("register: "); for(i = 0; i < 65; i++) { id = bitmap_sfu(bitmap, &binfo); buffer[i] = id; print_id(i, id); } #if pbitmap /* show bitmap */ printf("\n"); for(i = 0; i < 65; i++) { printf("%16llx ", bitmap[i]); if (!((i+1)%4)) printf("\n"); } #endif /* aged */ printf("\naged: "); for(i = 30; i < 65; ++i) { bitmap_unset(bitmap, &binfo, buffer[i]); print_id(i, buffer[i]); } #if pbitmap /* show bitmap */ printf("\n"); for(i = 0; i < 50; i++) { printf("%16llx ", bitmap[i]); if (!((i+1)%4)) printf("\n"); } #endif /* register again*/ printf("\nsecond register: "); for(i = 0; i < 50; i++) { id = bitmap_sfu(bitmap, &binfo); buffer[i+30] = id; print_id(i, id); } /* aged again */ printf("\naged: "); for(i = 0; i < 80; i++) { bitmap_unset(bitmap, &binfo, buffer[i]); print_id(i, buffer[i]); } printf("\n"); free(bitmap); return 0; }
static void display_group(int id) { int i, offset; int print_grp = 0; offset = ntohl(prh.idHash[IDHash(id)]); while (offset) { lseek(dbase_fd, offset + HDRSIZE, L_SET); if (read(dbase_fd, &pre, sizeof(struct prentry)) < 0) { fprintf(stderr, "pt_util: read i/o error: %s\n", strerror(errno)); exit(1); } fix_pre(&pre); if (pre.id == id) break; offset = pre.nextID; } if (print_id(id)) { fprintf(dfp, FMT_BASE, pre.name, pre.flags, pre.ngroups, pre.id, pre.owner, pre.creator); print_grp = 1; } if ((flags & DO_MEM) == 0) return; for (i = 0; i < PRSIZE; i++) { if ((id = pre.entries[i]) == 0) break; if (id == PRBADID) continue; if (print_id(id) || print_grp == 1) { if (print_grp == 0) { fprintf(dfp, FMT_BASE, pre.name, pre.flags, pre.ngroups, pre.id, pre.owner, pre.creator); print_grp = 2; } fprintf(dfp, FMT_MEM, id_to_name(id), id); } } if (i == PRSIZE) { offset = pre.next; while (offset) { lseek(dbase_fd, offset + HDRSIZE, L_SET); if (read(dbase_fd, &prco, sizeof(struct contentry)) < 0) { fprintf(stderr, "pt_util: read i/o error: %s\n", strerror(errno)); exit(1); } prco.next = ntohl(prco.next); for (i = 0; i < COSIZE; i++) { prco.entries[i] = ntohl(prco.entries[i]); if ((id = prco.entries[i]) == 0) break; if (id == PRBADID) continue; if (print_id(id) || print_grp == 1) { if (print_grp == 0) { fprintf(dfp, FMT_BASE, pre.name, pre.flags, pre.ngroups, pre.id, pre.owner, pre.creator); print_grp = 2; } fprintf(dfp, FMT_MEM, id_to_name(id), id); } } if ((i == COSIZE) && prco.next) offset = prco.next; else offset = 0; } } }
/* The Wacky Quoting Proposal (WQP), as implemented: For any line of text, the Quote is m|^([ \t>]*|\|[^>]>)*|. The Quote is repeated at the beginning of all wrap lines. If the Quote is longer than the screen, then it is no longer considered the Quote. */ void default_gsubrc(void) { char *buf, *quotebuf; struct gale_text timecode,text,loc_value; struct gale_text presence = gale_var(G_("GALE_TEXT_NOTICE_PRESENCE")); struct gale_text answer = gale_var(G_("GALE_TEXT_ANSWER_RECEIPT")); struct gale_text from_name = gale_var(G_("GALE_TEXT_MESSAGE_SENDER")); int i,len,buflen,bufloaded = 0,termwid = gale_columns(stdout); int do_verbose = 0; if (termwid < 2) termwid = 80; /* Don't crash */ /* Get the verbosity setting */ if (0 != (text = gale_var(G_("GALE_VERBOSE"))).l) { do_verbose = gale_text_to_number(text); } /* Check for _gale.query messages */ i = 1; loc_value = gale_var(G_("GALE_TO")); while (0 != loc_value.l) { /* "_gale.query." is 12 characters long */ if (0 == gale_text_compare( gale_text_left(loc_value, 12), G_("_gale.query."))) { if (do_verbose) gale_alert(GALE_NOTICE, gale_text_concat(3, G_("not printing message to \""), loc_value,G_("\"")),0); return; } loc_value = gale_var(gale_text_concat(3, G_("GALE_TO"),G_("_"), gale_text_from_number(++i,10,0))); } /* Get the time */ if (0 == (timecode = gale_var(G_("GALE_TIME_ID_TIME"))).l) timecode = gale_time_format(gale_time_now()); if (0 != gale_var(G_("GALE_DATA_SECURITY_ENCRYPTION")).l) { gale_alert(GALE_WARNING,gale_text_concat(3, G_("cannot decrypt message to \""), gale_var(G_("GALE_TO")), G_("\"")),0); return; } /* Format return receipts and presence notices specially */ if (0 != answer.l || 0 != presence.l) { gale_print(stdout, gale_print_bold | gale_print_clobber_left,G_("* ")); gale_print(stdout,0,timecode); if (answer.l) gale_print(stdout,0,G_(" received:")); if (presence.l) { gale_print(stdout,0,G_(" ")); gale_print(stdout,0,presence); } print_id(G_("GALE_FROM"),G_("unverified")); if (from_name.l) { gale_print(stdout,0,G_(" (")); gale_print(stdout,0,from_name); gale_print(stdout,0,G_(")")); } gale_print(stdout,gale_print_clobber_right,G_("")); gale_print(stdout,0,G_("\n")); fflush(stdout); return; } gale_print(stdout,gale_print_clobber_left,G_("-")); for (len = 0; len < termwid - 3; ++len) gale_print(stdout,0,G_("-")); gale_print(stdout,gale_print_clobber_right,G_("-")); gale_print(stdout,0,G_("\n")); /* Print the header */ gale_print(stdout,0,G_("To:")); print_id(G_("GALE_TO"),G_("unknown")); text = gale_var(G_("GALE_TEXT_MESSAGE_RECIPIENT")); if (text.l) { gale_print(stdout,0,G_(" (")); gale_print(stdout,0,text); gale_print(stdout,0,G_(")")); } i = 1; text = gale_var(G_("GALE_TEXT_MESSAGE_KEYWORD")); while (text.l) { gale_print(stdout,0,G_(" /")); if (quote_string(&text)) { gale_print(stdout,0,G_("'")); gale_print(stdout,gale_print_bold,text); gale_print(stdout,0,G_("'")); } else gale_print(stdout,gale_print_bold,text); text = gale_var(gale_text_concat(2, G_("GALE_TEXT_MESSAGE_KEYWORD_"), gale_text_from_number(++i,10,0))); } text = gale_var(G_("GALE_TEXT_MESSAGE_SUBJECT")); if (text.l) { gale_print(stdout,0,G_(" re \"")); gale_print(stdout,gale_print_bold,text); gale_print(stdout,0,G_("\"")); } if (gale_var(G_("GALE_TEXT_QUESTION_RECEIPT")).l) gale_print(stdout,gale_print_clobber_right,G_(" [rcpt]")); gale_print(stdout,gale_print_clobber_right,G_("\n")); /* Print the message body. */ buflen = termwid; /* can't be longer than this */ buf = gale_malloc(buflen); quotebuf = gale_malloc(buflen); while (1) { int quotelen = 0, quotecol = 0; char curchar; /* Read more data in order to process a line of input: */ if (!feof(stdin)) bufloaded += fread(buf + bufloaded, 1, buflen - bufloaded, stdin); if (!bufloaded && feof(stdin)) goto done_proper; /* Find the Quote. */ while (1) { if (quotelen == bufloaded || quotecol >= termwid) { /* This Quote is too long - give up and format as regular text. */ quotelen = quotecol = 0; goto end_quote; } curchar = buf[quotelen]; if (('\n' != curchar && isspace(curchar)) || '>' == curchar) { quotecol = gale_column(quotecol, curchar); ++quotelen; } else if ('|' == curchar) { ++quotecol; ++quotelen; for (; quotelen < bufloaded && '\n' != buf[quotelen] && '>' != buf[quotelen]; ++quotelen) quotecol = gale_column(quotecol, buf[quotelen]); } else goto end_quote; } end_quote: /* Process rest of the line. */ while (1) { /* Produce a line of output. */ int pos = quotelen; /* current position */ int col = quotecol; /* current screen column */ int prevend = pos; /* end of previous word */ int curstart = pos; /* start of current word */ /* Advance past end of first word. */ for (; pos < bufloaded && !isspace(buf[pos]); ++pos) { col = gale_column(col, buf[pos]); if (col >= termwid) { /* Extra long word! Output it verbatim. */ gale_print(stdout, gale_print_clobber_right, gale_text_from(gale_global->enc_console, buf, quotelen)); do { for (; pos < bufloaded && !isspace(buf[pos]); ++pos) col = gale_column(col, buf[pos]); gale_print(stdout, 0, gale_text_from(gale_global->enc_console, buf + quotelen, pos - quotelen)); /* Read more, if necessary. */ if (pos == bufloaded) { pos = bufloaded = quotelen; if (!feof(stdin)) bufloaded += fread(buf + bufloaded, 1, buflen - bufloaded, stdin); if (pos == bufloaded && feof(stdin)) goto done_premie; } } while (!isspace(buf[pos])); /* Skip whitespace. */ for (; '\n' != buf[pos] && isspace(buf[pos]);) if (++pos == bufloaded) { pos = bufloaded = quotelen; if (!feof(stdin)) bufloaded += fread(buf + bufloaded, 1, buflen - bufloaded, stdin); if (pos == bufloaded && feof(stdin)) goto done_premie; } gale_print(stdout,0,G_("\n")); if ('\n' == buf[pos]) { ++pos; memmove(buf, buf + pos, bufloaded - pos); bufloaded -= pos; goto end_line; } else { memmove(buf + quotelen, buf + pos, bufloaded - pos); bufloaded -= pos - quotelen; goto end_out_line; } } } /* Process remaining words.*/ while (1) { prevend = pos; /* Have we reached premature EOF? */ if (pos == bufloaded) { gale_print(stdout, 0, gale_text_from(gale_global->enc_console, buf, prevend)); goto done_premie; } /* Advance past whitespace. */ for (; pos < bufloaded && isspace(buf[pos]); ++pos) { col = gale_column(col, buf[pos]); if ('\n' == buf[pos] || col >= termwid) { /* Wrap line! */ gale_print(stdout, 0, gale_text_from(gale_global->enc_console, buf, prevend)); gale_print(stdout,0,G_("\n")); /* Skip any more whitespace. */ for (; '\n' != buf[pos] && isspace(buf[pos]);) if (++pos == bufloaded) { pos = bufloaded = quotelen; if (!feof(stdin)) bufloaded += fread(buf + bufloaded,1,buflen - bufloaded,stdin); if (pos == bufloaded && feof(stdin)) goto done_premie; } if ('\n' == buf[pos]) { ++pos; memmove(buf, buf + pos, bufloaded - pos); bufloaded -= pos; goto end_line; } else { memmove(buf + quotelen, buf + pos, bufloaded - pos); bufloaded -= pos - quotelen; goto end_out_line; } } } /* Have we reached premature EOF? */ if (pos == bufloaded) { gale_print(stdout, 0, gale_text_from(gale_global->enc_console, buf, prevend)); goto done_premie; } /* Process next word. */ curstart = pos; while (pos < bufloaded && !isspace(buf[pos])) { col = gale_column(col, buf[pos++]); if (col >= termwid) { /* Wrap line! */ gale_print(stdout, 0, gale_text_from(gale_global->enc_console, buf, prevend)); gale_print(stdout,0,G_("\n")); memmove(buf + quotelen, buf + curstart, bufloaded - curstart); bufloaded -= curstart - quotelen; goto end_out_line; } } } end_out_line: if (!feof(stdin)) bufloaded += fread(buf + bufloaded, 1, buflen - bufloaded, stdin); if (!bufloaded && feof(stdin)) goto done_proper; } end_line: ; } gale_print(stdout, gale_print_clobber_right, gale_text_from(gale_global->enc_console, buf, buflen)); done_premie: /* We must have got here via premature EOF, so add a newline. */ gale_print(stdout,0,G_("\n")); done_proper: /* Print the signature information. */ { struct gale_text from_name = gale_var(G_("GALE_TEXT_MESSAGE_SENDER")); int len = gale_text_width(timecode); if (0 == from_name.l) len += id_width(G_("GALE_FROM"),G_("anonymous")); else len += id_width(G_("GALE_FROM"),G_("unverified")) + from_name.l + 3; while (len++ < termwid - 7) gale_print(stdout,0,G_(" ")); gale_print(stdout,0,G_("--")); if (0 == from_name.l) print_id(G_("GALE_FROM"),G_("anonymous")); else { print_id(G_("GALE_FROM"),G_("unverified")); gale_print(stdout,0,G_(" (")); gale_print(stdout,0,from_name); gale_print(stdout,0,G_(")")); } gale_print(stdout,0,G_(" ")); gale_print(stdout,gale_print_clobber_right,timecode); gale_print(stdout,0,G_(" --")); gale_print(stdout,gale_print_clobber_right,G_("\n")); } fflush(stdout); }