2 * Copyright (c) 2012, Google Inc.
4 * SPDX-License-Identifier: GPL-2.0+
11 int sandbox_fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info)
14 * Only accept a NULL struct blk_desc 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);
103 int sandbox_fs_exists(const char *filename)
108 ret = os_get_filesize(filename, &size);
112 int sandbox_fs_size(const char *filename, loff_t *size)
114 return os_get_filesize(filename, size);
117 void sandbox_fs_close(void)
121 int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t len,
126 ret = sandbox_fs_read_at(filename, offset, buf, len, actread);
128 printf("** Unable to read file %s **\n", filename);
133 int fs_write_sandbox(const char *filename, void *buf, loff_t offset,
134 loff_t len, loff_t *actwrite)
138 ret = sandbox_fs_write_at(filename, offset, buf, len, actwrite);
140 printf("** Unable to write file %s **\n", filename);