From patchwork Tue Nov 4 02:50:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suriyan Ramasami X-Patchwork-Id: 406411 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id C0FCD14012B for ; Tue, 4 Nov 2014 15:08:36 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0B54C4B998; Tue, 4 Nov 2014 03:51:11 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id z+R58pa80J8j; Tue, 4 Nov 2014 03:51:10 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6E1FA4B9AD; Tue, 4 Nov 2014 03:51:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F40724B981 for ; Tue, 4 Nov 2014 03:51:05 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lH1dSXp6TRFl for ; Tue, 4 Nov 2014 03:51:05 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f41.google.com (mail-pa0-f41.google.com [209.85.220.41]) by theia.denx.de (Postfix) with ESMTPS id 51B4F4B955 for ; Tue, 4 Nov 2014 03:50:55 +0100 (CET) Received: by mail-pa0-f41.google.com with SMTP id rd3so13501871pab.28 for ; Mon, 03 Nov 2014 18:50:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cCAzKDdIgBp66S8wUuV7unFc4kNoy1TM2u2U1iISYLQ=; b=SQl7dQSsKRMOGMgKUS3YVQDlQia3MF2dfX+CbIiEhcn8SLdHfmU5MJEwvUfr83ZQ9D QisoYQqCiMHx9CK7l2U4y6ITRZl5V/aloJGIOWIG8ss1pqxcV/5xswAnPglus9Fz41qb 7saI7qPtZCgbqXvxmmmoQQYjSkEv8wHhEukMcw6O0jjXnITetWkARAzuHw7POzK/Yz7D m/GfIcDtlvp2I7sbD2X0MVDWJmBE2PkMwze0oz+aGXTB/ng7StJerO3/U1LE4wRVb8lw txj24QSHJnHgLzJTaY5NMoVx7Gu3Cjeye1npBf5DmfDELiieM1kx5tnTAvbRM52C27la zG1g== X-Received: by 10.68.201.130 with SMTP id ka2mr648978pbc.112.1415069446465; Mon, 03 Nov 2014 18:50:46 -0800 (PST) Received: from localhost.localdomain ([73.170.223.86]) by mx.google.com with ESMTPSA id al4sm18362124pbc.19.2014.11.03.18.50.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Nov 2014 18:50:45 -0800 (PST) From: Suriyan Ramasami To: Simon Glass Date: Mon, 3 Nov 2014 18:50:02 -0800 Message-Id: <1415069408-2978-7-git-send-email-suriyan.r@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1415069408-2978-1-git-send-email-suriyan.r@gmail.com> References: <1415069408-2978-1-git-send-email-suriyan.r@gmail.com> Cc: Jeroen Hofstee , Stephen Warren , Suriyan Ramasami , David Feng , Gabriel Huau , u-boot@lists.denx.de, Sonic Zhang , York Sun Subject: [U-Boot] [PATCH v6 6/6] sandbox: interface changes to accomodate files greater than 2GB X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Change the interface for the sandbox functions to take in an extra parameter of type "loff_t *" to return the size. The return values of these funtions now serve as an indicator of error conditions alone. Signed-off-by: Suriyan Ramasami --- Changes in v6: * Simon - Split this into a separate patch Changes in v5: None arch/sandbox/cpu/os.c | 13 +++++---- arch/sandbox/cpu/state.c | 8 +++--- common/board_f.c | 8 +++--- fs/sandbox/sandboxfs.c | 73 ++++++++++++++++++++++++++++++++---------------- include/os.h | 5 ++-- include/sandboxfs.h | 14 ++++++---- 6 files changed, 76 insertions(+), 45 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 1c4aa3f..31c9344 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -385,7 +385,7 @@ const char *os_dirent_get_typename(enum os_dirent_t type) return os_dirent_typename[OS_FILET_UNKNOWN]; } -ssize_t os_get_filesize(const char *fname) +int os_get_filesize(const char *fname, loff_t *size) { struct stat buf; int ret; @@ -393,7 +393,8 @@ ssize_t os_get_filesize(const char *fname) ret = stat(fname, &buf); if (ret) return ret; - return buf.st_size; + *size = buf.st_size; + return 0; } void os_putc(int ch) @@ -427,11 +428,11 @@ int os_read_ram_buf(const char *fname) { struct sandbox_state *state = state_get_current(); int fd, ret; - int size; + loff_t size; - size = os_get_filesize(fname); - if (size < 0) - return -ENOENT; + ret = os_get_filesize(fname, &size); + if (ret < 0) + return ret; if (size != state->ram_size) return -ENOSPC; fd = open(fname, O_RDONLY); diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c index 59adad6..ba73b7e 100644 --- a/arch/sandbox/cpu/state.c +++ b/arch/sandbox/cpu/state.c @@ -49,14 +49,14 @@ static int state_ensure_space(int extra_size) static int state_read_file(struct sandbox_state *state, const char *fname) { - int size; + loff_t size; int ret; int fd; - size = os_get_filesize(fname); - if (size < 0) { + ret = os_get_filesize(fname, &size); + if (ret < 0) { printf("Cannot find sandbox state file '%s'\n", fname); - return -ENOENT; + return ret; } state->state_fdt = os_malloc(size); if (!state->state_fdt) { diff --git a/common/board_f.c b/common/board_f.c index b5bebc9..844cc19 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -285,7 +285,7 @@ static int read_fdt_from_file(void) struct sandbox_state *state = state_get_current(); const char *fname = state->fdt_fname; void *blob; - ssize_t size; + loff_t size; int err; int fd; @@ -298,10 +298,10 @@ static int read_fdt_from_file(void) return -EINVAL; } - size = os_get_filesize(fname); - if (size < 0) { + err = os_get_filesize(fname, &size); + if (err < 0) { printf("Failed to file FDT file '%s'\n", fname); - return -ENOENT; + return err; } fd = os_open(fname, OS_O_RDONLY); if (fd < 0) { diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c index ba6402c..9ecd2f7 100644 --- a/fs/sandbox/sandboxfs.c +++ b/fs/sandbox/sandboxfs.c @@ -13,10 +13,10 @@ int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info) return 0; } -long sandbox_fs_read_at(const char *filename, unsigned long pos, - void *buffer, unsigned long maxsize) +int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer, + loff_t maxsize, loff_t *actread) { - ssize_t size; + loff_t size; int fd, ret; fd = os_open(filename, OS_O_RDONLY); @@ -27,16 +27,31 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos, os_close(fd); return ret; } - if (!maxsize) - maxsize = os_get_filesize(filename); + if (!maxsize) { + ret = os_get_filesize(filename, &size); + if (ret) { + os_close(fd); + return ret; + } + + maxsize = size; + } + size = os_read(fd, buffer, maxsize); os_close(fd); - return size; + if (size < 0) { + ret = -1; + } else { + ret = 0; + *actread = size; + } + + return ret; } -long sandbox_fs_write_at(const char *filename, unsigned long pos, - void *buffer, unsigned long towrite) +int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer, + loff_t towrite, loff_t *actwrite) { ssize_t size; int fd, ret; @@ -52,7 +67,14 @@ long sandbox_fs_write_at(const char *filename, unsigned long pos, size = os_write(fd, buffer, towrite); os_close(fd); - return size; + if (size == -1) { + ret = -1; + } else { + ret = 0; + *actwrite = size; + } + + return ret; } int sandbox_fs_ls(const char *dirname) @@ -74,43 +96,46 @@ int sandbox_fs_ls(const char *dirname) int sandbox_fs_exists(const char *filename) { - ssize_t sz; + loff_t sz; + int ret; - sz = os_get_filesize(filename); - return sz >= 0; + ret = os_get_filesize(filename, &sz); + return ret == 0; } -int sandbox_fs_size(const char *filename) +int sandbox_fs_size(const char *filename, loff_t *size) { - return os_get_filesize(filename); + return os_get_filesize(filename, size); } void sandbox_fs_close(void) { } -int fs_read_sandbox(const char *filename, void *buf, int offset, int len) +int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t len, + loff_t *actread) { - int len_read; + int ret; - len_read = sandbox_fs_read_at(filename, offset, buf, len); - if (len_read == -1) { + ret = sandbox_fs_read_at(filename, offset, buf, len, actread); + if (ret) { printf("** Unable to read file %s **\n", filename); return -1; } - return len_read; + return 0; } -int fs_write_sandbox(const char *filename, void *buf, int offset, int len) +int fs_write_sandbox(const char *filename, void *buf, loff_t offset, + loff_t len, loff_t *actwrite) { - int len_written; + int ret; - len_written = sandbox_fs_write_at(filename, offset, buf, len); - if (len_written == -1) { + ret = sandbox_fs_write_at(filename, offset, buf, len, actwrite); + if (ret == -1) { printf("** Unable to write file %s **\n", filename); return -1; } - return len_written; + return 0; } diff --git a/include/os.h b/include/os.h index 0230a7f..e3645e0 100644 --- a/include/os.h +++ b/include/os.h @@ -217,9 +217,10 @@ const char *os_dirent_get_typename(enum os_dirent_t type); * Get the size of a file * * @param fname Filename to check - * @return size of file, or -1 if an error ocurred + * @param size size of file is returned if no error + * @return 0 on success or -1 if an error ocurred */ -ssize_t os_get_filesize(const char *fname); +int os_get_filesize(const char *fname, loff_t *size); /** * Write a character to the controlling OS terminal diff --git a/include/sandboxfs.h b/include/sandboxfs.h index e7c3262..4c7745d 100644 --- a/include/sandboxfs.h +++ b/include/sandboxfs.h @@ -20,14 +20,18 @@ int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); -long sandbox_fs_read_at(const char *filename, unsigned long pos, - void *buffer, unsigned long maxsize); +int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer, + loff_t maxsize, loff_t *actread); +int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer, + loff_t maxsize, loff_t *actwrite); void sandbox_fs_close(void); int sandbox_fs_ls(const char *dirname); int sandbox_fs_exists(const char *filename); -int sandbox_fs_size(const char *filename); -int fs_read_sandbox(const char *filename, void *buf, int offset, int len); -int fs_write_sandbox(const char *filename, void *buf, int offset, int len); +int sandbox_fs_size(const char *filename, loff_t *size); +int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t len, + loff_t *actread); +int fs_write_sandbox(const char *filename, void *buf, loff_t offset, + loff_t len, loff_t *actwrite); #endif