From patchwork Tue Feb 26 23:03:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Schopp X-Patchwork-Id: 223426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DA4F02C0084 for ; Wed, 27 Feb 2013 10:06:49 +1100 (EST) Received: from localhost ([::1]:44165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UATbj-0001tz-P0 for incoming@patchwork.ozlabs.org; Tue, 26 Feb 2013 18:06:47 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41851) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UATbZ-0001qU-2y for qemu-devel@nongnu.org; Tue, 26 Feb 2013 18:06:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UATbV-0004F3-91 for qemu-devel@nongnu.org; Tue, 26 Feb 2013 18:06:36 -0500 Received: from e9.ny.us.ibm.com ([32.97.182.139]:54600) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UATbV-0004Eg-3k for qemu-devel@nongnu.org; Tue, 26 Feb 2013 18:06:33 -0500 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 26 Feb 2013 18:06:31 -0500 Received: from d01dlp02.pok.ibm.com (9.56.250.167) by e9.ny.us.ibm.com (192.168.1.109) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 26 Feb 2013 18:06:29 -0500 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id F1BFB6E801E for ; Tue, 26 Feb 2013 18:06:26 -0500 (EST) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r1QN6SPi306770 for ; Tue, 26 Feb 2013 18:06:28 -0500 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r1QN6SjG000796 for ; Tue, 26 Feb 2013 20:06:28 -0300 Received: from jschopp-w520 (jschopp-w520.austin.ibm.com [9.41.105.206]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r1QN6Shq000779; Tue, 26 Feb 2013 20:06:28 -0300 Received: by jschopp-w520 (Postfix, from userid 1000) id 65A28500147; Tue, 26 Feb 2013 17:06:27 -0600 (CST) Message-Id: <20130226230627.312573974@linux.vnet.ibm.com> User-Agent: quilt/0.60-1 Date: Tue, 26 Feb 2013 17:03:55 -0600 From: jschopp@linux.vnet.ibm.com To: qemu-devel@nongnu.org X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13022623-7182-0000-0000-00000589B57D X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.182.139 Cc: Stefan Berger Subject: [Qemu-devel] [PATCH 1/3] two new file wrappers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org These patches implement asn1 ber visitors for encoding and decoding data. References: <20130226230354.982917686@linux.vnet.ibm.com> Content-Disposition: inline; filename=qemu_file_bits.diff Signed-off-by: Stefan Berger Signed-off-by: Joel Schopp --- include/migration/qemu-file.h | 4 ++++ qemu-file.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) Index: b/qemu-file.c =================================================================== --- a/qemu-file.c +++ b/qemu-file.c @@ -367,7 +367,7 @@ static void qemu_file_set_error(QEMUFile /** Flushes QEMUFile buffer * */ -static int qemu_fflush(QEMUFile *f) +int qemu_fflush(QEMUFile *f) { int ret = 0; @@ -668,3 +668,34 @@ uint64_t qemu_get_be64(QEMUFile *f) v |= qemu_get_be32(f); return v; } + +int qemu_read_bytes(QEMUFile *f, uint8_t *buf, int size) +{ + if (qemu_file_get_error(f)) { + return -1; + } + return qemu_get_buffer(f, buf, size); +} + +int qemu_peek_bytes(QEMUFile *f, uint8_t *buf, int size, size_t offset) +{ + if (qemu_file_get_error(f)) { + return -1; + } + return qemu_peek_buffer(f, buf, size, offset); +} + +int qemu_write_bytes(QEMUFile *f, const uint8_t *buf, int size) +{ + if (qemu_file_get_error(f)) { + return -1; + } + + qemu_put_buffer(f, buf, size); + + if (qemu_file_get_error(f)) { + return -1; + } + + return size; +} Index: b/include/migration/qemu-file.h =================================================================== --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -79,11 +79,15 @@ QEMUFile *qemu_fdopen(int fd, const char QEMUFile *qemu_fopen_socket(int fd); QEMUFile *qemu_popen(FILE *popen_file, const char *mode); QEMUFile *qemu_popen_cmd(const char *command, const char *mode); +int qemu_fflush(QEMUFile *f); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); int64_t qemu_ftell(QEMUFile *f); void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); void qemu_put_byte(QEMUFile *f, int v); +int qemu_read_bytes(QEMUFile *f, uint8_t *buf, int size); +int qemu_peek_bytes(QEMUFile *f, uint8_t *buf, int size, size_t offset); +int qemu_write_bytes(QEMUFile *f, const uint8_t *buf, int size); static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v) {