From patchwork Sat Apr 20 18:42:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 238168 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 E704D2C0158 for ; Sun, 21 Apr 2013 04:46:39 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6D0A64A56B; Sat, 20 Apr 2013 20:45:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 Nq5lq-qN6zmm; Sat, 20 Apr 2013 20:45:46 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 794B94A46F; Sat, 20 Apr 2013 20:44:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 39C834A3C9 for ; Sat, 20 Apr 2013 20:43:57 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 RwEkJZ4b+bQQ for ; Sat, 20 Apr 2013 20:43:56 +0200 (CEST) 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-qe0-f73.google.com (mail-qe0-f73.google.com [209.85.128.73]) by theia.denx.de (Postfix) with ESMTPS id 9BFF64A3F2 for ; Sat, 20 Apr 2013 20:43:19 +0200 (CEST) Received: by mail-qe0-f73.google.com with SMTP id 1so545419qee.4 for ; Sat, 20 Apr 2013 11:43:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=5fFRCpQ4omYOchW/8NbcSFO7XP2SEigZ94IwdZxtvPM=; b=ZoVcOUGfo2levT5uwI3NPs+1vw1Ud0ILECHGcwOKAml0dX3Q16E5D5sohcCsezN9oW fQb5SdgzBuNY4OvQsUKLkUI3gxwtZ3jHUv1lfin+7NW0Sy90p0T3hWxh79DA7pPJF8Xv 30OdC1zWvLqhF6frLuZqn5vK2EVLOkgO+v2XGaUnlcVusXGKixAvLaWvGbMKA0xSKmFV nw28mgg/hF7zk78PW1rH2p+6U9QWWpes6RXFMc8ktDXWihKdzIHt/POaZ2RlraFHE6cU hyRb9vjLRbp/Wwz6/uz2UqyKy9OvQ43PS6AKBwrm0Q2cvJhJ8OJm7EySH/2ZcejncISg fA/Q== X-Received: by 10.236.85.5 with SMTP id t5mr10448646yhe.33.1366483396469; Sat, 20 Apr 2013 11:43:16 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id u58si4434972yhe.2.2013.04.20.11.43.16 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Sat, 20 Apr 2013 11:43:16 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.83.1]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 2FF2D31C267; Sat, 20 Apr 2013 11:43:16 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 0ED941605A1; Sat, 20 Apr 2013 11:43:16 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 20 Apr 2013 11:42:51 -0700 Message-Id: <1366483372-16523-17-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1366483372-16523-1-git-send-email-sjg@chromium.org> References: <1366483372-16523-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQlSlONnd5y3bPpVBG7TGXlhl3y24XWDB2ODnIABm8473g4kudGUcfulmx1HBTbaWkOs9yYr62gih4o/O9rF+8NN8SkobLFPfmcdnvKlFLxI+ddcxYxwPpAKaRQBjB6Cjmnt8lna3F4MXlPteDUc2aHKe5Tjntg7p9CUNlFFpbXSr/9+rTchNFdhEglVhS+lfZHX4xGi Cc: Tom Rini , u-boot-review@google.com Subject: [U-Boot] [PATCH v3 16/17] sandbox: fs: Add support for saving files to host filesystem X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 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 This allows write of files from the host filesystem in sandbox. There is currently no concept of overwriting the file and removing its existing contents - all writing is done on top of what is there. This means that writing 10 bytes to the start of a 1KB file will only update those 10 bytes, not truncate the file to 10 byte slong. If the file does not exist it is created. Signed-off-by: Simon Glass --- Changes in v3: None Changes in v2: None common/cmd_sandbox.c | 18 ++++++++++++++---- fs/fs.c | 1 + fs/sandbox/sandboxfs.c | 33 +++++++++++++++++++++++++++++++++ include/sandboxfs.h | 1 + 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/common/cmd_sandbox.c b/common/cmd_sandbox.c index 206a486..a28a844 100644 --- a/common/cmd_sandbox.c +++ b/common/cmd_sandbox.c @@ -32,9 +32,16 @@ static int do_sandbox_ls(cmd_tbl_t *cmdtp, int flag, int argc, return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX); } +static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX, 16); +} + static cmd_tbl_t cmd_sandbox_sub[] = { - U_BOOT_CMD_MKENT(load, 3, 0, do_sandbox_load, "", ""), + U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""), U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""), + U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""), }; static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc, @@ -56,8 +63,11 @@ static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc, } U_BOOT_CMD( - sb, 6, 1, do_sandbox, + sb, 8, 1, do_sandbox, "Miscellaneous sandbox commands", - "load host [ ] - load a file from host\n" - "sb ls host - save a file to host" + "load host [ ] - " + "load a file from host\n" + "sb ls host - list files on host\n" + "sb save host [] - " + "save a file to host\n" ); diff --git a/fs/fs.c b/fs/fs.c index eee7e23..99e516a 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -93,6 +93,7 @@ static struct fstype_info fstypes[] = { .close = sandbox_fs_close, .ls = sandbox_fs_ls, .read = fs_read_sandbox, + .write = fs_write_sandbox, }, #endif { diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c index 02d26ff..89769e8 100644 --- a/fs/sandbox/sandboxfs.c +++ b/fs/sandbox/sandboxfs.c @@ -48,6 +48,26 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos, return size; } +long sandbox_fs_write_at(const char *filename, unsigned long pos, + void *buffer, unsigned long towrite) +{ + ssize_t size; + int fd, ret; + + fd = os_open(filename, OS_O_RDWR | OS_O_CREAT); + if (fd < 0) + return fd; + ret = os_lseek(fd, pos, OS_SEEK_SET); + if (ret == -1) { + os_close(fd); + return ret; + } + size = os_write(fd, buffer, towrite); + os_close(fd); + + return size; +} + int sandbox_fs_ls(const char *dirname) { struct os_dirent_node *head, *node; @@ -81,3 +101,16 @@ int fs_read_sandbox(const char *filename, void *buf, int offset, int len) return len_read; } + +int fs_write_sandbox(const char *filename, void *buf, int offset, int len) +{ + int len_written; + + len_written = sandbox_fs_write_at(filename, offset, buf, len); + if (len_written == -1) { + printf("** Unable to write file %s **\n", filename); + return -1; + } + + return len_written; +} diff --git a/include/sandboxfs.h b/include/sandboxfs.h index f5213ac..8ea8cb7 100644 --- a/include/sandboxfs.h +++ b/include/sandboxfs.h @@ -26,5 +26,6 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos, void sandbox_fs_close(void); int sandbox_fs_ls(const char *dirname); 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); #endif