From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X93s2-0000V2-If for qemu-devel@nongnu.org; Sun, 20 Jul 2014 23:02:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X93rn-00017U-5n for qemu-devel@nongnu.org; Sun, 20 Jul 2014 23:02:34 -0400 Received: from e23smtp05.au.ibm.com ([202.81.31.147]:48131) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X93rm-000160-Ge for qemu-devel@nongnu.org; Sun, 20 Jul 2014 23:02:19 -0400 Received: from /spool/local by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 21 Jul 2014 13:02:14 +1000 From: Alexey Kardashevskiy Date: Mon, 21 Jul 2014 13:02:03 +1000 Message-Id: <1405911724-4678-2-git-send-email-aik@ozlabs.ru> In-Reply-To: <1405911724-4678-1-git-send-email-aik@ozlabs.ru> References: <1405911724-4678-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH 1/2] loader: Add load_image_size() to replace load_image() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , qemu-ppc@nongnu.org, Alexander Graf From: Benjamin Herrenschmidt A subsequent patch to ppc/spapr needs to load the RTAS blob into qemu memory rather than target memory (so it can later be copied into the right spot at machine reset time). I would use load_image() but it is marked deprecated because it doesn't take a buffer size as argument, so let's add load_image_size() that does. Signed-off-by: Benjamin Herrenschmidt [aik: fixed errors from checkpatch.pl] Signed-off-by: Alexey Kardashevskiy --- hw/core/loader.c | 21 +++++++++++++++++++++ include/hw/loader.h | 1 + 2 files changed, 22 insertions(+) diff --git a/hw/core/loader.c b/hw/core/loader.c index 2bf6b8f..5e2b6cd 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -89,6 +89,27 @@ int load_image(const char *filename, uint8_t *addr) return size; } +/* return the size or -1 if error */ +ssize_t load_image_size(const char *filename, void *addr, size_t size) +{ + int fd; + ssize_t actsize; + + fd = open(filename, O_RDONLY | O_BINARY); + if (fd < 0) { + return -1; + } + + actsize = read(fd, addr, size); + if (actsize < 0) { + close(fd); + return -1; + } + close(fd); + + return actsize; +} + /* read()-like version */ ssize_t read_targphys(const char *name, int fd, hwaddr dst_addr, size_t nbytes) diff --git a/include/hw/loader.h b/include/hw/loader.h index 796cbf9..991f84a 100644 --- a/include/hw/loader.h +++ b/include/hw/loader.h @@ -13,6 +13,7 @@ */ int get_image_size(const char *filename); int load_image(const char *filename, uint8_t *addr); /* deprecated */ +ssize_t load_image_size(const char *filename, void *addr, size_t size); int load_image_targphys(const char *filename, hwaddr, uint64_t max_sz); -- 2.0.0