]> git.ipfire.org Git - people/ms/u-boot.git/blob - fs/sandbox/sandboxfs.c
Merge branch 'u-boot-atmel/master' into 'u-boot-arm/master'
[people/ms/u-boot.git] / 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 }