[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] error reporting: Update arch_init and block files t
From: |
Michal Novotny |
Subject: |
[Qemu-devel] [PATCH] error reporting: Update arch_init and block files to use error_report() instead of fprintf(stderr) |
Date: |
Wed, 31 Jul 2013 16:33:03 +0200 |
As mentioned on http://patchwork.ozlabs.org/patch/260801/ qemu shouldn't be
using fprintf(stderr, fmt, args) approach for error message as there's newer
function called error_report() to report errors. This patch updates block
files to use it and it also fixes indentation on block/vvfat.c file.
Signed-off-by: Michal Novotny <address@hidden>
---
arch_init.c | 31 +-
audio/wavcapture.c | 2 +-
block-migration.c | 6 +-
block/curl.c | 6 +-
block/linux-aio.c | 5 +-
block/qcow2-refcount.c | 78 ++--
block/qcow2.c | 27 +-
block/qed.c | 14 +-
block/raw-posix.c | 11 +-
block/raw-win32.c | 6 +-
block/ssh.c | 2 +-
block/vdi.c | 16 +-
block/vmdk.c | 24 +-
block/vpc.c | 4 +-
block/vvfat.c | 1107 ++++++++++++++++++++++++------------------------
bsd-user/bsdload.c | 2 +-
bsd-user/elfload.c | 2 +-
bsd-user/main.c | 11 +-
18 files changed, 676 insertions(+), 678 deletions(-)
diff --git a/arch_init.c b/arch_init.c
index 68a7ab7..29e1a9f 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -781,12 +781,12 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void
*host)
xh_len = qemu_get_be16(f);
if (xh_flags != ENCODING_FLAG_XBZRLE) {
- fprintf(stderr, "Failed to load XBZRLE page - wrong compression!\n");
+ error_report("Failed to load XBZRLE page - wrong compression!");
return -1;
}
if (xh_len > TARGET_PAGE_SIZE) {
- fprintf(stderr, "Failed to load XBZRLE page - len overflow!\n");
+ error_report("Failed to load XBZRLE page - len overflow!");
return -1;
}
/* load data and decode */
@@ -796,10 +796,10 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void
*host)
ret = xbzrle_decode_buffer(XBZRLE.decoded_buf, xh_len, host,
TARGET_PAGE_SIZE);
if (ret == -1) {
- fprintf(stderr, "Failed to load XBZRLE page - decode error!\n");
+ error_report("Failed to load XBZRLE page - decode error!");
rc = -1;
} else if (ret > TARGET_PAGE_SIZE) {
- fprintf(stderr, "Failed to load XBZRLE page - size %d exceeds %d!\n",
+ error_report("Failed to load XBZRLE page - size %d exceeds %d!",
ret, TARGET_PAGE_SIZE);
abort();
}
@@ -817,7 +817,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
if (flags & RAM_SAVE_FLAG_CONTINUE) {
if (!block) {
- fprintf(stderr, "Ack, bad migration stream!\n");
+ error_report("Ack, bad migration stream!");
return NULL;
}
@@ -833,7 +833,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
return memory_region_get_ram_ptr(block->mr) + offset;
}
- fprintf(stderr, "Can't find block %s!\n", id);
+ error_report("Can't find block %s!", id);
return NULL;
}
@@ -893,9 +893,9 @@ static int ram_load(QEMUFile *f, void *opaque, int
version_id)
QTAILQ_FOREACH(block, &ram_list.blocks, next) {
if (!strncmp(id, block->idstr, sizeof(id))) {
if (block->length != length) {
- fprintf(stderr,
+ error_report(
"Length mismatch: %s: " RAM_ADDR_FMT
- " in != " RAM_ADDR_FMT "\n", id,
length,
+ " in != " RAM_ADDR_FMT, id, length,
block->length);
ret = -EINVAL;
goto done;
@@ -905,8 +905,8 @@ static int ram_load(QEMUFile *f, void *opaque, int
version_id)
}
if (!block) {
- fprintf(stderr, "Unknown ramblock \"%s\", cannot "
- "accept migration\n", id);
+ error_report("Unknown ramblock \"%s\", cannot "
+ "accept migration", id);
ret = -EINVAL;
goto done;
}
@@ -1053,12 +1053,11 @@ void select_soundhw(const char *optarg)
if (!c->name) {
if (l > 80) {
- fprintf(stderr,
- "Unknown sound card name (too big to show)\n");
+ error_report("Unknown sound card name (too big to show)");
}
else {
- fprintf(stderr, "Unknown sound card name `%.*s'\n",
- (int) l, p);
+ error_report("Unknown sound card name `%.*s'"
+ - (int) l, p);
}
bad_card = 1;
}
@@ -1125,8 +1124,8 @@ void do_acpitable_option(const QemuOpts *opts)
acpi_table_add(opts, &err);
if (err) {
- fprintf(stderr, "Wrong acpi table provided: %s\n",
- error_get_pretty(err));
+ error_report("Wrong acpi table provided: %s\n",
+ error_get_pretty(err));
error_free(err);
exit(1);
}
diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index 9d94623..a792ebb 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -63,7 +63,7 @@ static void wav_destroy (void *opaque)
}
doclose:
if (fclose (wav->f)) {
- fprintf (stderr, "wav_destroy: fclose failed: %s",
+ error_report("wav_destroy: fclose failed: %s",
strerror (errno));
}
}
diff --git a/block-migration.c b/block-migration.c
index f803f20..374de8f 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -758,8 +758,8 @@ static int block_load(QEMUFile *f, void *opaque, int
version_id)
bs = bdrv_find(device_name);
if (!bs) {
- fprintf(stderr, "Error unknown block device %s\n",
- device_name);
+ error_report("Error unknown block device %s\n",
+ device_name);
return -EINVAL;
}
@@ -800,7 +800,7 @@ static int block_load(QEMUFile *f, void *opaque, int
version_id)
(addr == 100) ? '\n' : '\r');
fflush(stdout);
} else if (!(flags & BLK_MIG_FLAG_EOS)) {
- fprintf(stderr, "Unknown block migration flags: %#x\n", flags);
+ error_report("Unknown block migration flags: %#x\n", flags);
return -EINVAL;
}
ret = qemu_file_get_error(f);
diff --git a/block/curl.c b/block/curl.c
index 82d39ff..0721ec7 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -424,8 +424,8 @@ static int curl_open(BlockDriverState *bs, QDict *options,
int flags)
s->readahead_size = qemu_opt_get_size(opts, "readahead", READ_AHEAD_SIZE);
if ((s->readahead_size & 0x1ff) != 0) {
- fprintf(stderr, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n",
- s->readahead_size);
+ error_report("HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n",
+ s->readahead_size);
goto out_noclean;
}
@@ -486,7 +486,7 @@ static int curl_open(BlockDriverState *bs, QDict *options,
int flags)
return 0;
out:
- fprintf(stderr, "CURL: Error opening file: %s\n", state->errmsg);
+ error_report("CURL: Error opening file: %s\n", state->errmsg);
curl_easy_cleanup(state->curl);
state->curl = NULL;
out_noclean:
diff --git a/block/linux-aio.c b/block/linux-aio.c
index ee0f8d1..7c31f79 100644
--- a/block/linux-aio.c
+++ b/block/linux-aio.c
@@ -12,6 +12,7 @@
#include "qemu/queue.h"
#include "block/raw-aio.h"
#include "qemu/event_notifier.h"
+#include "qemu/error-report.h"
#include <libaio.h>
@@ -172,8 +173,8 @@ BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void
*aio_ctx, int fd,
break;
/* Currently Linux kernel does not support other operations */
default:
- fprintf(stderr, "%s: invalid AIO request type 0x%x.\n",
- __func__, type);
+ error_report("%s: invalid AIO request type 0x%x.\n",
+ __func__, type);
goto out_free_aiocb;
}
io_set_eventfd(&laiocb->iocb, event_notifier_get_fd(&s->e));
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 1244693..b58685c 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -768,7 +768,7 @@ void qcow2_free_clusters(BlockDriverState *bs,
BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_FREE);
ret = update_refcount(bs, offset, size, -1, type);
if (ret < 0) {
- fprintf(stderr, "qcow2_free_clusters failed: %s\n", strerror(-ret));
+ error_report("qcow2_free_clusters failed: %s\n", strerror(-ret));
/* TODO Remember the clusters to free them later and avoid leaking */
}
}
@@ -994,18 +994,18 @@ static void inc_refcounts(BlockDriverState *bs,
cluster_offset += s->cluster_size) {
k = cluster_offset >> s->cluster_bits;
if (k < 0) {
- fprintf(stderr, "ERROR: invalid cluster offset=0x%" PRIx64 "\n",
- cluster_offset);
+ error_report("Invalid cluster offset=0x%" PRIx64,
+ cluster_offset);
res->corruptions++;
} else if (k >= refcount_table_size) {
- fprintf(stderr, "Warning: cluster offset=0x%" PRIx64 " is after "
- "the end of the image file, can't properly check refcounts.\n",
- cluster_offset);
+ error_report("Warning: cluster offset=0x%" PRIx64 " is after "
+ "the end of the image file, can't properly check
refcounts.",
+ cluster_offset);
res->check_errors++;
} else {
if (++refcount_table[k] == 0) {
- fprintf(stderr, "ERROR: overflow cluster offset=0x%" PRIx64
- "\n", cluster_offset);
+ error_report("Overflow cluster offset=0x%" PRIx64,
+ cluster_offset);
res->corruptions++;
}
}
@@ -1050,9 +1050,9 @@ static int check_refcounts_l2(BlockDriverState *bs,
BdrvCheckResult *res,
case QCOW2_CLUSTER_COMPRESSED:
/* Compressed clusters don't have QCOW_OFLAG_COPIED */
if (l2_entry & QCOW_OFLAG_COPIED) {
- fprintf(stderr, "ERROR: cluster %" PRId64 ": "
- "copied flag must never be set for compressed "
- "clusters\n", l2_entry >> s->cluster_bits);
+ error_report("Cluster %" PRId64 ": "
+ "copied flag must never be set for compressed "
+ "clusters", l2_entry >> s->cluster_bits);
l2_entry &= ~QCOW_OFLAG_COPIED;
res->corruptions++;
}
@@ -1091,13 +1091,13 @@ static int check_refcounts_l2(BlockDriverState *bs,
BdrvCheckResult *res,
if (flags & CHECK_OFLAG_COPIED) {
refcount = get_refcount(bs, offset >> s->cluster_bits);
if (refcount < 0) {
- fprintf(stderr, "Can't get refcount for offset %"
- PRIx64 ": %s\n", l2_entry, strerror(-refcount));
+ error_report("Can't get refcount for offset %"
+ PRIx64 ": %s", l2_entry, strerror(-refcount));
goto fail;
}
if ((refcount == 1) != ((l2_entry & QCOW_OFLAG_COPIED) != 0)) {
- fprintf(stderr, "ERROR OFLAG_COPIED: offset=%"
- PRIx64 " refcount=%d\n", l2_entry, refcount);
+ error_report("OFLAG_COPIED: offset=%"
+ PRIx64 " refcount=%d", l2_entry, refcount);
res->corruptions++;
}
}
@@ -1117,8 +1117,8 @@ static int check_refcounts_l2(BlockDriverState *bs,
BdrvCheckResult *res,
/* Correct offsets are cluster aligned */
if (offset & (s->cluster_size - 1)) {
- fprintf(stderr, "ERROR offset=%" PRIx64 ": Cluster is not "
- "properly aligned; L2 entry corrupted.\n", offset);
+ error_report("offset=%" PRIx64 ": Cluster is not "
+ "properly aligned; L2 entry corrupted.\n",
offset);
res->corruptions++;
}
break;
@@ -1136,7 +1136,7 @@ static int check_refcounts_l2(BlockDriverState *bs,
BdrvCheckResult *res,
return 0;
fail:
- fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n");
+ error_report("I/O error in check_refcounts_l2\n");
g_free(l2_table);
return -EIO;
}
@@ -1187,13 +1187,13 @@ static int check_refcounts_l1(BlockDriverState *bs,
refcount = get_refcount(bs, (l2_offset & ~QCOW_OFLAG_COPIED)
>> s->cluster_bits);
if (refcount < 0) {
- fprintf(stderr, "Can't get refcount for l2_offset %"
- PRIx64 ": %s\n", l2_offset, strerror(-refcount));
+ error_report("Can't get refcount for l2_offset %"
+ PRIx64 ": %s", l2_offset,
strerror(-refcount));
goto fail;
}
if ((refcount == 1) != ((l2_offset & QCOW_OFLAG_COPIED) != 0))
{
- fprintf(stderr, "ERROR OFLAG_COPIED: l2_offset=%" PRIx64
- " refcount=%d\n", l2_offset, refcount);
+ error_report("OFLAG_COPIED: l2_offset=%" PRIx64
+ " refcount=%d", l2_offset, refcount);
res->corruptions++;
}
}
@@ -1205,8 +1205,8 @@ static int check_refcounts_l1(BlockDriverState *bs,
/* L2 tables are cluster aligned */
if (l2_offset & (s->cluster_size - 1)) {
- fprintf(stderr, "ERROR l2_offset=%" PRIx64 ": Table is not "
- "cluster aligned; L1 entry corrupted\n", l2_offset);
+ error_report("l2_offset=%" PRIx64 ": Table is not "
+ "cluster aligned; L1 entry corrupted\n",
l2_offset);
res->corruptions++;
}
@@ -1222,7 +1222,7 @@ static int check_refcounts_l1(BlockDriverState *bs,
return 0;
fail:
- fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n");
+ error_report("I/O error in check_refcounts_l1");
res->check_errors++;
g_free(l1_table);
return -EIO;
@@ -1287,15 +1287,15 @@ int qcow2_check_refcounts(BlockDriverState *bs,
BdrvCheckResult *res,
/* Refcount blocks are cluster aligned */
if (offset & (s->cluster_size - 1)) {
- fprintf(stderr, "ERROR refcount block %" PRId64 " is not "
- "cluster aligned; refcount table entry corrupted\n", i);
+ error_report("refcount block %" PRId64 " is not "
+ "cluster aligned; refcount table entry corrupted", i);
res->corruptions++;
continue;
}
if (cluster >= nb_clusters) {
- fprintf(stderr, "ERROR refcount block %" PRId64
- " is outside image\n", i);
+ error_report("ERROR refcount block %" PRId64
+ " is outside image", i);
res->corruptions++;
continue;
}
@@ -1304,9 +1304,9 @@ int qcow2_check_refcounts(BlockDriverState *bs,
BdrvCheckResult *res,
inc_refcounts(bs, res, refcount_table, nb_clusters,
offset, s->cluster_size);
if (refcount_table[cluster] != 1) {
- fprintf(stderr, "ERROR refcount block %" PRId64
- " refcount=%d\n",
- i, refcount_table[cluster]);
+ error_report("refcount block %" PRId64
+ " refcount=%d",
+ i, refcount_table[cluster]);
res->corruptions++;
}
}
@@ -1316,8 +1316,8 @@ int qcow2_check_refcounts(BlockDriverState *bs,
BdrvCheckResult *res,
for (i = 0, highest_cluster = 0; i < nb_clusters; i++) {
refcount1 = get_refcount(bs, i);
if (refcount1 < 0) {
- fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": %s\n",
- i, strerror(-refcount1));
+ error_report("Can't get refcount for cluster %" PRId64 ": %s\n",
+ i, strerror(-refcount1));
res->check_errors++;
continue;
}
@@ -1338,11 +1338,11 @@ int qcow2_check_refcounts(BlockDriverState *bs,
BdrvCheckResult *res,
num_fixed = &res->corruptions_fixed;
}
- fprintf(stderr, "%s cluster %" PRId64 " refcount=%d
reference=%d\n",
- num_fixed != NULL ? "Repairing" :
- refcount1 < refcount2 ? "ERROR" :
- "Leaked",
- i, refcount1, refcount2);
+ error_report("%s cluster %" PRId64 " refcount=%d reference=%d\n",
+ num_fixed != NULL ? "Repairing" :
+ refcount1 < refcount2 ? "ERROR" :
+ "Leaked",
+ i, refcount1, refcount2);
if (num_fixed) {
ret = update_refcount(bs, i << s->cluster_bits, 1,
diff --git a/block/qcow2.c b/block/qcow2.c
index 3376901..c4b247b 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -101,9 +101,8 @@ static int qcow2_read_extensions(BlockDriverState *bs,
uint64_t start_offset,
#endif
if (bdrv_pread(bs->file, offset, &ext, sizeof(ext)) != sizeof(ext)) {
- fprintf(stderr, "qcow2_read_extension: ERROR: "
- "pread fail from offset %" PRIu64 "\n",
- offset);
+ error_report("qcow2_read_extension: pread fail from offset %"
PRIu64,
+ offset);
return 1;
}
be32_to_cpus(&ext.magic);
@@ -123,9 +122,9 @@ static int qcow2_read_extensions(BlockDriverState *bs,
uint64_t start_offset,
case QCOW2_EXT_MAGIC_BACKING_FORMAT:
if (ext.len >= sizeof(bs->backing_format)) {
- fprintf(stderr, "ERROR: ext_backing_format: len=%u too large"
- " (>=%zu)\n",
- ext.len, sizeof(bs->backing_format));
+ error_report("ext_backing_format: len=%u too large"
+ " (>=%zu)\n",
+ ext.len, sizeof(bs->backing_format));
return 2;
}
if (bdrv_pread(bs->file, offset , bs->backing_format,
@@ -1424,8 +1423,8 @@ static int qcow2_create(const char *filename,
QEMUOptionParameter *options)
} else if (!strcmp(options->value.s, "metadata")) {
prealloc = 1;
} else {
- fprintf(stderr, "Invalid preallocation mode: '%s'\n",
- options->value.s);
+ error_report("Invalid preallocation mode: '%s'",
+ options->value.s);
return -EINVAL;
}
} else if (!strcmp(options->name, BLOCK_OPT_COMPAT_LEVEL)) {
@@ -1434,8 +1433,8 @@ static int qcow2_create(const char *filename,
QEMUOptionParameter *options)
} else if (!strcmp(options->value.s, "1.1")) {
version = 3;
} else {
- fprintf(stderr, "Invalid compatibility level: '%s'\n",
- options->value.s);
+ error_report("Invalid compatibility level: '%s'",
+ options->value.s);
return -EINVAL;
}
} else if (!strcmp(options->name, BLOCK_OPT_LAZY_REFCOUNTS)) {
@@ -1445,14 +1444,14 @@ static int qcow2_create(const char *filename,
QEMUOptionParameter *options)
}
if (backing_file && prealloc) {
- fprintf(stderr, "Backing file and preallocation cannot be used at "
- "the same time\n");
+ error_report("Backing file and preallocation cannot be used at "
+ "the same time");
return -EINVAL;
}
if (version < 3 && (flags & BLOCK_FLAG_LAZY_REFCOUNTS)) {
- fprintf(stderr, "Lazy refcounts only supported with compatibility "
- "level 1.1 and above (use compat=1.1 or greater)\n");
+ error_report("Lazy refcounts only supported with compatibility "
+ "level 1.1 and above (use compat=1.1 or greater)");
return -EINVAL;
}
diff --git a/block/qed.c b/block/qed.c
index f767b05..9b3b6c9 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -631,19 +631,19 @@ static int bdrv_qed_create(const char *filename,
QEMUOptionParameter *options)
}
if (!qed_is_cluster_size_valid(cluster_size)) {
- fprintf(stderr, "QED cluster size must be within range [%u, %u] and
power of 2\n",
- QED_MIN_CLUSTER_SIZE, QED_MAX_CLUSTER_SIZE);
+ error_report("QED cluster size must be within range [%u, %u] and power
of 2",
+ QED_MIN_CLUSTER_SIZE, QED_MAX_CLUSTER_SIZE);
return -EINVAL;
}
if (!qed_is_table_size_valid(table_size)) {
- fprintf(stderr, "QED table size must be within range [%u, %u] and
power of 2\n",
- QED_MIN_TABLE_SIZE, QED_MAX_TABLE_SIZE);
+ error_report("QED table size must be within range [%u, %u] and power
of 2",
+ QED_MIN_TABLE_SIZE, QED_MAX_TABLE_SIZE);
return -EINVAL;
}
if (!qed_is_image_size_valid(image_size, cluster_size, table_size)) {
- fprintf(stderr, "QED image size must be a non-zero multiple of "
- "cluster size and less than %" PRIu64 " bytes\n",
- qed_max_image_size(cluster_size, table_size));
+ error_report("QED image size must be a non-zero multiple of "
+ "cluster size and less than %" PRIu64 " bytes",
+ qed_max_image_size(cluster_size, table_size));
return -EINVAL;
}
diff --git a/block/raw-posix.c b/block/raw-posix.c
index ba721d3..a86f430 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -183,8 +183,8 @@ static int raw_normalize_devicepath(const char **filename)
fname = *filename;
dp = strrchr(fname, '/');
if (lstat(fname, &sb) < 0) {
- fprintf(stderr, "%s: stat failed: %s\n",
- fname, strerror(errno));
+ error_report("%s: stat failed: %s",
+ fname, strerror(errno));
return -errno;
}
@@ -198,9 +198,10 @@ static int raw_normalize_devicepath(const char **filename)
snprintf(namebuf, PATH_MAX, "%.*s/r%s",
(int)(dp - fname), fname, dp + 1);
}
- fprintf(stderr, "%s is a block device", fname);
*filename = namebuf;
- fprintf(stderr, ", using %s\n", *filename);
+
+ error_report("%s is a block device, using %s",
+ fname, *filename);
return 0;
}
@@ -768,7 +769,7 @@ static int aio_worker(void *arg)
ret = handle_aiocb_discard(aiocb);
break;
default:
- fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type);
+ error_report("invalid aio request (0x%x)", aiocb->aio_type);
ret = -EINVAL;
break;
}
diff --git a/block/raw-win32.c b/block/raw-win32.c
index 9b5b2af..ee77ed8 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -130,7 +130,7 @@ static int aio_worker(void *arg)
}
break;
default:
- fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type);
+ error_report("invalid aio request (0x%x)", aiocb->aio_type);
ret = -EINVAL;
break;
}
@@ -352,11 +352,11 @@ static int raw_truncate(BlockDriverState *bs, int64_t
offset)
*/
dwPtrLow = SetFilePointer(s->hfile, low, &high, FILE_BEGIN);
if (dwPtrLow == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
- fprintf(stderr, "SetFilePointer error: %lu\n", GetLastError());
+ error_report("SetFilePointer error: %lu", GetLastError());
return -EIO;
}
if (SetEndOfFile(s->hfile) == 0) {
- fprintf(stderr, "SetEndOfFile error: %lu\n", GetLastError());
+ error_report("SetEndOfFile error: %lu", GetLastError());
return -EIO;
}
return 0;
diff --git a/block/ssh.c b/block/ssh.c
index d7e7bf8..337f6df 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -1066,7 +1066,7 @@ static void bdrv_ssh_init(void)
r = libssh2_init(0);
if (r != 0) {
- fprintf(stderr, "libssh2 initialization failed, %d\n", r);
+ error_report("libssh2 initialization failed: %d\n", r);
exit(EXIT_FAILURE);
}
diff --git a/block/vdi.c b/block/vdi.c
index 8a91525..c0e9d06 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -300,21 +300,23 @@ static int vdi_check(BlockDriverState *bs,
BdrvCheckResult *res,
if (!VDI_IS_ALLOCATED(bmap[bmap_entry])) {
bmap[bmap_entry] = bmap_entry;
} else {
- fprintf(stderr, "ERROR: block index %" PRIu32
- " also used by %" PRIu32 "\n", bmap[bmap_entry],
bmap_entry);
+ error_report("block index %" PRIu32
+ " also used by %" PRIu32,
+ bmap[bmap_entry], bmap_entry);
res->corruptions++;
}
} else {
- fprintf(stderr, "ERROR: block index %" PRIu32
- " too large, is %" PRIu32 "\n", block, bmap_entry);
+ error_report("block index %" PRIu32
+ " too large, is %" PRIu32,
+ block, bmap_entry);
res->corruptions++;
}
}
}
if (blocks_allocated != s->header.blocks_allocated) {
- fprintf(stderr, "ERROR: allocated blocks mismatch, is %" PRIu32
- ", should be %" PRIu32 "\n",
- blocks_allocated, s->header.blocks_allocated);
+ error_report("allocated blocks mismatch, is %" PRIu32
+ ", should be %" PRIu32 "\n",
+ blocks_allocated, s->header.blocks_allocated);
res->corruptions++;
}
diff --git a/block/vmdk.c b/block/vmdk.c
index 3756333..c54a78b 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -713,8 +713,7 @@ static int vmdk_parse_extents(const char *desc,
BlockDriverState *bs,
return ret;
}
} else {
- fprintf(stderr,
- "VMDK: Not supported extent type \"%s\""".\n", type);
+ error_report("VMDK: Not supported extent type \"%s\""".\n", type);
return -ENOTSUP;
}
next_line:
@@ -755,8 +754,7 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int
flags,
if (strcmp(ct, "monolithicFlat") &&
strcmp(ct, "twoGbMaxExtentSparse") &&
strcmp(ct, "twoGbMaxExtentFlat")) {
- fprintf(stderr,
- "VMDK: Not supported image type \"%s\""".\n", ct);
+ error_report("VMDK: Not supported image type \"%s\""".\n", ct);
ret = -ENOTSUP;
goto exit;
}
@@ -1218,10 +1216,9 @@ static int vmdk_write(BlockDriverState *bs, int64_t
sector_num,
VmdkMetaData m_data;
if (sector_num > bs->total_sectors) {
- fprintf(stderr,
- "(VMDK) Wrong offset: sector_num=0x%" PRIx64
- " total_sectors=0x%" PRIx64 "\n",
- sector_num, bs->total_sectors);
+ error_report("(VMDK) Wrong offset: sector_num=0x%" PRIx64
+ " total_sectors=0x%" PRIx64,
+ sector_num, bs->total_sectors);
return -EIO;
}
@@ -1239,9 +1236,8 @@ static int vmdk_write(BlockDriverState *bs, int64_t
sector_num,
if (extent->compressed) {
if (ret == VMDK_OK) {
/* Refuse write to allocated cluster for streamOptimized */
- fprintf(stderr,
- "VMDK: can't write to allocated cluster"
- " for streamOptimized\n");
+ error_report("VMDK: can't write to allocated cluster"
+ " for streamOptimized");
return -EIO;
} else {
/* allocate */
@@ -1453,7 +1449,7 @@ static int filename_decompose(const char *filename, char
*path, char *prefix,
const char *p, *q;
if (filename == NULL || !strlen(filename)) {
- fprintf(stderr, "Vmdk: no filename provided.\n");
+ error_report("VMDK: no filename provided.");
return VMDK_ERROR;
}
p = strrchr(filename, '/');
@@ -1552,7 +1548,7 @@ static int vmdk_create(const char *filename,
QEMUOptionParameter *options)
strcmp(adapter_type, "buslogic") &&
strcmp(adapter_type, "lsilogic") &&
strcmp(adapter_type, "legacyESX")) {
- fprintf(stderr, "VMDK: Unknown adapter type: '%s'.\n", adapter_type);
+ error_report("VMDK: Unknown adapter type: '%s'.", adapter_type);
return -EINVAL;
}
if (strcmp(adapter_type, "ide") != 0) {
@@ -1568,7 +1564,7 @@ static int vmdk_create(const char *filename,
QEMUOptionParameter *options)
strcmp(fmt, "twoGbMaxExtentSparse") &&
strcmp(fmt, "twoGbMaxExtentFlat") &&
strcmp(fmt, "streamOptimized")) {
- fprintf(stderr, "VMDK: Unknown subformat: %s\n", fmt);
+ error_report("VMDK: Unknown subformat: %s", fmt);
return -EINVAL;
}
split = !(strcmp(fmt, "twoGbMaxExtentFlat") &&
diff --git a/block/vpc.c b/block/vpc.c
index fe4f311..3a083c5 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -198,8 +198,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options,
int flags)
checksum = be32_to_cpu(footer->checksum);
footer->checksum = 0;
if (vpc_checksum(s->footer_buf, HEADER_SIZE) != checksum)
- fprintf(stderr, "block-vpc: The header checksum of '%s' is "
- "incorrect.\n", bs->filename);
+ error_report("block-vpc: The header checksum of '%s' is "
+ "incorrect.\n", bs->filename);
/* Write 'checksum' back to footer, or else will leave it with zero. */
footer->checksum = be32_to_cpu(checksum);
diff --git a/block/vvfat.c b/block/vvfat.c
index cd3b8ed..699d2cd 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -30,6 +30,7 @@
#include "migration/migration.h"
#include "qapi/qmp/qint.h"
#include "qapi/qmp/qbool.h"
+#include "qemu/error-report.h"
#ifndef S_IWGRP
#define S_IWGRP 0
@@ -60,7 +61,7 @@ static void checkpoint(void);
#ifdef __MINGW32__
void nonono(const char* file, int line, const char* msg) {
- fprintf(stderr, "Nonono! %s:%d %s\n", file, line, msg);
+ error_report("Nonono! %s:%d %s", file, line, msg);
exit(-5);
}
#undef assert
@@ -102,12 +103,12 @@ static inline void* array_get(array_t* array,unsigned int
index) {
static inline int array_ensure_allocated(array_t* array, int index)
{
if((index + 1) * array->item_size > array->size) {
- int new_size = (index + 32) * array->item_size;
- array->pointer = g_realloc(array->pointer, new_size);
- if (!array->pointer)
- return -1;
- array->size = new_size;
- array->next = index + 1;
+ int new_size = (index + 32) * array->item_size;
+ array->pointer = g_realloc(array->pointer, new_size);
+ if (!array->pointer)
+ return -1;
+ array->size = new_size;
+ array->next = index + 1;
}
return 0;
@@ -118,7 +119,7 @@ static inline void* array_get_next(array_t* array) {
void* result;
if (array_ensure_allocated(array, next) < 0)
- return NULL;
+ return NULL;
array->next = next + 1;
result = array_get(array, next);
@@ -127,16 +128,16 @@ static inline void* array_get_next(array_t* array) {
}
static inline void* array_insert(array_t* array,unsigned int index,unsigned
int count) {
- if((array->next+count)*array->item_size>array->size) {
- int increment=count*array->item_size;
- array->pointer=g_realloc(array->pointer,array->size+increment);
- if(!array->pointer)
+ if ((array->next+count)*array->item_size>array->size) {
+ int increment=count*array->item_size;
+ array->pointer=g_realloc(array->pointer,array->size+increment);
+ if (!array->pointer)
return NULL;
- array->size+=increment;
+ array->size+=increment;
}
memmove(array->pointer+(index+count)*array->item_size,
- array->pointer+index*array->item_size,
- (array->next-index)*array->item_size);
+ array->pointer+index*array->item_size,
+ (array->next-index)*array->item_size);
array->next+=count;
return array->pointer+index*array->item_size;
}
@@ -150,13 +151,13 @@ static inline int array_roll(array_t* array,int
index_to,int index_from,int coun
char* to;
int is;
- if(!array ||
- index_to<0 || index_to>=array->next ||
- index_from<0 || index_from>=array->next)
- return -1;
+ if (!array ||
+ index_to < 0 || index_to >= array->next ||
+ index_from < 0 || index_from >= array->next)
+ return -1;
- if(index_to==index_from)
- return 0;
+ if (index_to==index_from)
+ return 0;
is=array->item_size;
from=array->pointer+index_from*is;
@@ -165,12 +166,11 @@ static inline int array_roll(array_t* array,int
index_to,int index_from,int coun
memcpy(buf,from,is*count);
if(index_to<index_from)
- memmove(to+is*count,to,from-to);
+ memmove(to+is*count,to,from-to);
else
- memmove(from,from+is*count,to-from);
+ memmove(from,from+is*count,to-from);
memcpy(to,buf,is*count);
-
g_free(buf);
return 0;
@@ -182,7 +182,7 @@ static inline int array_remove_slice(array_t* array,int
index, int count)
assert(count > 0);
assert(index + count <= array->next);
if(array_roll(array,array->next-1,index,count))
- return -1;
+ return -1;
array->next -= count;
return 0;
}
@@ -425,12 +425,12 @@ static inline int short2long_name(char* dest,const char*
src)
int len;
for(i=0;i<129 && src[i];i++) {
dest[2*i]=src[i];
- dest[2*i+1]=0;
+ dest[2*i+1]=0;
}
len=2*i;
dest[2*i]=dest[2*i+1]=0;
for(i=2*i+2;(i%26);i++)
- dest[i]=0xff;
+ dest[i]=0xff;
return len;
}
@@ -442,19 +442,19 @@ static inline direntry_t*
create_long_filename(BDRVVVFATState* s,const char* fil
direntry_t* entry;
for(i=0;i<number_of_entries;i++) {
- entry=array_get_next(&(s->directory));
- entry->attributes=0xf;
- entry->reserved[0]=0;
- entry->begin=0;
- entry->name[0]=(number_of_entries-i)|(i==0?0x40:0);
+ entry=array_get_next(&(s->directory));
+ entry->attributes=0xf;
+ entry->reserved[0]=0;
+ entry->begin=0;
+ entry->name[0]=(number_of_entries-i)|(i==0?0x40:0);
}
for(i=0;i<26*number_of_entries;i++) {
- int offset=(i%26);
- if(offset<10) offset=1+offset;
- else if(offset<22) offset=14+offset-10;
- else offset=28+offset-22;
- entry=array_get(&(s->directory),s->directory.next-1-(i/26));
- entry->name[offset]=buffer[i];
+ int offset=(i%26);
+ if(offset<10) offset=1+offset;
+ else if(offset<22) offset=14+offset-10;
+ else offset=28+offset-22;
+ entry=array_get(&(s->directory),s->directory.next-1-(i/26));
+ entry->name[offset]=buffer[i];
}
return array_get(&(s->directory),s->directory.next-number_of_entries);
}
@@ -534,74 +534,73 @@ static uint16_t fat_datetime(time_t time,int return_time)
{
struct tm t1;
t = &t1;
localtime_r(&time,t);
- if(return_time)
- return cpu_to_le16((t->tm_sec/2)|(t->tm_min<<5)|(t->tm_hour<<11));
+ if (return_time)
+ return cpu_to_le16((t->tm_sec/2)|(t->tm_min<<5)|(t->tm_hour<<11));
return cpu_to_le16((t->tm_mday)|((t->tm_mon+1)<<5)|((t->tm_year-80)<<9));
}
static inline void fat_set(BDRVVVFATState* s,unsigned int cluster,uint32_t
value)
{
if(s->fat_type==32) {
- uint32_t* entry=array_get(&(s->fat),cluster);
- *entry=cpu_to_le32(value);
+ uint32_t* entry=array_get(&(s->fat),cluster);
+ *entry=cpu_to_le32(value);
} else if(s->fat_type==16) {
- uint16_t* entry=array_get(&(s->fat),cluster);
- *entry=cpu_to_le16(value&0xffff);
+ uint16_t* entry=array_get(&(s->fat),cluster);
+ *entry=cpu_to_le16(value&0xffff);
} else {
- int offset = (cluster*3/2);
- unsigned char* p = array_get(&(s->fat), offset);
- switch (cluster&1) {
- case 0:
- p[0] = value&0xff;
- p[1] = (p[1]&0xf0) | ((value>>8)&0xf);
- break;
- case 1:
- p[0] = (p[0]&0xf) | ((value&0xf)<<4);
- p[1] = (value>>4);
- break;
- }
+ int offset = (cluster*3/2);
+ unsigned char* p = array_get(&(s->fat), offset);
+ switch (cluster & 1) {
+ case 0:
+ p[0] = value&0xff;
+ p[1] = (p[1]&0xf0) | ((value>>8)&0xf);
+ break;
+ case 1:
+ p[0] = (p[0]&0xf) | ((value&0xf)<<4);
+ p[1] = (value>>4);
+ break;
+ }
}
}
static inline uint32_t fat_get(BDRVVVFATState* s,unsigned int cluster)
{
if(s->fat_type==32) {
- uint32_t* entry=array_get(&(s->fat),cluster);
- return le32_to_cpu(*entry);
+ uint32_t* entry = array_get(&(s->fat),cluster);
+ return le32_to_cpu(*entry);
} else if(s->fat_type==16) {
- uint16_t* entry=array_get(&(s->fat),cluster);
- return le16_to_cpu(*entry);
+ uint16_t* entry=array_get(&(s->fat),cluster);
+ return le16_to_cpu(*entry);
} else {
- const uint8_t* x=(uint8_t*)(s->fat.pointer)+cluster*3/2;
- return ((x[0]|(x[1]<<8))>>(cluster&1?4:0))&0x0fff;
+ const uint8_t* x=(uint8_t*)(s->fat.pointer)+cluster*3/2;
+ return ((x[0]|(x[1]<<8))>>(cluster&1?4:0))&0x0fff;
}
}
static inline int fat_eof(BDRVVVFATState* s,uint32_t fat_entry)
{
- if(fat_entry>s->max_fat_value-8)
- return -1;
+ if (fat_entry > s->max_fat_value - 8)
+ return -1;
return 0;
}
static inline void init_fat(BDRVVVFATState* s)
{
if (s->fat_type == 12) {
- array_init(&(s->fat),1);
- array_ensure_allocated(&(s->fat),
- s->sectors_per_fat * 0x200 * 3 / 2 - 1);
+ array_init(&(s->fat),1);
+ array_ensure_allocated(&(s->fat), s->sectors_per_fat * 0x200 * 3 / 2 -
1);
} else {
- array_init(&(s->fat),(s->fat_type==32?4:2));
- array_ensure_allocated(&(s->fat),
- s->sectors_per_fat * 0x200 / s->fat.item_size - 1);
+ array_init(&(s->fat),(s->fat_type==32?4:2));
+ array_ensure_allocated(&(s->fat),
+ s->sectors_per_fat * 0x200 / s->fat.item_size - 1);
}
memset(s->fat.pointer,0,s->fat.size);
switch(s->fat_type) {
- case 12: s->max_fat_value=0xfff; break;
- case 16: s->max_fat_value=0xffff; break;
- case 32: s->max_fat_value=0x0fffffff; break;
- default: s->max_fat_value=0; /* error... */
+ case 12: s->max_fat_value=0xfff; break;
+ case 16: s->max_fat_value=0xffff; break;
+ case 32: s->max_fat_value=0x0fffffff; break;
+ default: s->max_fat_value=0; /* error... */
}
}
@@ -615,79 +614,80 @@ static inline direntry_t*
create_short_and_long_name(BDRVVVFATState* s,
direntry_t* entry = NULL;
direntry_t* entry_long = NULL;
- if(is_dot) {
- entry=array_get_next(&(s->directory));
- memset(entry->name,0x20,11);
- memcpy(entry->name,filename,strlen(filename));
- return entry;
+ if (is_dot) {
+ entry = array_get_next(&(s->directory));
+ memset(entry->name,0x20,11);
+ memcpy(entry->name,filename,strlen(filename));
+ return entry;
}
entry_long=create_long_filename(s,filename);
i = strlen(filename);
- for(j = i - 1; j>0 && filename[j]!='.';j--);
+ for (j = i - 1; j>0 && filename[j]!='.';j--);
if (j > 0)
- i = (j > 8 ? 8 : j);
+ i = (j > 8 ? 8 : j);
else if (i > 8)
- i = 8;
+ i = 8;
entry=array_get_next(&(s->directory));
memset(entry->name,0x20,11);
memcpy(entry->name, filename, i);
- if(j > 0)
- for (i = 0; i < 3 && filename[j+1+i]; i++)
- entry->extension[i] = filename[j+1+i];
+ if (j > 0)
+ for (i = 0; i < 3 && filename[j+1+i]; i++)
+ entry->extension[i] = filename[j+1+i];
/* upcase & remove unwanted characters */
- for(i=10;i>=0;i--) {
- if(i==10 || i==7) for(;i>0 && entry->name[i]==' ';i--);
- if(entry->name[i]<=' ' || entry->name[i]>0x7f
- || strchr(".*?<>|\":/\\[];,+='",entry->name[i]))
- entry->name[i]='_';
+ for (i = 10;i >= 0; i--) {
+ if (i == 10 || i == 7)
+ for(;i > 0 && entry->name[i]==' ';i--);
+ if (entry->name[i]<=' ' || entry->name[i] > 0x7f
+ || strchr(".*?<>|\":/\\[];,+='",entry->name[i]))
+ entry->name[i]='_';
else if(entry->name[i]>='a' && entry->name[i]<='z')
entry->name[i]+='A'-'a';
}
/* mangle duplicates */
- while(1) {
- direntry_t* entry1=array_get(&(s->directory),directory_start);
- int j;
-
- for(;entry1<entry;entry1++)
- if(!is_long_name(entry1) && !memcmp(entry1->name,entry->name,11))
- break; /* found dupe */
- if(entry1==entry) /* no dupe found */
- break;
-
- /* use all 8 characters of name */
- if(entry->name[7]==' ') {
- int j;
- for(j=6;j>0 && entry->name[j]==' ';j--)
- entry->name[j]='~';
- }
+ while (1) {
+ direntry_t* entry1=array_get(&(s->directory),directory_start);
+ int j;
+
+ for(;entry1<entry;entry1++)
+ if(!is_long_name(entry1) && !memcmp(entry1->name,entry->name,11))
+ break; /* found dupe */
+ if (entry1==entry) /* no dupe found */
+ break;
+
+ /* use all 8 characters of name */
+ if(entry->name[7]==' ') {
+ int j;
+ for (j = 6; j > 0 && entry->name[j]==' ';j--)
+ entry->name[j]='~';
+ }
- /* increment number */
- for(j=7;j>0 && entry->name[j]=='9';j--)
- entry->name[j]='0';
- if(j>0) {
- if(entry->name[j]<'0' || entry->name[j]>'9')
- entry->name[j]='0';
- else
- entry->name[j]++;
- }
+ /* increment number */
+ for (j = 7; j > 0 && entry->name[j]=='9';j--)
+ entry->name[j]='0';
+ if (j > 0) {
+ if (entry->name[j]<'0' || entry->name[j]>'9')
+ entry->name[j]='0';
+ else
+ entry->name[j]++;
+ }
}
/* calculate checksum; propagate to long name */
- if(entry_long) {
+ if (entry_long) {
uint8_t chksum=fat_chksum(entry);
- /* calculate anew, because realloc could have taken place */
- entry_long=array_get(&(s->directory),long_index);
- while(entry_long<entry && is_long_name(entry_long)) {
- entry_long->reserved[1]=chksum;
- entry_long++;
- }
+ /* calculate a new, because realloc could have taken place */
+ entry_long=array_get(&(s->directory),long_index);
+ while(entry_long<entry && is_long_name(entry_long)) {
+ entry_long->reserved[1]=chksum;
+ entry_long++;
+ }
}
return entry;
@@ -714,8 +714,8 @@ static int read_directory(BDRVVVFATState* s, int
mapping_index)
assert(mapping->mode & MODE_DIRECTORY);
if(!dir) {
- mapping->end = mapping->begin;
- return -1;
+ mapping->end = mapping->begin;
+ return -1;
}
i = mapping->info.dir.first_dir_index =
@@ -723,90 +723,91 @@ static int read_directory(BDRVVVFATState* s, int
mapping_index)
/* actually read the directory, and allocate the mappings */
while((entry=readdir(dir))) {
- unsigned int length=strlen(dirname)+2+strlen(entry->d_name);
+ unsigned int length=strlen(dirname)+2+strlen(entry->d_name);
char* buffer;
- direntry_t* direntry;
+ direntry_t* direntry;
struct stat st;
- int is_dot=!strcmp(entry->d_name,".");
- int is_dotdot=!strcmp(entry->d_name,"..");
+ int is_dot=!strcmp(entry->d_name,".");
+ int is_dotdot=!strcmp(entry->d_name,"..");
- if(first_cluster == 0 && (is_dotdot || is_dot))
- continue;
+ if (first_cluster == 0 && (is_dotdot || is_dot))
+ continue;
- buffer=(char*)g_malloc(length);
- snprintf(buffer,length,"%s/%s",dirname,entry->d_name);
+ buffer=(char*)g_malloc(length);
+ snprintf(buffer,length,"%s/%s",dirname,entry->d_name);
- if(stat(buffer,&st)<0) {
+ if (stat(buffer,&st) < 0) {
g_free(buffer);
continue;
- }
+ }
+
+ /* create directory entry for this file */
+ direntry=create_short_and_long_name(s, i, entry->d_name, is_dot ||
is_dotdot);
+ direntry->attributes=(S_ISDIR(st.st_mode)?0x10:0x20);
+ direntry->reserved[0]=direntry->reserved[1]=0;
+ direntry->ctime=fat_datetime(st.st_ctime,1);
+ direntry->cdate=fat_datetime(st.st_ctime,0);
+ direntry->adate=fat_datetime(st.st_atime,0);
+ direntry->begin_hi=0;
+ direntry->mtime=fat_datetime(st.st_mtime,1);
+ direntry->mdate=fat_datetime(st.st_mtime,0);
+ if(is_dotdot)
+ set_begin_of_direntry(direntry, first_cluster_of_parent);
+ else if(is_dot)
+ set_begin_of_direntry(direntry, first_cluster);
+ else
+ direntry->begin=0; /* do that later */
- /* create directory entry for this file */
- direntry=create_short_and_long_name(s, i, entry->d_name,
- is_dot || is_dotdot);
- direntry->attributes=(S_ISDIR(st.st_mode)?0x10:0x20);
- direntry->reserved[0]=direntry->reserved[1]=0;
- direntry->ctime=fat_datetime(st.st_ctime,1);
- direntry->cdate=fat_datetime(st.st_ctime,0);
- direntry->adate=fat_datetime(st.st_atime,0);
- direntry->begin_hi=0;
- direntry->mtime=fat_datetime(st.st_mtime,1);
- direntry->mdate=fat_datetime(st.st_mtime,0);
- if(is_dotdot)
- set_begin_of_direntry(direntry, first_cluster_of_parent);
- else if(is_dot)
- set_begin_of_direntry(direntry, first_cluster);
- else
- direntry->begin=0; /* do that later */
if (st.st_size > 0x7fffffff) {
- fprintf(stderr, "File %s is larger than 2GB\n", buffer);
+ error_report("File %s is larger than 2GB", buffer);
g_free(buffer);
closedir(dir);
- return -2;
+ return -2;
+ }
+
+ direntry->size=cpu_to_le32(S_ISDIR(st.st_mode)?0:st.st_size);
+
+ /* create mapping for this file */
+ if (!is_dot && !is_dotdot && (S_ISDIR(st.st_mode) || st.st_size)) {
+ s->current_mapping=(mapping_t*)array_get_next(&(s->mapping));
+ s->current_mapping->begin=0;
+ s->current_mapping->end=st.st_size;
+ /*
+ * we get the direntry of the most recent direntry, which
+ * contains the short name and all the relevant information.
+ */
+ s->current_mapping->dir_index=s->directory.next-1;
+ s->current_mapping->first_mapping_index = -1;
+ if (S_ISDIR(st.st_mode)) {
+ s->current_mapping->mode = MODE_DIRECTORY;
+ s->current_mapping->info.dir.parent_mapping_index =
+ mapping_index;
+ } else {
+ s->current_mapping->mode = MODE_UNDEFINED;
+ s->current_mapping->info.file.offset = 0;
+ }
+ s->current_mapping->path = buffer;
+ s->current_mapping->read_only =
+ (st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0;
}
- direntry->size=cpu_to_le32(S_ISDIR(st.st_mode)?0:st.st_size);
-
- /* create mapping for this file */
- if(!is_dot && !is_dotdot && (S_ISDIR(st.st_mode) || st.st_size)) {
- s->current_mapping=(mapping_t*)array_get_next(&(s->mapping));
- s->current_mapping->begin=0;
- s->current_mapping->end=st.st_size;
- /*
- * we get the direntry of the most recent direntry, which
- * contains the short name and all the relevant information.
- */
- s->current_mapping->dir_index=s->directory.next-1;
- s->current_mapping->first_mapping_index = -1;
- if (S_ISDIR(st.st_mode)) {
- s->current_mapping->mode = MODE_DIRECTORY;
- s->current_mapping->info.dir.parent_mapping_index =
- mapping_index;
- } else {
- s->current_mapping->mode = MODE_UNDEFINED;
- s->current_mapping->info.file.offset = 0;
- }
- s->current_mapping->path=buffer;
- s->current_mapping->read_only =
- (st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0;
- }
}
closedir(dir);
/* fill with zeroes up to the end of the cluster */
- while(s->directory.next%(0x10*s->sectors_per_cluster)) {
- direntry_t* direntry=array_get_next(&(s->directory));
- memset(direntry,0,sizeof(direntry_t));
+ while (s->directory.next%(0x10*s->sectors_per_cluster)) {
+ direntry_t* direntry=array_get_next(&(s->directory));
+ memset(direntry,0,sizeof(direntry_t));
}
/* TODO: if there are more entries, bootsector has to be adjusted! */
#define ROOT_ENTRIES (0x02 * 0x10 * s->sectors_per_cluster)
if (mapping_index == 0 && s->directory.next < ROOT_ENTRIES) {
- /* root directory */
- int cur = s->directory.next;
- array_ensure_allocated(&(s->directory), ROOT_ENTRIES - 1);
- s->directory.next = ROOT_ENTRIES;
- memset(array_get(&(s->directory), cur), 0,
- (ROOT_ENTRIES - cur) * sizeof(direntry_t));
+ /* root directory */
+ int cur = s->directory.next;
+ array_ensure_allocated(&(s->directory), ROOT_ENTRIES - 1);
+ s->directory.next = ROOT_ENTRIES;
+ memset(array_get(&(s->directory), cur), 0,
+ (ROOT_ENTRIES - cur) * sizeof(direntry_t));
}
/* reget the mapping, since s->mapping was possibly realloc()ed */
@@ -879,60 +880,61 @@ static int init_directories(BDRVVVFATState* s,
mapping->path = g_strdup(dirname);
i = strlen(mapping->path);
if (i > 0 && mapping->path[i - 1] == '/')
- mapping->path[i - 1] = '\0';
+ mapping->path[i - 1] = '\0';
+
mapping->mode = MODE_DIRECTORY;
mapping->read_only = 0;
s->path = mapping->path;
for (i = 0, cluster = 0; i < s->mapping.next; i++) {
- /* MS-DOS expects the FAT to be 0 for the root directory
- * (except for the media byte). */
- /* LATER TODO: still true for FAT32? */
- int fix_fat = (i != 0);
- mapping = array_get(&(s->mapping), i);
+ /* MS-DOS expects the FAT to be 0 for the root directory
+ * (except for the media byte). */
+ /* LATER TODO: still true for FAT32? */
+ int fix_fat = (i != 0);
+ mapping = array_get(&(s->mapping), i);
if (mapping->mode & MODE_DIRECTORY) {
- mapping->begin = cluster;
- if(read_directory(s, i)) {
- fprintf(stderr, "Could not read directory %s\n",
- mapping->path);
- return -1;
- }
- mapping = array_get(&(s->mapping), i);
- } else {
- assert(mapping->mode == MODE_UNDEFINED);
- mapping->mode=MODE_NORMAL;
- mapping->begin = cluster;
- if (mapping->end > 0) {
- direntry_t* direntry = array_get(&(s->directory),
- mapping->dir_index);
-
- mapping->end = cluster + 1 + (mapping->end-1)/s->cluster_size;
- set_begin_of_direntry(direntry, mapping->begin);
+ mapping->begin = cluster;
+ if (read_directory(s, i)) {
+ error_report("Could not read directory %s",
+ mapping->path);
+ return -1;
+ }
+ mapping = array_get(&(s->mapping), i);
} else {
- mapping->end = cluster + 1;
- fix_fat = 0;
+ assert(mapping->mode == MODE_UNDEFINED);
+ mapping->mode=MODE_NORMAL;
+ mapping->begin = cluster;
+ if (mapping->end > 0) {
+ direntry_t* direntry = array_get(&(s->directory),
+ mapping->dir_index);
+
+ mapping->end = cluster + 1 + (mapping->end-1)/s->cluster_size;
+ set_begin_of_direntry(direntry, mapping->begin);
+ } else {
+ mapping->end = cluster + 1;
+ fix_fat = 0;
+ }
}
- }
- assert(mapping->begin < mapping->end);
+ assert(mapping->begin < mapping->end);
- /* next free cluster */
- cluster = mapping->end;
+ /* next free cluster */
+ cluster = mapping->end;
- if(cluster > s->cluster_count) {
- fprintf(stderr,"Directory does not fit in FAT%d (capacity %.2f
MB)\n",
- s->fat_type, s->sector_count / 2000.0);
- return -EINVAL;
- }
+ if (cluster > s->cluster_count) {
+ error_report("Directory does not fit in FAT%d (capacity
%.2f MB)\n",
+ s->fat_type, s->sector_count / 2000.0);
+ return -EINVAL;
+ }
- /* fix fat for entry */
- if (fix_fat) {
- int j;
- for(j = mapping->begin; j < mapping->end - 1; j++)
- fat_set(s, j, j+1);
- fat_set(s, mapping->end - 1, s->max_fat_value);
- }
+ /* fix fat for entry */
+ if (fix_fat) {
+ int j;
+ for (j = mapping->begin; j < mapping->end - 1; j++)
+ fat_set(s, j, j+1);
+ fat_set(s, mapping->end - 1, s->max_fat_value);
+ }
}
mapping = array_get(&(s->mapping), 0);
@@ -1129,8 +1131,8 @@ DLOG(if (stderr == NULL) {
switch (s->fat_type) {
case 32:
- fprintf(stderr, "Big fat greek warning: FAT32 has not been tested. "
- "You are welcome to do so!\n");
+ error_report("Big fat greek warning: FAT32 has not been tested. "
+ "You are welcome to do so!");
break;
case 16:
case 12:
@@ -1158,8 +1160,8 @@ DLOG(if (stderr == NULL) {
s->fat2 = NULL;
s->downcase_short_names = 1;
- fprintf(stderr, "vvfat %s chs %d,%d,%d\n",
- dirname, cyls, heads, secs);
+ error_report("vvfat %s chs %d,%d,%d",
+ dirname, cyls, heads, secs);
s->sector_count = cyls * heads * secs - (s->first_sectors_number - 1);
@@ -1380,7 +1382,7 @@ static int vvfat_read(BlockDriverState *bs, int64_t
sector_num,
if (s->qcow) {
int n;
if (bdrv_is_allocated(s->qcow, sector_num, nb_sectors-i, &n)) {
-DLOG(fprintf(stderr, "sectors %d+%d allocated\n", (int)sector_num, n));
+DLOG(error_report("sectors %d+%d allocated", (int)sector_num, n));
if (bdrv_read(s->qcow, sector_num, buf + i*0x200, n)) {
return -1;
}
@@ -1388,7 +1390,7 @@ DLOG(fprintf(stderr, "sectors %d+%d allocated\n",
(int)sector_num, n));
sector_num += n - 1;
continue;
}
-DLOG(fprintf(stderr, "sector %d not allocated\n", (int)sector_num));
+DLOG(error_report("sector %d not allocated", (int)sector_num));
}
if(sector_num<s->faked_sectors) {
if(sector_num<s->first_sectors_number)
@@ -1462,7 +1464,7 @@ typedef struct commit_t {
static void clear_commits(BDRVVVFATState* s)
{
int i;
-DLOG(fprintf(stderr, "clear_commits (%d commits)\n", s->commits.next));
+DLOG(error_report("clear_commits (%d commits)\n", s->commits.next));
for (i = 0; i < s->commits.next; i++) {
commit_t* commit = array_get(&(s->commits), i);
assert(commit->path || commit->action == ACTION_WRITEOUT);
@@ -1864,41 +1866,41 @@ static int check_directory_consistency(BDRVVVFATState
*s,
ret++;
if (s->used_clusters[cluster_num] & USED_ANY) {
- fprintf(stderr, "cluster %d used more than once\n",
(int)cluster_num);
+ error_report("cluster %d used more than once", (int)cluster_num);
return 0;
}
s->used_clusters[cluster_num] = USED_DIRECTORY;
-DLOG(fprintf(stderr, "read cluster %d (sector %d)\n", (int)cluster_num,
(int)cluster2sector(s, cluster_num)));
+ DLOG(error_report("read cluster %d (sector %d)", (int)cluster_num,
(int)cluster2sector(s, cluster_num)));
subret = vvfat_read(s->bs, cluster2sector(s, cluster_num), cluster,
- s->sectors_per_cluster);
+ s->sectors_per_cluster);
if (subret) {
- fprintf(stderr, "Error fetching direntries\n");
+ error_report("Error fetching direntries");
fail:
- g_free(cluster);
+ g_free(cluster);
return 0;
}
for (i = 0; i < 0x10 * s->sectors_per_cluster; i++) {
int cluster_count = 0;
-DLOG(fprintf(stderr, "check direntry %d:\n", i); print_direntry(direntries +
i));
+ DLOG(error_report("check direntry %d:", i); print_direntry(direntries
+ i));
if (is_volume_label(direntries + i) || is_dot(direntries + i) ||
is_free(direntries + i))
- continue;
+ continue;
subret = parse_long_name(&lfn, direntries + i);
if (subret < 0) {
- fprintf(stderr, "Error in long name\n");
- goto fail;
+ fprintf(stderr, "Error in long name\n");
+ goto fail;
}
if (subret == 0 || is_free(direntries + i))
- continue;
+ continue;
if (fat_chksum(direntries+i) != lfn.checksum) {
subret = parse_short_name(s, &lfn, direntries + i);
if (subret < 0) {
- fprintf(stderr, "Error in short name (%d)\n", subret);
+ error_report("Error in short name (%d)\n", subret);
goto fail;
}
if (subret > 0 || !strcmp((char*)lfn.name, ".")
@@ -1908,39 +1910,38 @@ DLOG(fprintf(stderr, "check direntry %d:\n", i);
print_direntry(direntries + i))
lfn.checksum = 0x100; /* cannot use long name twice */
if (path_len + 1 + lfn.len >= PATH_MAX) {
- fprintf(stderr, "Name too long: %s/%s\n", path, lfn.name);
- goto fail;
+ fprintf(stderr, "Name too long: %s/%s\n", path, lfn.name);
+ goto fail;
}
- pstrcpy(path2 + path_len + 1, sizeof(path2) - path_len - 1,
- (char*)lfn.name);
+ pstrcpy(path2 + path_len + 1, sizeof(path2) - path_len - 1,
+ (char*)lfn.name);
if (is_directory(direntries + i)) {
- if (begin_of_direntry(direntries + i) == 0) {
- DLOG(fprintf(stderr, "invalid begin for directory: %s\n",
path2); print_direntry(direntries + i));
- goto fail;
- }
- cluster_count = check_directory_consistency(s,
- begin_of_direntry(direntries + i), path2);
- if (cluster_count == 0) {
- DLOG(fprintf(stderr, "problem in directory %s:\n", path2);
print_direntry(direntries + i));
- goto fail;
- }
- } else if (is_file(direntries + i)) {
- /* check file size with FAT */
- cluster_count = get_cluster_count_for_direntry(s, direntries +
i, path2);
- if (cluster_count !=
- (le32_to_cpu(direntries[i].size) + s->cluster_size
- - 1) / s->cluster_size) {
- DLOG(fprintf(stderr, "Cluster count mismatch\n"));
- goto fail;
- }
+ if (begin_of_direntry(direntries + i) == 0) {
+ DLOG(fprintf(stderr, "invalid begin for directory:
%s\n", path2); print_direntry(direntries + i));
+ goto fail;
+ }
+ cluster_count = check_directory_consistency(s,
+ begin_of_direntry(direntries + i), path2);
+ if (cluster_count == 0) {
+ DLOG(fprintf(stderr, "problem in directory %s:\n", path2);
print_direntry(direntries + i));
+ goto fail;
+ }
+ } else if (is_file(direntries + i)) {
+ /* check file size with FAT */
+ cluster_count = get_cluster_count_for_direntry(s, direntries + i,
path2);
+ if (cluster_count !=
+ (le32_to_cpu(direntries[i].size) + s->cluster_size - 1) /
s->cluster_size) {
+ DLOG(fprintf(stderr, "Cluster count mismatch\n"));
+ goto fail;
+ }
} else
abort(); /* cluster_count = 0; */
- ret += cluster_count;
+ ret += cluster_count;
}
- cluster_num = modified_fat_get(s, cluster_num);
+ cluster_num = modified_fat_get(s, cluster_num);
} while(!fat_eof(s, cluster_num));
g_free(cluster);
@@ -1972,77 +1973,77 @@ DLOG(checkpoint());
s->fat2 = g_malloc(size);
memcpy(s->fat2, s->fat.pointer, size);
}
- check = vvfat_read(s->bs,
- s->first_sectors_number, s->fat2, s->sectors_per_fat);
+ check = vvfat_read(s->bs, s->first_sectors_number,
+ s->fat2, s->sectors_per_fat);
if (check) {
- fprintf(stderr, "Could not copy fat\n");
- return 0;
+ error_report("Could not copy fat");
+ return 0;
}
- assert (s->used_clusters);
+ assert(s->used_clusters);
for (i = 0; i < sector2cluster(s, s->sector_count); i++)
- s->used_clusters[i] &= ~USED_ANY;
+ s->used_clusters[i] &= ~USED_ANY;
clear_commits(s);
/* mark every mapped file/directory as deleted.
* (check_directory_consistency() will unmark those still present). */
if (s->qcow)
- for (i = 0; i < s->mapping.next; i++) {
- mapping_t* mapping = array_get(&(s->mapping), i);
- if (mapping->first_mapping_index < 0)
- mapping->mode |= MODE_DELETED;
- }
+ for (i = 0; i < s->mapping.next; i++) {
+ mapping_t* mapping = array_get(&(s->mapping), i);
+ if (mapping->first_mapping_index < 0)
+ mapping->mode |= MODE_DELETED;
+ }
used_clusters_count = check_directory_consistency(s, 0, s->path);
if (used_clusters_count <= 0) {
- DLOG(fprintf(stderr, "problem in directory\n"));
- return 0;
+ DLOG(error_report("problem in directory"));
+ return 0;
}
check = s->last_cluster_of_root_directory;
for (i = check; i < sector2cluster(s, s->sector_count); i++) {
- if (modified_fat_get(s, i)) {
- if(!s->used_clusters[i]) {
- DLOG(fprintf(stderr, "FAT was modified (%d), but cluster is not
used?\n", i));
- return 0;
+ if (modified_fat_get(s, i)) {
+ if (!s->used_clusters[i]) {
+ DLOG(error_report("FAT was modified (%d), but cluster is not
used?", i));
+ return 0;
+ }
+ check++;
}
- check++;
- }
- if (s->used_clusters[i] == USED_ALLOCATED) {
- /* allocated, but not used... */
- DLOG(fprintf(stderr, "unused, modified cluster: %d\n", i));
- return 0;
- }
+ if (s->used_clusters[i] == USED_ALLOCATED) {
+ /* allocated, but not used... */
+ DLOG(fprintf(stderr, "unused, modified cluster: %d\n", i));
+ return 0;
+ }
}
if (check != used_clusters_count)
- return 0;
+ return 0;
return used_clusters_count;
}
static inline void adjust_mapping_indices(BDRVVVFATState* s,
- int offset, int adjust)
+ int offset, int adjust)
{
int i;
for (i = 0; i < s->mapping.next; i++) {
- mapping_t* mapping = array_get(&(s->mapping), i);
+ mapping_t* mapping = array_get(&(s->mapping), i);
#define ADJUST_MAPPING_INDEX(name) \
- if (mapping->name >= offset) \
- mapping->name += adjust
+ if (mapping->name >= offset) \
+ mapping->name += adjust
- ADJUST_MAPPING_INDEX(first_mapping_index);
- if (mapping->mode & MODE_DIRECTORY)
- ADJUST_MAPPING_INDEX(info.dir.parent_mapping_index);
+ ADJUST_MAPPING_INDEX(first_mapping_index);
+ if (mapping->mode & MODE_DIRECTORY)
+ ADJUST_MAPPING_INDEX(info.dir.parent_mapping_index);
}
}
/* insert or update mapping */
static mapping_t* insert_mapping(BDRVVVFATState* s,
- uint32_t begin, uint32_t end)
+ uint32_t begin, uint32_t end)
{
/*
* - find mapping where mapping->begin >= begin,
@@ -2057,27 +2058,27 @@ static mapping_t* insert_mapping(BDRVVVFATState* s,
if (index < s->mapping.next && (mapping = array_get(&(s->mapping), index))
&& mapping->begin < begin) {
- mapping->end = begin;
- index++;
- mapping = array_get(&(s->mapping), index);
+ mapping->end = begin;
+ index++;
+ mapping = array_get(&(s->mapping), index);
}
if (index >= s->mapping.next || mapping->begin > begin) {
- mapping = array_insert(&(s->mapping), index, 1);
- mapping->path = NULL;
- adjust_mapping_indices(s, index, +1);
+ mapping = array_insert(&(s->mapping), index, 1);
+ mapping->path = NULL;
+ adjust_mapping_indices(s, index, +1);
}
mapping->begin = begin;
mapping->end = end;
-DLOG(mapping_t* next_mapping;
-assert(index + 1 >= s->mapping.next ||
-((next_mapping = array_get(&(s->mapping), index + 1)) &&
- next_mapping->begin >= end)));
+ DLOG(mapping_t* next_mapping;
+ assert(index + 1 >= s->mapping.next ||
+ ((next_mapping = array_get(&(s->mapping), index + 1)) &&
+ next_mapping->begin >= end)));
if (s->current_mapping && first_mapping != (mapping_t*)s->mapping.pointer)
- s->current_mapping = array_get(&(s->mapping),
- s->current_mapping - first_mapping);
+ s->current_mapping = array_get(&(s->mapping),
+ s->current_mapping - first_mapping);
return mapping;
}
@@ -2099,8 +2100,8 @@ static int remove_mapping(BDRVVVFATState* s, int
mapping_index)
adjust_mapping_indices(s, mapping_index, -1);
if (s->current_mapping && first_mapping != (mapping_t*)s->mapping.pointer)
- s->current_mapping = array_get(&(s->mapping),
- s->current_mapping - first_mapping);
+ s->current_mapping = array_get(&(s->mapping),
+ s->current_mapping - first_mapping);
return 0;
}
@@ -2109,12 +2110,12 @@ static void adjust_dirindices(BDRVVVFATState* s, int
offset, int adjust)
{
int i;
for (i = 0; i < s->mapping.next; i++) {
- mapping_t* mapping = array_get(&(s->mapping), i);
- if (mapping->dir_index >= offset)
- mapping->dir_index += adjust;
- if ((mapping->mode & MODE_DIRECTORY) &&
- mapping->info.dir.first_dir_index >= offset)
- mapping->info.dir.first_dir_index += adjust;
+ mapping_t* mapping = array_get(&(s->mapping), i);
+ if (mapping->dir_index >= offset)
+ mapping->dir_index += adjust;
+ if ((mapping->mode & MODE_DIRECTORY) &&
+ mapping->info.dir.first_dir_index >= offset)
+ mapping->info.dir.first_dir_index += adjust;
}
}
@@ -2127,7 +2128,7 @@ static direntry_t* insert_direntries(BDRVVVFATState* s,
*/
direntry_t* result = array_insert(&(s->directory), dir_index, count);
if (result == NULL)
- return NULL;
+ return NULL;
adjust_dirindices(s, dir_index, count);
return result;
}
@@ -2136,7 +2137,7 @@ static int remove_direntries(BDRVVVFATState* s, int
dir_index, int count)
{
int ret = array_remove_slice(&(s->directory), dir_index, count);
if (ret)
- return ret;
+ return ret;
adjust_dirindices(s, dir_index, -count);
return 0;
}
@@ -2148,7 +2149,7 @@ static int remove_direntries(BDRVVVFATState* s, int
dir_index, int count)
* adjusted)
*/
static int commit_mappings(BDRVVVFATState* s,
- uint32_t first_cluster, int dir_index)
+ uint32_t first_cluster, int dir_index)
{
mapping_t* mapping = find_mapping_for_cluster(s, first_cluster);
direntry_t* direntry = array_get(&(s->directory), dir_index);
@@ -2160,72 +2161,71 @@ static int commit_mappings(BDRVVVFATState* s,
assert(mapping->begin == first_cluster);
mapping->first_mapping_index = -1;
mapping->dir_index = dir_index;
- mapping->mode = (dir_index <= 0 || is_directory(direntry)) ?
- MODE_DIRECTORY : MODE_NORMAL;
+ mapping->mode = (dir_index <= 0 || is_directory(direntry)) ?
MODE_DIRECTORY : MODE_NORMAL;
while (!fat_eof(s, cluster)) {
- uint32_t c, c1;
-
- for (c = cluster, c1 = modified_fat_get(s, c); c + 1 == c1;
- c = c1, c1 = modified_fat_get(s, c1));
-
- c++;
- if (c > mapping->end) {
- int index = array_index(&(s->mapping), mapping);
- int i, max_i = s->mapping.next - index;
- for (i = 1; i < max_i && mapping[i].begin < c; i++);
- while (--i > 0)
- remove_mapping(s, index + 1);
- }
- assert(mapping == array_get(&(s->mapping), s->mapping.next - 1)
- || mapping[1].begin >= c);
- mapping->end = c;
-
- if (!fat_eof(s, c1)) {
- int i = find_mapping_for_cluster_aux(s, c1, 0, s->mapping.next);
- mapping_t* next_mapping = i >= s->mapping.next ? NULL :
- array_get(&(s->mapping), i);
-
- if (next_mapping == NULL || next_mapping->begin > c1) {
- int i1 = array_index(&(s->mapping), mapping);
-
- next_mapping = insert_mapping(s, c1, c1+1);
-
- if (c1 < c)
- i1++;
- mapping = array_get(&(s->mapping), i1);
- }
-
- next_mapping->dir_index = mapping->dir_index;
- next_mapping->first_mapping_index =
- mapping->first_mapping_index < 0 ?
- array_index(&(s->mapping), mapping) :
- mapping->first_mapping_index;
- next_mapping->path = mapping->path;
- next_mapping->mode = mapping->mode;
- next_mapping->read_only = mapping->read_only;
- if (mapping->mode & MODE_DIRECTORY) {
- next_mapping->info.dir.parent_mapping_index =
- mapping->info.dir.parent_mapping_index;
- next_mapping->info.dir.first_dir_index =
- mapping->info.dir.first_dir_index +
- 0x10 * s->sectors_per_cluster *
- (mapping->end - mapping->begin);
- } else
- next_mapping->info.file.offset = mapping->info.file.offset +
- mapping->end - mapping->begin;
-
- mapping = next_mapping;
- }
+ uint32_t c, c1;
+
+ for (c = cluster, c1 = modified_fat_get(s, c); c + 1 == c1;
+ c = c1, c1 = modified_fat_get(s, c1));
+
+ c++;
+ if (c > mapping->end) {
+ int index = array_index(&(s->mapping), mapping);
+ int i, max_i = s->mapping.next - index;
+ for (i = 1; i < max_i && mapping[i].begin < c; i++);
+ while (--i > 0)
+ remove_mapping(s, index + 1);
+ }
+ assert(mapping == array_get(&(s->mapping), s->mapping.next - 1)
+ || mapping[1].begin >= c);
+ mapping->end = c;
+
+ if (!fat_eof(s, c1)) {
+ int i = find_mapping_for_cluster_aux(s, c1, 0, s->mapping.next);
+ mapping_t* next_mapping = i >= s->mapping.next ? NULL :
+ array_get(&(s->mapping), i);
+
+ if (next_mapping == NULL || next_mapping->begin > c1) {
+ int i1 = array_index(&(s->mapping), mapping);
+
+ next_mapping = insert_mapping(s, c1, c1+1);
+
+ if (c1 < c)
+ i1++;
+ mapping = array_get(&(s->mapping), i1);
+ }
+
+ next_mapping->dir_index = mapping->dir_index;
+ next_mapping->first_mapping_index =
+ mapping->first_mapping_index < 0 ?
+ array_index(&(s->mapping), mapping) :
+ mapping->first_mapping_index;
+ next_mapping->path = mapping->path;
+ next_mapping->mode = mapping->mode;
+ next_mapping->read_only = mapping->read_only;
+ if (mapping->mode & MODE_DIRECTORY) {
+ next_mapping->info.dir.parent_mapping_index =
+ mapping->info.dir.parent_mapping_index;
+ next_mapping->info.dir.first_dir_index =
+ mapping->info.dir.first_dir_index +
+ 0x10 * s->sectors_per_cluster *
+ (mapping->end - mapping->begin);
+ } else
+ next_mapping->info.file.offset = mapping->info.file.offset +
+ mapping->end - mapping->begin;
+
+ mapping = next_mapping;
+ }
- cluster = c1;
+ cluster = c1;
}
return 0;
}
static int commit_direntries(BDRVVVFATState* s,
- int dir_index, int parent_mapping_index)
+ int dir_index, int parent_mapping_index)
{
direntry_t* direntry = array_get(&(s->directory), dir_index);
uint32_t first_cluster = dir_index == 0 ? 0 : begin_of_direntry(direntry);
@@ -2238,7 +2238,7 @@ static int commit_direntries(BDRVVVFATState* s,
int ret, i;
uint32_t c;
-DLOG(fprintf(stderr, "commit_direntries for %s, parent_mapping_index %d\n",
mapping->path, parent_mapping_index));
+ DLOG(error_report("commit_direntries for %s, parent_mapping_index %d",
mapping->path, parent_mapping_index));
assert(direntry);
assert(mapping);
@@ -2250,53 +2250,51 @@ DLOG(fprintf(stderr, "commit_direntries for %s,
parent_mapping_index %d\n", mapp
mapping->info.dir.parent_mapping_index = parent_mapping_index;
if (first_cluster == 0) {
- old_cluster_count = new_cluster_count =
- s->last_cluster_of_root_directory;
+ old_cluster_count = new_cluster_count =
+ s->last_cluster_of_root_directory;
} else {
- for (old_cluster_count = 0, c = first_cluster; !fat_eof(s, c);
- c = fat_get(s, c))
- old_cluster_count++;
+ for (old_cluster_count = 0, c = first_cluster; !fat_eof(s, c); c =
fat_get(s, c))
+ old_cluster_count++;
- for (new_cluster_count = 0, c = first_cluster; !fat_eof(s, c);
- c = modified_fat_get(s, c))
- new_cluster_count++;
+ for (new_cluster_count = 0, c = first_cluster; !fat_eof(s, c);
+ c = modified_fat_get(s, c))
+ new_cluster_count++;
}
if (new_cluster_count > old_cluster_count) {
- if (insert_direntries(s,
- current_dir_index + factor * old_cluster_count,
- factor * (new_cluster_count - old_cluster_count)) == NULL)
- return -1;
- } else if (new_cluster_count < old_cluster_count)
- remove_direntries(s,
- current_dir_index + factor * new_cluster_count,
- factor * (old_cluster_count - new_cluster_count));
+ if (insert_direntries(s,
+ current_dir_index + factor * old_cluster_count,
+ factor * (new_cluster_count - old_cluster_count)) == NULL)
+ return -1;
+ } else
+ if (new_cluster_count < old_cluster_count)
+ remove_direntries(s, current_dir_index + factor * new_cluster_count,
+ factor * (old_cluster_count - new_cluster_count));
for (c = first_cluster; !fat_eof(s, c); c = modified_fat_get(s, c)) {
- void* direntry = array_get(&(s->directory), current_dir_index);
- int ret = vvfat_read(s->bs, cluster2sector(s, c), direntry,
- s->sectors_per_cluster);
- if (ret)
- return ret;
- assert(!strncmp(s->directory.pointer, "QEMU", 4));
- current_dir_index += factor;
+ void* direntry = array_get(&(s->directory), current_dir_index);
+ int ret = vvfat_read(s->bs, cluster2sector(s, c), direntry,
s->sectors_per_cluster);
+ if (ret)
+ return ret;
+ assert(!strncmp(s->directory.pointer, "QEMU", 4));
+ current_dir_index += factor;
}
ret = commit_mappings(s, first_cluster, dir_index);
if (ret)
- return ret;
+ return ret;
/* recurse */
for (i = 0; i < factor * new_cluster_count; i++) {
- direntry = array_get(&(s->directory), first_dir_index + i);
- if (is_directory(direntry) && !is_dot(direntry)) {
- mapping = find_mapping_for_cluster(s, first_cluster);
- assert(mapping->mode & MODE_DIRECTORY);
- ret = commit_direntries(s, first_dir_index + i,
- array_index(&(s->mapping), mapping));
- if (ret)
- return ret;
- }
+ direntry = array_get(&(s->directory), first_dir_index + i);
+ if (is_directory(direntry) && !is_dot(direntry)) {
+ mapping = find_mapping_for_cluster(s, first_cluster);
+ assert(mapping->mode & MODE_DIRECTORY);
+ ret = commit_direntries(s, first_dir_index + i,
+ array_index(&(s->mapping), mapping));
+ if (ret)
+ return ret;
+ }
}
return 0;
@@ -2305,7 +2303,7 @@ DLOG(fprintf(stderr, "commit_direntries for %s,
parent_mapping_index %d\n", mapp
/* commit one file (adjust contents, adjust mapping),
return first_mapping_index */
static int commit_one_file(BDRVVVFATState* s,
- int dir_index, uint32_t offset)
+ int dir_index, uint32_t offset)
{
direntry_t* direntry = array_get(&(s->directory), dir_index);
uint32_t c = begin_of_direntry(direntry);
@@ -2320,14 +2318,14 @@ static int commit_one_file(BDRVVVFATState* s,
assert((offset % s->cluster_size) == 0);
for (i = s->cluster_size; i < offset; i += s->cluster_size)
- c = modified_fat_get(s, c);
+ c = modified_fat_get(s, c);
fd = qemu_open(mapping->path, O_RDWR | O_CREAT | O_BINARY, 0666);
if (fd < 0) {
- fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path,
- strerror(errno), errno);
+ error_report("Could not open %s... (%s, %d)", mapping->path,
+ strerror(errno), errno);
g_free(cluster);
- return fd;
+ return fd;
}
if (offset > 0) {
if (lseek(fd, offset, SEEK_SET) != offset) {
@@ -2338,18 +2336,18 @@ static int commit_one_file(BDRVVVFATState* s,
}
while (offset < size) {
- uint32_t c1;
- int rest_size = (size - offset > s->cluster_size ?
- s->cluster_size : size - offset);
- int ret;
+ uint32_t c1;
+ int rest_size = (size - offset > s->cluster_size ?
+ s->cluster_size : size - offset);
+ int ret;
- c1 = modified_fat_get(s, c);
+ c1 = modified_fat_get(s, c);
- assert((size - offset == 0 && fat_eof(s, c)) ||
- (size > offset && c >=2 && !fat_eof(s, c)));
+ assert((size - offset == 0 && fat_eof(s, c)) ||
+ (size > offset && c >=2 && !fat_eof(s, c)));
- ret = vvfat_read(s->bs, cluster2sector(s, c),
- (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);
+ ret = vvfat_read(s->bs, cluster2sector(s, c),
+ (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);
if (ret < 0) {
qemu_close(fd);
@@ -2363,8 +2361,8 @@ static int commit_one_file(BDRVVVFATState* s,
return -2;
}
- offset += rest_size;
- c = c1;
+ offset += rest_size;
+ c = c1;
}
if (ftruncate(fd, size)) {
@@ -2385,18 +2383,19 @@ static void check1(BDRVVVFATState* s)
{
int i;
for (i = 0; i < s->mapping.next; i++) {
- mapping_t* mapping = array_get(&(s->mapping), i);
- if (mapping->mode & MODE_DELETED) {
- fprintf(stderr, "deleted\n");
- continue;
- }
- assert(mapping->dir_index < s->directory.next);
- direntry_t* direntry = array_get(&(s->directory), mapping->dir_index);
- assert(mapping->begin == begin_of_direntry(direntry) ||
mapping->first_mapping_index >= 0);
- if (mapping->mode & MODE_DIRECTORY) {
- assert(mapping->info.dir.first_dir_index + 0x10 *
s->sectors_per_cluster * (mapping->end - mapping->begin) <= s->directory.next);
- assert((mapping->info.dir.first_dir_index % (0x10 *
s->sectors_per_cluster)) == 0);
- }
+ mapping_t* mapping = array_get(&(s->mapping), i);
+ if (mapping->mode & MODE_DELETED) {
+ error_report("deleted");
+ continue;
+ }
+ assert(mapping->dir_index < s->directory.next);
+ direntry_t* direntry = array_get(&(s->directory), mapping->dir_index);
+ assert(mapping->begin == begin_of_direntry(direntry) ||
mapping->first_mapping_index >= 0);
+ if (mapping->mode & MODE_DIRECTORY) {
+ assert(mapping->info.dir.first_dir_index + 0x10 *
s->sectors_per_cluster *
+ (mapping->end - mapping->begin) <= s->directory.next);
+ assert((mapping->info.dir.first_dir_index % (0x10 *
s->sectors_per_cluster)) == 0);
+ }
}
}
@@ -2407,43 +2406,44 @@ static void check2(BDRVVVFATState* s)
int first_mapping = -1;
for (i = 0; i < s->directory.next; i++) {
- direntry_t* direntry = array_get(&(s->directory), i);
+ direntry_t* direntry = array_get(&(s->directory), i);
- if (is_short_name(direntry) && begin_of_direntry(direntry)) {
- mapping_t* mapping = find_mapping_for_cluster(s,
begin_of_direntry(direntry));
- assert(mapping);
- assert(mapping->dir_index == i || is_dot(direntry));
- assert(mapping->begin == begin_of_direntry(direntry) ||
is_dot(direntry));
- }
-
- if ((i % (0x10 * s->sectors_per_cluster)) == 0) {
- /* cluster start */
- int j, count = 0;
+ if (is_short_name(direntry) && begin_of_direntry(direntry)) {
+ mapping_t* mapping = find_mapping_for_cluster(s,
begin_of_direntry(direntry));
+ assert(mapping);
+ assert(mapping->dir_index == i || is_dot(direntry));
+ assert(mapping->begin == begin_of_direntry(direntry) ||
is_dot(direntry));
+ }
- for (j = 0; j < s->mapping.next; j++) {
- mapping_t* mapping = array_get(&(s->mapping), j);
- if (mapping->mode & MODE_DELETED)
- continue;
- if (mapping->mode & MODE_DIRECTORY) {
- if (mapping->info.dir.first_dir_index <= i &&
mapping->info.dir.first_dir_index + 0x10 * s->sectors_per_cluster > i) {
- assert(++count == 1);
- if (mapping->first_mapping_index == -1)
- first_mapping = array_index(&(s->mapping), mapping);
- else
- assert(first_mapping ==
mapping->first_mapping_index);
- if (mapping->info.dir.parent_mapping_index < 0)
- assert(j == 0);
- else {
- mapping_t* parent = array_get(&(s->mapping),
mapping->info.dir.parent_mapping_index);
- assert(parent->mode & MODE_DIRECTORY);
- assert(parent->info.dir.first_dir_index <
mapping->info.dir.first_dir_index);
- }
- }
- }
- }
- if (count == 0)
- first_mapping = -1;
- }
+ if ((i % (0x10 * s->sectors_per_cluster)) == 0) {
+ /* cluster start */
+ int j, count = 0;
+
+ for (j = 0; j < s->mapping.next; j++) {
+ mapping_t* mapping = array_get(&(s->mapping), j);
+ if (mapping->mode & MODE_DELETED)
+ continue;
+ if (mapping->mode & MODE_DIRECTORY) {
+ if (mapping->info.dir.first_dir_index <= i &&
mapping->info.dir.first_dir_index +
+ 0x10 * s->sectors_per_cluster > i) {
+ assert(++count == 1);
+ if (mapping->first_mapping_index == -1)
+ first_mapping = array_index(&(s->mapping),
mapping);
+ else
+ assert(first_mapping ==
mapping->first_mapping_index);
+ if (mapping->info.dir.parent_mapping_index < 0)
+ assert(j == 0);
+ else {
+ mapping_t* parent = array_get(&(s->mapping),
mapping->info.dir.parent_mapping_index);
+ assert(parent->mode & MODE_DIRECTORY);
+ assert(parent->info.dir.first_dir_index <
mapping->info.dir.first_dir_index);
+ }
+ }
+ }
+ }
+ if (count == 0)
+ first_mapping = -1;
+ }
}
}
#endif
@@ -2455,8 +2455,8 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s)
#ifdef DEBUG
fprintf(stderr, "handle_renames\n");
for (i = 0; i < s->commits.next; i++) {
- commit_t* commit = array_get(&(s->commits), i);
- fprintf(stderr, "%d, %s (%d, %d)\n", i, commit->path ? commit->path :
"(null)", commit->param.rename.cluster, commit->action);
+ commit_t* commit = array_get(&(s->commits), i);
+ fprintf(stderr, "%d, %s (%d, %d)\n", i, commit->path ? commit->path :
"(null)", commit->param.rename.cluster, commit->action);
}
#endif
@@ -2688,7 +2688,7 @@ static int handle_deletes(BDRVVVFATState* s)
return -4;
deleted++;
}
- DLOG(fprintf(stderr, "DELETE (%d)\n", i);
print_mapping(mapping); print_direntry(entry));
+ DLOG(error_report("DELETE (%d)", i); print_mapping(mapping);
print_direntry(entry));
remove_mapping(s, i);
}
}
@@ -2717,7 +2717,7 @@ static int do_commit(BDRVVVFATState* s)
ret = handle_renames_and_mkdirs(s);
if (ret) {
- fprintf(stderr, "Error handling renames (%d)\n", ret);
+ error_report("Error handling renames (%d)", ret);
abort();
return ret;
}
@@ -2728,23 +2728,23 @@ static int do_commit(BDRVVVFATState* s)
/* recurse direntries from root (using bs->bdrv_read) */
ret = commit_direntries(s, 0, -1);
if (ret) {
- fprintf(stderr, "Fatal: error while committing (%d)\n", ret);
- abort();
- return ret;
+ error_report("Fatal: error while committing (%d)", ret);
+ abort();
+ return ret;
}
ret = handle_commits(s);
if (ret) {
- fprintf(stderr, "Error handling commits (%d)\n", ret);
+ error_report("Error handling commits (%d)", ret);
abort();
- return ret;
+ return ret;
}
ret = handle_deletes(s);
if (ret) {
- fprintf(stderr, "Error deleting\n");
+ error_report("Error deleting");
abort();
- return ret;
+ return ret;
}
if (s->qcow->drv->bdrv_make_empty) {
@@ -2753,16 +2753,16 @@ static int do_commit(BDRVVVFATState* s)
memset(s->used_clusters, 0, sector2cluster(s, s->sector_count));
-DLOG(checkpoint());
+ DLOG(checkpoint());
return 0;
}
static int try_commit(BDRVVVFATState* s)
{
vvfat_close_current_file(s);
-DLOG(checkpoint());
+ DLOG(checkpoint());
if(!is_consistent(s))
- return -1;
+ return -1;
return do_commit(s);
}
@@ -2788,78 +2788,77 @@ DLOG(checkpoint());
*/
if (sector_num < s->first_sectors_number)
- return -1;
+ return -1;
for (i = sector2cluster(s, sector_num);
- i <= sector2cluster(s, sector_num + nb_sectors - 1);) {
- mapping_t* mapping = find_mapping_for_cluster(s, i);
- if (mapping) {
- if (mapping->read_only) {
- fprintf(stderr, "Tried to write to write-protected file %s\n",
- mapping->path);
- return -1;
- }
-
- if (mapping->mode & MODE_DIRECTORY) {
- int begin = cluster2sector(s, i);
- int end = begin + s->sectors_per_cluster, k;
- int dir_index;
- const direntry_t* direntries;
- long_file_name lfn;
-
- lfn_init(&lfn);
-
- if (begin < sector_num)
- begin = sector_num;
- if (end > sector_num + nb_sectors)
- end = sector_num + nb_sectors;
- dir_index = mapping->dir_index +
- 0x10 * (begin - mapping->begin * s->sectors_per_cluster);
- direntries = (direntry_t*)(buf + 0x200 * (begin - sector_num));
-
- for (k = 0; k < (end - begin) * 0x10; k++) {
- /* do not allow non-ASCII filenames */
- if (parse_long_name(&lfn, direntries + k) < 0) {
- fprintf(stderr, "Warning: non-ASCII filename\n");
- return -1;
- }
- /* no access to the direntry of a read-only file */
- else if (is_short_name(direntries+k) &&
- (direntries[k].attributes & 1)) {
- if (memcmp(direntries + k,
- array_get(&(s->directory), dir_index + k),
- sizeof(direntry_t))) {
- fprintf(stderr, "Warning: tried to write to
write-protected file\n");
- return -1;
- }
- }
- }
- }
- i = mapping->end;
- } else
- i++;
+ i <= sector2cluster(s, sector_num + nb_sectors - 1);) {
+ mapping_t* mapping = find_mapping_for_cluster(s, i);
+ if (mapping) {
+ if (mapping->read_only) {
+ error_report("Tried to write to write-protected file %s",
+ mapping->path);
+ return -1;
+ }
+
+ if (mapping->mode & MODE_DIRECTORY) {
+ int begin = cluster2sector(s, i);
+ int end = begin + s->sectors_per_cluster, k;
+ int dir_index;
+ const direntry_t* direntries;
+ long_file_name lfn;
+
+ lfn_init(&lfn);
+
+ if (begin < sector_num)
+ begin = sector_num;
+ if (end > sector_num + nb_sectors)
+ end = sector_num + nb_sectors;
+ dir_index = mapping->dir_index + 0x10 *
+ (begin - mapping->begin * s->sectors_per_cluster);
+ direntries = (direntry_t*)(buf + 0x200 * (begin - sector_num));
+
+ for (k = 0; k < (end - begin) * 0x10; k++) {
+ /* do not allow non-ASCII filenames */
+ if (parse_long_name(&lfn, direntries + k) < 0) {
+ error_report("Warning: non-ASCII filename");
+ return -1;
+ }
+ /* no access to the direntry of a read-only file */
+ else if (is_short_name(direntries+k) &&
+ (direntries[k].attributes & 1)) {
+ if (memcmp(direntries + k, array_get(&(s->directory),
dir_index + k),
+ sizeof(direntry_t))) {
+ error_report("Warning: tried to write to
write-protected file");
+ return -1;
+ }
+ }
+ }
+ }
+ i = mapping->end;
+ } else
+ i++;
}
/*
* Use qcow backend. Commit later.
*/
-DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num,
nb_sectors));
+ DLOG(error_report("Write to qcow backend: %d + %d", (int)sector_num,
nb_sectors));
ret = bdrv_write(s->qcow, sector_num, buf, nb_sectors);
if (ret < 0) {
- fprintf(stderr, "Error writing to qcow backend\n");
- return ret;
+ error_report("Error writing to qcow backend");
+ return ret;
}
for (i = sector2cluster(s, sector_num);
- i <= sector2cluster(s, sector_num + nb_sectors - 1); i++)
- if (i >= 0)
- s->used_clusters[i] |= USED_ALLOCATED;
+ i <= sector2cluster(s, sector_num + nb_sectors - 1); i++)
+ if (i >= 0)
+ s->used_clusters[i] |= USED_ALLOCATED;
-DLOG(checkpoint());
+ DLOG(checkpoint());
/* TODO: add timeout */
try_commit(s);
-DLOG(checkpoint());
+ DLOG(checkpoint());
return 0;
}
@@ -2880,14 +2879,14 @@ static int coroutine_fn
vvfat_co_is_allocated(BlockDriverState *bs,
BDRVVVFATState* s = bs->opaque;
*n = s->sector_count - sector_num;
if (*n > nb_sectors)
- *n = nb_sectors;
+ *n = nb_sectors;
else if (*n < 0)
- return 0;
+ return 0;
return 1;
}
static int write_target_commit(BlockDriverState *bs, int64_t sector_num,
- const uint8_t* buffer, int nb_sectors) {
+ const uint8_t* buffer, int nb_sectors) {
BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque);
return try_commit(s);
}
diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c
index 2abc713..6b52e08 100644
--- a/bsd-user/bsdload.c
+++ b/bsd-user/bsdload.c
@@ -183,7 +183,7 @@ int loader_exec(const char * filename, char ** argv, char
** envp,
&& bprm.buf[3] == 'F') {
retval = load_elf_binary(&bprm,regs,infop);
} else {
- fprintf(stderr, "Unknown binary format\n");
+ error_report("Unknown binary format");
return -1;
}
}
diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 93fd9e4..95652b1 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -628,7 +628,7 @@ static abi_ulong copy_elf_strings(int argc,char ** argv,
void **page,
while (argc-- > 0) {
tmp = argv[argc];
if (!tmp) {
- fprintf(stderr, "VFS: argc is wrong");
+ error_report("VFS: argc is wrong");
exit(-1);
}
tmp1 = tmp;
diff --git a/bsd-user/main.c b/bsd-user/main.c
index f9246aa..a9cca12 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -33,6 +33,7 @@
#include "tcg.h"
#include "qemu/timer.h"
#include "qemu/envlist.h"
+#include "qemu/error-report.h"
int singlestep;
#if defined(CONFIG_USE_GUEST_BASE)
@@ -752,7 +753,7 @@ int main(int argc, char **argv)
module_call_init(MODULE_INIT_QOM);
if ((envlist = envlist_create()) == NULL) {
- (void) fprintf(stderr, "Unable to allocate envlist\n");
+ (void) error_report("Unable to allocate envlist");
exit(1);
}
@@ -794,7 +795,7 @@ int main(int argc, char **argv)
} else if (!strcmp(r, "ignore-environment")) {
envlist_free(envlist);
if ((envlist = envlist_create()) == NULL) {
- (void) fprintf(stderr, "Unable to allocate envlist\n");
+ error_report("Unable to allocate envlist");
exit(1);
}
} else if (!strcmp(r, "U")) {
@@ -816,7 +817,7 @@ int main(int argc, char **argv)
qemu_host_page_size = atoi(argv[optind++]);
if (qemu_host_page_size == 0 ||
(qemu_host_page_size & (qemu_host_page_size - 1)) != 0) {
- fprintf(stderr, "page size must be a power of two\n");
+ error_report("page size must be a power of two");
exit(1);
}
} else if (!strcmp(r, "g")) {
@@ -910,7 +911,7 @@ int main(int argc, char **argv)
qemu_host_page_size */
env = cpu_init(cpu_model);
if (!env) {
- fprintf(stderr, "Unable to find CPU definition\n");
+ error_report("Unable to find CPU definition");
exit(1);
}
cpu = ENV_GET_CPU(env);
@@ -1014,7 +1015,7 @@ int main(int argc, char **argv)
#ifndef TARGET_ABI32
/* enable 64 bit mode if possible */
if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM)) {
- fprintf(stderr, "The selected x86 CPU does not support 64 bit mode\n");
+ error_report("The selected x86 CPU does not support 64 bit mode");
exit(1);
}
env->cr[4] |= CR4_PAE_MASK;
--
1.7.11.7
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [PATCH] error reporting: Update arch_init and block files to use error_report() instead of fprintf(stderr),
Michal Novotny <=