1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012, Google Inc.
10 int sandbox_fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info)
13 * Only accept a NULL struct blk_desc for the sandbox, which is when
14 * hostfs interface is used
19 int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer,
20 loff_t maxsize, loff_t *actread)
25 fd = os_open(filename, OS_O_RDONLY);
28 ret = os_lseek(fd, pos, OS_SEEK_SET);
34 ret = os_get_filesize(filename, &size);
43 size = os_read(fd, buffer, maxsize);
56 int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,
57 loff_t towrite, loff_t *actwrite)
62 fd = os_open(filename, OS_O_RDWR | OS_O_CREAT);
65 ret = os_lseek(fd, pos, OS_SEEK_SET);
70 size = os_write(fd, buffer, towrite);
83 int sandbox_fs_ls(const char *dirname)
85 struct os_dirent_node *head, *node;
88 ret = os_dirent_ls(dirname, &head);
92 for (node = head; node; node = node->next) {
93 printf("%s %10lu %s\n", os_dirent_get_typename(node->type),
94 node->size, node->name);
102 int sandbox_fs_exists(const char *filename)
107 ret = os_get_filesize(filename, &size);
111 int sandbox_fs_size(const char *filename, loff_t *size)
113 return os_get_filesize(filename, size);
116 void sandbox_fs_close(void)
120 int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t len,
125 ret = sandbox_fs_read_at(filename, offset, buf, len, actread);
127 printf("** Unable to read file %s **\n", filename);
132 int fs_write_sandbox(const char *filename, void *buf, loff_t offset,
133 loff_t len, loff_t *actwrite)
137 ret = sandbox_fs_write_at(filename, offset, buf, len, actwrite);
139 printf("** Unable to write file %s **\n", filename);