Beispiel #1
0
static int img_check(int argc, char **argv)
{
    int c, ret;
    const char *filename, *fmt;
    BlockDriver *drv;
    BlockDriverState *bs;

    fmt = NULL;
    for(;;) {
        c = getopt(argc, argv, "f:h");
        if (c == -1)
            break;
        switch(c) {
        case 'h':
            help();
            break;
        case 'f':
            fmt = optarg;
            break;
        }
    }
    if (optind >= argc)
        help();
    filename = argv[optind++];

    bs = bdrv_new("");
    if (!bs)
        error("Not enough memory");
    if (fmt) {
        drv = bdrv_find_format(fmt);
        if (!drv)
            error("Unknown file format '%s'", fmt);
    } else {
        drv = NULL;
    }
    if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) {
        error("Could not open '%s'", filename);
    }
    ret = bdrv_check(bs);
    switch(ret) {
    case 0:
        printf("No errors were found on the image.\n");
        break;
    case -ENOTSUP:
        error("This image format does not support checks");
        break;
    default:
        if (ret < 0) {
            error("An error occurred during the check");
        } else {
            printf("%d errors were found on the image.\n", ret);
        }
        break;
    }

    bdrv_delete(bs);
    return 0;
}
Beispiel #2
0
static void test_sync_op_check(BdrvChild *c)
{
    BdrvCheckResult result;
    int ret;

    /* Error: Driver does not implement check */
    ret = bdrv_check(c->bs, &result, 0);
    g_assert_cmpint(ret, ==, -ENOTSUP);
}
Beispiel #3
0
static int img_check(int argc, char **argv)
{
    int c, ret;
    const char *filename, *fmt;
    BlockDriverState *bs;

    fmt = NULL;
    for(;;) {
        c = getopt(argc, argv, "f:h");
        if (c == -1)
            break;
        switch(c) {
        case 'h':
            help();
            break;
        case 'f':
            fmt = optarg;
            break;
        }
    }
    if (optind >= argc)
        help();
    filename = argv[optind++];

    bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS);
    ret = bdrv_check(bs);
    switch(ret) {
    case 0:
        printf("No errors were found on the image.\n");
        break;
    case -ENOTSUP:
        error("This image format does not support checks");
        break;
    default:
        if (ret < 0) {
            error("An error occurred during the check");
        } else {
            printf("%d errors were found on the image.\n", ret);
        }
        break;
    }

    bdrv_delete(bs);
    return 0;
}
Beispiel #4
0
/*
 * Checks an image for consistency. Exit codes:
 *
 * 0 - Check completed, image is good
 * 1 - Check not completed because of internal errors
 * 2 - Check completed, image is corrupted
 * 3 - Check completed, image has leaked clusters, but is good otherwise
 */
static int img_check(int argc, char **argv)
{
    int c, ret;
    const char *filename, *fmt;
    BlockDriverState *bs;
    BdrvCheckResult result;

    fmt = NULL;
    for(;;) {
        c = getopt(argc, argv, "f:h");
        if (c == -1)
            break;
        switch(c) {
        case 'h':
            help();
            break;
        case 'f':
            fmt = optarg;
            break;
        }
    }
    if (optind >= argc)
        help();
    filename = argv[optind++];

    bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS);
    if (!bs) {
        return 1;
    }
    ret = bdrv_check(bs, &result);

    if (ret == -ENOTSUP) {
        error("This image format does not support checks");
        bdrv_delete(bs);
        return 1;
    }

    if (!(result.corruptions || result.leaks || result.check_errors)) {
        printf("No errors were found on the image.\n");
    } else {
        if (result.corruptions) {
            printf("\n%d errors were found on the image.\n"
                "Data may be corrupted, or further writes to the image "
                "may corrupt it.\n",
                result.corruptions);
        }

        if (result.leaks) {
            printf("\n%d leaked clusters were found on the image.\n"
                "This means waste of disk space, but no harm to data.\n",
                result.leaks);
        }

        if (result.check_errors) {
            printf("\n%d internal errors have occurred during the check.\n",
                result.check_errors);
        }
    }

    bdrv_delete(bs);

    if (ret < 0 || result.check_errors) {
        printf("\nAn error has occurred during the check: %s\n"
            "The check is not complete and may have missed error.\n",
            strerror(-ret));
        return 1;
    }

    if (result.corruptions) {
        return 2;
    } else if (result.leaks) {
        return 3;
    } else {
        return 0;
    }
}