X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=fs%2Fsandbox%2Fsandboxfs.c;h=5acfc03704a9b35d9f823637ffac86e06f051208;hb=6e2f1538959d79b54a0ceeed2f24643cf98ebaa4;hp=89769e8ce680cf5bac206c2dff83e131a6120577;hpb=cac423a730d3506154744485af1bbc1cd3a1e6a8;p=u-boot diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c index 89769e8ce6..5acfc03704 100644 --- a/fs/sandbox/sandboxfs.c +++ b/fs/sandbox/sandboxfs.c @@ -1,20 +1,7 @@ /* * Copyright (c) 2012, Google Inc. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -23,13 +10,17 @@ int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info) { - return 0; + /* + * Only accept a NULL block_dev_desc_t for the sandbox, which is when + * hostfs interface is used + */ + return rbdd != NULL; } -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); @@ -40,16 +31,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; @@ -65,7 +71,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) @@ -85,32 +98,44 @@ int sandbox_fs_ls(const char *dirname) return 0; } +int sandbox_fs_exists(const char *filename) +{ + loff_t size; + int ret; + + ret = os_get_filesize(filename, &size); + return ret == 0; +} + +int sandbox_fs_size(const char *filename, loff_t *size) +{ + 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 ret; } -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) printf("** Unable to write file %s **\n", filename); - return -1; - } - return len_written; + return ret; }