Commit 92ccc96bf3cd6c6a3a9a56e03d5ceb4874735d22

Authored by Simon Glass
Committed by Tom Rini
1 parent 62584db191

sandbox: Add host filesystem

This allows reading of files from the host filesystem in sandbox.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@ti.com>

Showing 7 changed files with 189 additions and 0 deletions Side-by-side Diff

... ... @@ -264,6 +264,7 @@
264 264 fs/fdos/libfdos.o \
265 265 fs/jffs2/libjffs2.o \
266 266 fs/reiserfs/libreiserfs.o \
  267 + fs/sandbox/libsandboxfs.o \
267 268 fs/ubifs/libubifs.o \
268 269 fs/yaffs2/libyaffs2.o \
269 270 fs/zfs/libzfs.o
... ... @@ -472,6 +472,23 @@
472 472 int part;
473 473 disk_partition_t tmpinfo;
474 474  
  475 + /*
  476 + * For now, we have a special case for sandbox, since there is no
  477 + * real block device support.
  478 + */
  479 + if (0 == strcmp(ifname, "host")) {
  480 + *dev_desc = NULL;
  481 + info->start = info->size = info->blksz = 0;
  482 + info->bootable = 0;
  483 + strcpy((char *)info->type, BOOT_PART_TYPE);
  484 + strcpy((char *)info->name, "Sandbox host");
  485 +#ifdef CONFIG_PARTITION_UUIDS
  486 + info->uuid[0] = 0;
  487 +#endif
  488 +
  489 + return 0;
  490 + }
  491 +
475 492 /* If no dev_part_str, use bootdevice environment variable */
476 493 if (!dev_part_str || !strlen(dev_part_str) ||
477 494 !strcmp(dev_part_str, "-"))
... ... @@ -20,6 +20,7 @@
20 20 #include <ext4fs.h>
21 21 #include <fat.h>
22 22 #include <fs.h>
  23 +#include <sandboxfs.h>
23 24 #include <asm/io.h>
24 25  
25 26 DECLARE_GLOBAL_DATA_PTR;
... ... @@ -76,6 +77,15 @@
76 77 .close = ext4fs_close,
77 78 .ls = ext4fs_ls,
78 79 .read = ext4_read_file,
  80 + },
  81 +#endif
  82 +#ifdef CONFIG_SANDBOX
  83 + {
  84 + .fstype = FS_TYPE_SANDBOX,
  85 + .probe = sandbox_fs_set_blk_dev,
  86 + .close = sandbox_fs_close,
  87 + .ls = sandbox_fs_ls,
  88 + .read = fs_read_sandbox,
79 89 },
80 90 #endif
81 91 {
  1 +#
  2 +# Copyright (c) 2012, Google Inc.
  3 +#
  4 +# (C) Copyright 2006
  5 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6 +#
  7 +# (C) Copyright 2003
  8 +# Pavel Bartusek, Sysgo Real-Time Solutions AG, pba@sysgo.de
  9 +#
  10 +# This program is free software; you can redistribute it and/or
  11 +# modify it under the terms of the GNU General Public License as
  12 +# published by the Free Software Foundation; either version 2 of
  13 +# the License, or (at your option) any later version.
  14 +#
  15 +# This program is distributed in the hope that it will be useful,
  16 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18 +# GNU General Public License for more details.
  19 +#
  20 +# You should have received a copy of the GNU General Public License
  21 +# along with this program; if not, write to the Free Software
  22 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23 +# MA 02111-1307 USA
  24 +#
  25 +
  26 +include $(TOPDIR)/config.mk
  27 +
  28 +LIB = $(obj)libsandboxfs.o
  29 +
  30 +COBJS-$(CONFIG_SANDBOX) := sandboxfs.o
  31 +
  32 +SRCS := $(COBJS-y:.o=.c)
  33 +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
  34 +
  35 +all: $(LIB) $(AOBJS)
  36 +
  37 +$(LIB): $(obj).depend $(OBJS)
  38 + $(call cmd_link_o_target, $(OBJS))
  39 +
  40 +#########################################################################
  41 +
  42 +# defines $(obj).depend target
  43 +include $(SRCTREE)/rules.mk
  44 +
  45 +sinclude $(obj).depend
  46 +
  47 +#########################################################################
fs/sandbox/sandboxfs.c
  1 +/*
  2 + * Copyright (c) 2012, Google Inc.
  3 + *
  4 + * This program is free software; you can redistribute it and/or
  5 + * modify it under the terms of the GNU General Public License as
  6 + * published by the Free Software Foundation; either version 2 of
  7 + * the License, or (at your option) any later version.
  8 + *
  9 + * This program is distributed in the hope that it will be useful,
  10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 + * GNU General Public License for more details.
  13 + *
  14 + * You should have received a copy of the GNU General Public License
  15 + * along with this program; if not, write to the Free Software
  16 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17 + * MA 02111-1307 USA
  18 + */
  19 +
  20 +#include <common.h>
  21 +#include <fs.h>
  22 +#include <os.h>
  23 +
  24 +int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
  25 +{
  26 + return 0;
  27 +}
  28 +
  29 +long sandbox_fs_read_at(const char *filename, unsigned long pos,
  30 + void *buffer, unsigned long maxsize)
  31 +{
  32 + ssize_t size;
  33 + int fd, ret;
  34 +
  35 + fd = os_open(filename, OS_O_RDONLY);
  36 + if (fd < 0)
  37 + return fd;
  38 + ret = os_lseek(fd, pos, OS_SEEK_SET);
  39 + if (ret == -1) {
  40 + os_close(fd);
  41 + return ret;
  42 + }
  43 + if (!maxsize)
  44 + maxsize = os_get_filesize(filename);
  45 + size = os_read(fd, buffer, maxsize);
  46 + os_close(fd);
  47 +
  48 + return size;
  49 +}
  50 +
  51 +int sandbox_fs_ls(const char *dirname)
  52 +{
  53 + struct os_dirent_node *head, *node;
  54 + int ret;
  55 +
  56 + ret = os_dirent_ls(dirname, &head);
  57 + if (ret)
  58 + return ret;
  59 +
  60 + for (node = head; node; node = node->next) {
  61 + printf("%s %10lu %s\n", os_dirent_get_typename(node->type),
  62 + node->size, node->name);
  63 + }
  64 +
  65 + return 0;
  66 +}
  67 +
  68 +void sandbox_fs_close(void)
  69 +{
  70 +}
  71 +
  72 +int fs_read_sandbox(const char *filename, void *buf, int offset, int len)
  73 +{
  74 + int len_read;
  75 +
  76 + len_read = sandbox_fs_read_at(filename, offset, buf, len);
  77 + if (len_read == -1) {
  78 + printf("** Unable to read file %s **\n", filename);
  79 + return -1;
  80 + }
  81 +
  82 + return len_read;
  83 +}
... ... @@ -21,6 +21,7 @@
21 21 #define FS_TYPE_ANY 0
22 22 #define FS_TYPE_FAT 1
23 23 #define FS_TYPE_EXT 2
  24 +#define FS_TYPE_SANDBOX 3
24 25  
25 26 /*
26 27 * Tell the fs layer which block device an partition to use for future
  1 +/*
  2 + * Copyright (c) 2012, Google Inc.
  3 + *
  4 + * This program is free software; you can redistribute it and/or modify
  5 + * it under the terms of the GNU General Public License version 2 as
  6 + * published by the Free Software Foundation.
  7 + *
  8 + * This program is distributed in the hope that it will be useful,
  9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11 + * GNU General Public License for more details.
  12 + *
  13 + * You should have received a copy of the GNU General Public License
  14 + * along with this program; if not, write to the Free Software
  15 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16 + */
  17 +
  18 +#ifndef __SANDBOX_FS__
  19 +#define __SANDBOX_FS__
  20 +
  21 +int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
  22 +
  23 +long sandbox_fs_read_at(const char *filename, unsigned long pos,
  24 + void *buffer, unsigned long maxsize);
  25 +
  26 +void sandbox_fs_close(void);
  27 +int sandbox_fs_ls(const char *dirname);
  28 +int fs_read_sandbox(const char *filename, void *buf, int offset, int len);
  29 +
  30 +#endif