Revision 5fafdf24 qemu-img.c

b/qemu-img.c
1 1
/*
2 2
 * QEMU disk image utility
3
 * 
3
 *
4 4
 * Copyright (c) 2003-2007 Fabrice Bellard
5
 * 
5
 *
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
8 8
 * in the Software without restriction, including without limitation the rights
......
75 75
    term_printf(filename);
76 76
}
77 77

  
78
void __attribute__((noreturn)) error(const char *fmt, ...) 
78
void __attribute__((noreturn)) error(const char *fmt, ...)
79 79
{
80 80
    va_list ap;
81 81
    va_start(ap, fmt);
......
166 166
    tty.c_cflag |= CS8;
167 167
    tty.c_cc[VMIN] = 1;
168 168
    tty.c_cc[VTIME] = 0;
169
    
169
   
170 170
    tcsetattr (0, TCSANOW, &tty);
171 171

  
172 172
    atexit(term_exit);
......
248 248
    int64_t size;
249 249
    const char *p;
250 250
    BlockDriver *drv;
251
    
251
   
252 252
    encrypted = 0;
253 253
    for(;;) {
254 254
        c = getopt(argc, argv, "b:f:he");
......
269 269
            break;
270 270
        }
271 271
    }
272
    if (optind >= argc) 
272
    if (optind >= argc)
273 273
        help();
274 274
    filename = argv[optind++];
275 275
    size = 0;
......
338 338
            break;
339 339
        }
340 340
    }
341
    if (optind >= argc) 
341
    if (optind >= argc)
342 342
        help();
343 343
    filename = argv[optind++];
344 344

  
......
446 446
            break;
447 447
        }
448 448
    }
449
    if (optind >= argc) 
449
    if (optind >= argc)
450 450
        help();
451 451
    filename = argv[optind++];
452
    if (optind >= argc) 
452
    if (optind >= argc)
453 453
        help();
454 454
    out_filename = argv[optind++];
455
    
455
   
456 456
    bs = bdrv_new_open(filename, fmt);
457 457

  
458 458
    drv = bdrv_find_format(out_fmt);
......
473 473
            error("Error while formatting '%s'", out_filename);
474 474
        }
475 475
    }
476
    
476
   
477 477
    out_bs = bdrv_new_open(out_filename, out_fmt);
478 478

  
479 479
    if (compress) {
......
492 492
                n = cluster_sectors;
493 493
            else
494 494
                n = nb_sectors;
495
            if (bdrv_read(bs, sector_num, buf, n) < 0) 
495
            if (bdrv_read(bs, sector_num, buf, n) < 0)
496 496
                error("error while reading");
497 497
            if (n < cluster_sectors)
498 498
                memset(buf + n * 512, 0, cluster_size - n * 512);
499 499
            if (is_not_zero(buf, cluster_size)) {
500
                if (bdrv_write_compressed(out_bs, sector_num, buf, 
500
                if (bdrv_write_compressed(out_bs, sector_num, buf,
501 501
                                          cluster_sectors) != 0)
502 502
                    error("error while compressing sector %" PRId64,
503 503
                          sector_num);
......
516 516
                n = (IO_BUF_SIZE / 512);
517 517
            else
518 518
                n = nb_sectors;
519
            if (bdrv_read(bs, sector_num, buf, n) < 0) 
519
            if (bdrv_read(bs, sector_num, buf, n) < 0)
520 520
                error("error while reading");
521 521
            /* NOTE: at the same time we convert, we do not write zero
522 522
               sectors to have a chance to compress the image. Ideally, we
......
524 524
            buf1 = buf;
525 525
            while (n > 0) {
526 526
                if (is_allocated_sectors(buf1, n, &n1)) {
527
                    if (bdrv_write(out_bs, sector_num, buf1, n1) < 0) 
527
                    if (bdrv_write(out_bs, sector_num, buf1, n1) < 0)
528 528
                        error("error while writing");
529 529
                }
530 530
                sector_num += n1;
......
554 554
	    return (((int64_t) high) << 32) + low;
555 555
    }
556 556

  
557
    if (_stati64(filename, &st) < 0) 
557
    if (_stati64(filename, &st) < 0)
558 558
        return -1;
559 559
    return st.st_size;
560 560
}
......
562 562
static int64_t get_allocated_file_size(const char *filename)
563 563
{
564 564
    struct stat st;
565
    if (stat(filename, &st) < 0) 
565
    if (stat(filename, &st) < 0)
566 566
        return -1;
567 567
    return (int64_t)st.st_blocks * 512;
568 568
}
......
612 612
            break;
613 613
        }
614 614
    }
615
    if (optind >= argc) 
615
    if (optind >= argc)
616 616
        help();
617 617
    filename = argv[optind++];
618 618

  
......
636 636
    if (allocated_size < 0)
637 637
	sprintf(dsize_buf, "unavailable");
638 638
    else
639
        get_human_readable_size(dsize_buf, sizeof(dsize_buf), 
639
        get_human_readable_size(dsize_buf, sizeof(dsize_buf),
640 640
                                allocated_size);
641 641
    printf("image: %s\n"
642 642
           "file format: %s\n"
643 643
           "virtual size: %s (%" PRId64 " bytes)\n"
644 644
           "disk size: %s\n",
645
           filename, fmt_name, size_buf, 
645
           filename, fmt_name, size_buf,
646 646
           (total_sectors * 512),
647 647
           dsize_buf);
648 648
    if (bdrv_is_encrypted(bs))
649 649
        printf("encrypted: yes\n");
650 650
    if (bdrv_get_info(bs, &bdi) >= 0) {
651
        if (bdi.cluster_size != 0) 
651
        if (bdi.cluster_size != 0)
652 652
            printf("cluster_size: %d\n", bdi.cluster_size);
653 653
    }
654 654
    bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_filename));
655 655
    if (backing_filename[0] != '\0') {
656 656
        path_combine(backing_filename2, sizeof(backing_filename2),
657 657
                     filename, backing_filename);
658
        printf("backing file: %s (actual path: %s)\n", 
658
        printf("backing file: %s (actual path: %s)\n",
659 659
               backing_filename,
660 660
               backing_filename2);
661 661
    }

Also available in: Unified diff