Exemplo n.º 1
0
/* 
 * Requests larger than 1/2 the cache size will be bypassed and go
 * directly to the disk.  XXX tune this.
 */
int
bcache_strategy(void *devdata, int unit, int rw, daddr_t blk, size_t size,
		char *buf, size_t *rsize)
{
    static int			bcache_unit = -1;
    struct bcache_devdata	*dd = (struct bcache_devdata *)devdata;

    bcache_ops++;

    if(bcache_unit != unit) {
	bcache_flush();
	bcache_unit = unit;
    }

    /* bypass large requests, or when the cache is inactive */
    if ((bcache_data == NULL) || ((size * 2 / bcache_blksize) > bcache_nblks)) {
	DEBUG("bypass %d from %d", size / bcache_blksize, blk);
	bcache_bypasses++;
	return(dd->dv_strategy(dd->dv_devdata, rw, blk, size, buf, rsize));
    }

    switch (rw) {
    case F_READ:
	return read_strategy(devdata, unit, rw, blk, size, buf, rsize);
    case F_WRITE:
	return write_strategy(devdata, unit, rw, blk, size, buf, rsize);
    }
    return -1;
}
Exemplo n.º 2
0
image_t *charger_image_pgm(const char *nom_fichier) {
  FILE *file = fopen(nom_fichier, "r");
  image_t *img = NULL;

  if (file) {
    char buffer[TMP_STR_SIZE];

    fgets(buffer, TMP_STR_SIZE, file);
    read_funct_t fun_read = read_strategy(buffer);
    if (fun_read) {
      img = creer_image_path(nom_fichier);
      while (fgets(buffer, TMP_STR_SIZE, file) &&
          (sscanf(buffer, "%zu %zu", &img->w, &img->h) == 0)) {}
      while (fgets(buffer, TMP_STR_SIZE, file) &&
          (sscanf(buffer, "%hhu", &img->maxval) == 0)) {}
      img->buff = fun_read(file, img);
    } else {
      perror("charge_image_pgm: Error invalid pgm file.");
    }
    fclose(file);
  } else {
    perror("charge_image_pgm: Error invalid filename or file.");
  }
  return img;
}
Exemplo n.º 3
0
ssize_t res_counter_read(struct res_counter *counter, int member,
		const char __user *userbuf, size_t nbytes, loff_t *pos,
		int (*read_strategy)(unsigned long long val, char *st_buf))
{
	unsigned long long *val;
	char buf[64], *s;

	s = buf;
	val = res_counter_member(counter, member);
	if (read_strategy)
		s += read_strategy(*val, s);
	else
		s += sprintf(s, "%llu\n", *val);
	return simple_read_from_buffer((void __user *)userbuf, nbytes,
			pos, buf, s - buf);
}