2 * Copyright (c) 2012, Google Inc.
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.
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.
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,
24 int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
29 long sandbox_fs_read_at(const char *filename, unsigned long pos,
30 void *buffer, unsigned long maxsize)
35 fd = os_open(filename, OS_O_RDONLY);
38 ret = os_lseek(fd, pos, OS_SEEK_SET);
44 maxsize = os_get_filesize(filename);
45 size = os_read(fd, buffer, maxsize);
51 long sandbox_fs_write_at(const char *filename, unsigned long pos,
52 void *buffer, unsigned long towrite)
57 fd = os_open(filename, OS_O_RDWR | OS_O_CREAT);
60 ret = os_lseek(fd, pos, OS_SEEK_SET);
65 size = os_write(fd, buffer, towrite);
71 int sandbox_fs_ls(const char *dirname)
73 struct os_dirent_node *head, *node;
76 ret = os_dirent_ls(dirname, &head);
80 for (node = head; node; node = node->next) {
81 printf("%s %10lu %s\n", os_dirent_get_typename(node->type),
82 node->size, node->name);
88 void sandbox_fs_close(void)
92 int fs_read_sandbox(const char *filename, void *buf, int offset, int len)
96 len_read = sandbox_fs_read_at(filename, offset, buf, len);
98 printf("** Unable to read file %s **\n", filename);
105 int fs_write_sandbox(const char *filename, void *buf, int offset, int len)
109 len_written = sandbox_fs_write_at(filename, offset, buf, len);
110 if (len_written == -1) {
111 printf("** Unable to write file %s **\n", filename);