1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012, Google Inc.
10 #include <sandboxfs.h>
12 int sandbox_fs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info)
15 * Only accept a NULL struct blk_desc for the sandbox, which is when
16 * hostfs interface is used
21 int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer,
22 loff_t maxsize, loff_t *actread)
27 fd = os_open(filename, OS_O_RDONLY);
30 ret = os_lseek(fd, pos, OS_SEEK_SET);
36 ret = os_get_filesize(filename, &size);
45 size = os_read(fd, buffer, maxsize);
58 int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,
59 loff_t towrite, loff_t *actwrite)
64 fd = os_open(filename, OS_O_RDWR | OS_O_CREAT);
67 ret = os_lseek(fd, pos, OS_SEEK_SET);
72 size = os_write(fd, buffer, towrite);
85 int sandbox_fs_ls(const char *dirname)
87 struct os_dirent_node *head, *node;
90 ret = os_dirent_ls(dirname, &head);
94 for (node = head; node; node = node->next) {
95 printf("%s %10lu %s\n", os_dirent_get_typename(node->type),
96 node->size, node->name);
104 int sandbox_fs_exists(const char *filename)
109 ret = os_get_filesize(filename, &size);
113 int sandbox_fs_size(const char *filename, loff_t *size)
115 return os_get_filesize(filename, size);
118 void sandbox_fs_close(void)
122 int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t len,
127 ret = sandbox_fs_read_at(filename, offset, buf, len, actread);
129 printf("** Unable to read file %s **\n", filename);
134 int fs_write_sandbox(const char *filename, void *buf, loff_t offset,
135 loff_t len, loff_t *actwrite)
139 ret = sandbox_fs_write_at(filename, offset, buf, len, actwrite);
141 printf("** Unable to write file %s **\n", filename);