static int img_commit(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_commit(bs); switch(ret) { case 0: printf("Image committed.\n"); break; case -ENOENT: error("No disk inserted"); break; case -EACCES: error("Image is read-only"); break; case -ENOTSUP: error("Image is already committed"); break; default: error("Error while committing image"); break; } bdrv_delete(bs); return 0; }
static int img_commit(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 '?': 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 | BDRV_O_RDWR); if (!bs) { return 1; } ret = bdrv_commit(bs); switch(ret) { case 0: printf("Image committed.\n"); break; case -ENOENT: error_report("No disk inserted"); break; case -EACCES: error_report("Image is read-only"); break; case -ENOTSUP: error_report("Image is already committed"); break; default: error_report("Error while committing image"); break; } bdrv_delete(bs); if (ret) { return 1; } return 0; }
static int img_commit(int argc, char **argv) { int c, ret, flags; const char *filename, *fmt, *cache; BlockDriverState *bs; fmt = NULL; cache = BDRV_DEFAULT_CACHE; for(;;) { c = getopt(argc, argv, "f:ht:"); if (c == -1) { break; } switch(c) { case '?': case 'h': help(); break; case 'f': fmt = optarg; break; case 't': cache = optarg; break; } } if (optind >= argc) { help(); } filename = argv[optind++]; flags = BDRV_O_RDWR; ret = bdrv_parse_cache_flags(cache, &flags); if (ret < 0) { error_report("Invalid cache option: %s", cache); return -1; } bs = bdrv_new_open(filename, fmt, flags); if (!bs) { return 1; } ret = bdrv_commit(bs); switch(ret) { case 0: printf("Image committed.\n"); break; case -ENOENT: error_report("No disk inserted"); break; case -EACCES: error_report("Image is read-only"); break; case -ENOTSUP: error_report("Image is already committed"); break; default: error_report("Error while committing image"); break; } bdrv_delete(bs); if (ret) { return 1; } return 0; }