MCPcopy Create free account
hub / github.com/ading2210/linuxpdf / bf_init_onload

Function bf_init_onload

tinyemu/block_net.c:439–531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

437}
438
439static void bf_init_onload(void *opaque, int err, void *data, size_t size)
440{
441 BlockDevice *bs = opaque;
442 BlockDeviceHTTP *bf = bs->opaque;
443 int block_size_kb, block_num;
444 JSONValue cfg, array;
445
446 if (err < 0) {
447 fprintf(stderr, "Could not load block device file (err=%d)\n", -err);
448 exit(1);
449 }
450
451 /* parse the disk image info */
452 cfg = json_parse_value_len(data, size);
453 if (json_is_error(cfg)) {
454 vm_error("error: %s\n", json_get_error(cfg));
455 config_error:
456 json_free(cfg);
457 exit(1);
458 }
459
460 if (vm_get_int(cfg, "block_size", &block_size_kb) < 0)
461 goto config_error;
462 bf->block_size = block_size_kb * 2;
463 if (bf->block_size <= 0 ||
464 (bf->block_size & (bf->block_size - 1)) != 0) {
465 vm_error("invalid block_size\n");
466 goto config_error;
467 }
468 if (vm_get_int(cfg, "n_block", &bf->nb_blocks) < 0)
469 goto config_error;
470 if (bf->nb_blocks <= 0) {
471 vm_error("invalid n_block\n");
472 goto config_error;
473 }
474
475 bf->nb_sectors = bf->block_size * (uint64_t)bf->nb_blocks;
476 bf->n_cached_blocks = 0;
477 bf->n_cached_blocks_max = max_int(1, bf->max_cache_size_kb / block_size_kb);
478 bf->cur_block_num = -1; /* no request in progress */
479
480 bf->sectors_per_cluster = 8; /* 4 KB */
481 bf->n_clusters = (bf->nb_sectors + bf->sectors_per_cluster - 1) / bf->sectors_per_cluster;
482 bf->clusters = mallocz(sizeof(bf->clusters[0]) * bf->n_clusters);
483
484 if (vm_get_int_opt(cfg, "prefetch_group_len",
485 &bf->prefetch_group_len, 1) < 0)
486 goto config_error;
487 if (bf->prefetch_group_len > PREFETCH_GROUP_LEN_MAX) {
488 vm_error("prefetch_group_len is too large");
489 goto config_error;
490 }
491
492 array = json_object_get(cfg, "prefetch");
493 if (!json_is_undefined(array)) {
494 int idx, prefetch_len, l, i;
495 JSONValue el;
496 int tab_block_num[PREFETCH_GROUP_LEN_MAX];

Callers

nothing calls this directly

Calls 15

json_parse_value_lenFunction · 0.85
json_is_errorFunction · 0.85
vm_errorFunction · 0.85
json_get_errorFunction · 0.85
json_freeFunction · 0.85
vm_get_intFunction · 0.85
max_intFunction · 0.85
malloczFunction · 0.85
vm_get_int_optFunction · 0.85
json_object_getFunction · 0.85
json_is_undefinedFunction · 0.85
min_intFunction · 0.85

Tested by

no test coverage detected