| 402 | } |
| 403 | |
| 404 | BlockDevice *block_device_init_http(const char *url, |
| 405 | int max_cache_size_kb, |
| 406 | void (*start_cb)(void *opaque), |
| 407 | void *start_opaque) |
| 408 | { |
| 409 | BlockDevice *bs; |
| 410 | BlockDeviceHTTP *bf; |
| 411 | char *p; |
| 412 | |
| 413 | bs = mallocz(sizeof(*bs)); |
| 414 | bf = mallocz(sizeof(*bf)); |
| 415 | strcpy(bf->url, url); |
| 416 | /* get the path with the trailing '/' */ |
| 417 | p = strrchr(bf->url, '/'); |
| 418 | if (!p) |
| 419 | p = bf->url; |
| 420 | else |
| 421 | p++; |
| 422 | *p = '\0'; |
| 423 | |
| 424 | init_list_head(&bf->cached_blocks); |
| 425 | bf->max_cache_size_kb = max_cache_size_kb; |
| 426 | bf->start_cb = start_cb; |
| 427 | bf->start_opaque = start_opaque; |
| 428 | bf->bs = bs; |
| 429 | |
| 430 | bs->opaque = bf; |
| 431 | bs->get_sector_count = bf_get_sector_count; |
| 432 | bs->read_async = bf_read_async; |
| 433 | bs->write_async = bf_write_async; |
| 434 | |
| 435 | fs_wget(url, NULL, NULL, bs, bf_init_onload, TRUE); |
| 436 | return bs; |
| 437 | } |
| 438 | |
| 439 | static void bf_init_onload(void *opaque, int err, void *data, size_t size) |
| 440 | { |
no test coverage detected