int buffer_flush (buffer_ref b) { register unsigned int n = allreadwrite(b->op, b->fd, b->x + b->p, b->n - b->p) ; b->p += n ; buffer_clean(b) ; return buffer_len(b) ? -1 : (int)n ; }
static void sync_buffers(kdev_t dev, int wait) { register struct buffer_head *bh; for (bh = bh_chain; bh != NULL; bh = bh->b_next) { if (dev && bh->b_dev != dev) continue; /* * Skip clean buffers. */ if (buffer_clean(bh)) continue; /* * Locked buffers.. * * Buffer is locked; skip it unless wait is requested * AND pass > 0. */ if (buffer_locked(bh) && wait) continue; else wait_on_buffer(bh); /* * Do the stuff */ bh->b_count++; ll_rw_blk(WRITE, bh); bh->b_count--; } return; }
void show_buffer(struct buffer_head *buffer) { printf("%Lx/%i%s ", buffer->index, buffer->count, buffer_dirty(buffer) ? "*" : buffer_clean(buffer) ? "" : buffer->state == BUFFER_EMPTY ? "-" : "?"); }
int buffer_put (register buffer_ref b, char const *buf, unsigned int len) { if (len > (b->a - b->n)) { buffer_clean(b) ; if ((len > (b->a - b->n)) && (buffer_flush(b) == -1)) return -1 ; } return buffer_putalign(b, buf, len) ; }
int buffer_fill (buffer_ref b) { register int r ; buffer_clean(b) ; if (b->n == b->a) return (errno = ENOBUFS, -1) ; r = (*b->op)(b->fd, b->x + b->n, b->a - b->n) ; if (r > 0) b->n += r ; return r ; }
unsigned int buffer_putnoflush (buffer_ref b, char const *buf, unsigned int len) { if (len > buffer_available(b)) { buffer_clean(b) ; if (len > buffer_available(b)) len = buffer_available(b) ; } byte_copy(buffer_WPEEK(b), len, buf) ; buffer_WSEEK(b, len) ; return len ; }
struct buffer_head *getblk(kdev_t dev, block_t block) { register struct buffer_head *bh; /* If there are too many dirty buffers, we wake up the update process * now so as to ensure that there are still clean buffers available * for user processes to use (and dirty) */ do { bh = get_hash_table(dev, block); if (bh != NULL) { if (buffer_clean(bh) && buffer_uptodate(bh)) put_last_lru(bh); return bh; } /* I think the following check is redundant * So I will remove it for now */ } while(find_buffer(dev, block)); /* * Create a buffer for this job. */ bh = get_free_buffer(); /* OK, FINALLY we know that this buffer is the only one of its kind, * and that it's unused (b_count=0), unlocked (buffer_locked=0), and clean */ bh->b_count = 1; bh->b_dirty = 0; bh->b_lock = 0; bh->b_uptodate = 0; bh->b_dev = dev; bh->b_blocknr = block; bh->b_seg = kernel_ds; return bh; }
/** * @short Opens a script file, and executes it. */ void prerecorded(const char *oscript, int do_r){ INIT_LOCAL(); FILE *fd=fopen(oscript, "r"); if (!fd){ FAIL("Could not open script file"); END_LOCAL(); return; } const char *script=basename((char*)oscript); buffer *buffer=buffer_new(1024*1024); onion_request *req=onion_request_new(server, buffer, "test"); ssize_t r; const size_t LINE_SIZE=1024; char *line=malloc(LINE_SIZE); size_t len=LINE_SIZE; onion_connection_status ret; int ntest=0; int linen=0; while (!feof(fd)){ ntest++; ret=OCS_NEED_MORE_DATA; ONION_DEBUG("Test %d",ntest); // Read request while ( (r=getline(&line, &len, fd)) != -1 ){ linen++; if (strcmp(line,"-- --\n")==0){ break; } if (do_r){ line[r-1]='\r'; line[r]='\n'; r++; } if (ret==OCS_NEED_MORE_DATA) ret=onion_request_write(req, line, r); //line[r]='\0'; //ONION_DEBUG0("Write: %s\\n (%d). Ret %d",line,r,ret); len=LINE_SIZE; } if (r<0){ buffer_free(buffer); fclose(fd); onion_request_free(req); free(line); END_LOCAL(); return; } if (r==0){ FAIL_IF("Found end of file before end of request"); buffer_free(buffer); fclose(fd); onion_request_free(req); free(line); END_LOCAL(); return; } // Check response buffer->data[buffer->pos]='\0'; if (buffer->pos==0){ ONION_DEBUG("Empty response"); } else{ ONION_DEBUG0("Response: %s",buffer->data); } while ( (r=getline(&line, &len, fd)) != -1 ){ linen++; if (strcmp(line,"++ ++\n")==0){ break; } line[strlen(line)-1]='\0'; if (strcmp(line,"INTERNAL_ERROR")==0){ // Checks its an internal error ONION_DEBUG("%s:%d Check INTERNAL_ERROR",script,linen); ONION_DEBUG0("Returned %d",ret); FAIL_IF_NOT_EQUAL(ret, OCS_INTERNAL_ERROR); } else if (strcmp(line,"NOT_IMPLEMENTED")==0){ // Checks its an internal error ONION_DEBUG("Check NOT_IMPLEMENTED"); ONION_DEBUG0("Returned %d",ret); FAIL_IF_NOT_EQUAL(ret, OCS_NOT_IMPLEMENTED); } else{ regex_t re; regmatch_t match[1]; int l=strlen(line)-1; int _not=line[0]=='!'; if (_not){ ONION_DEBUG("Oposite regexp"); memmove(line, line+1, l); l--; } memmove(line+1,line,l+1); line[0]='^'; line[l+2]='$'; line[l+3]='\0'; ONION_DEBUG("%s:%d Check regexp: '%s'",script, linen, line); int r; r=regcomp(&re, line, REG_EXTENDED); if ( r !=0 ){ char error[1024]; regerror(r, &re, error, sizeof(error)); ONION_ERROR("%s:%d Error compiling regular expression %s: %s",script, linen, line, error); FAIL(line); } else{ int _match=regexec_multiline(&re, buffer->data, 1, match, 0); if ( (_not && _match==0) || (!_not && _match!=0) ){ ONION_ERROR("%s:%d cant find %s",script, linen, line); FAIL(line); } else{ ONION_DEBUG0("Found at %d-%d",match[0].rm_so, match[0].rm_eo); FAIL_IF(0); // To mark a passed test } } regfree(&re); } len=1024; } buffer_clean(buffer); onion_request_clean(req); } free(line); onion_request_free(req); buffer_free(buffer); fclose(fd); END_LOCAL(); }