2 * Copyright (c) 2012, Google Inc.
4 * SPDX-License-Identifier: GPL-2.0+
11 int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
14 * Only accept a NULL block_dev_desc_t for the sandbox, which is when
15 * hostfs interface is used
20 int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer,
21 loff_t maxsize, loff_t *actread)
26 fd = os_open(filename, OS_O_RDONLY);
29 ret = os_lseek(fd, pos, OS_SEEK_SET);
35 ret = os_get_filesize(filename, &size);
44 size = os_read(fd, buffer, maxsize);
57 int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,
58 loff_t towrite, loff_t *actwrite)
63 fd = os_open(filename, OS_O_RDWR | OS_O_CREAT);
66 ret = os_lseek(fd, pos, OS_SEEK_SET);
71 size = os_write(fd, buffer, towrite);
84 int sandbox_fs_ls(const char *dirname)
86 struct os_dirent_node *head, *node;
89 ret = os_dirent_ls(dirname, &head);
93 for (node = head; node; node = node->next) {
94 printf("%s %10lu %s\n", os_dirent_get_typename(node->type),
95 node->size, node->name);
101 int sandbox_fs_exists(const char *filename)
106 ret = os_get_filesize(filename, &size);
110 int sandbox_fs_size(const char *filename, loff_t *size)
112 return os_get_filesize(filename, size);
115 void sandbox_fs_close(void)
119 int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t len,
124 ret = sandbox_fs_read_at(filename, offset, buf, len, actread);
126 printf("** Unable to read file %s **\n", filename);
131 int fs_write_sandbox(const char *filename, void *buf, loff_t offset,
132 loff_t len, loff_t *actwrite)
136 ret = sandbox_fs_write_at(filename, offset, buf, len, actwrite);
138 printf("** Unable to write file %s **\n", filename);