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)
16 int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer,
17 loff_t maxsize, loff_t *actread)
22 fd = os_open(filename, OS_O_RDONLY);
25 ret = os_lseek(fd, pos, OS_SEEK_SET);
31 ret = os_get_filesize(filename, &size);
40 size = os_read(fd, buffer, maxsize);
53 int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,
54 loff_t towrite, loff_t *actwrite)
59 fd = os_open(filename, OS_O_RDWR | OS_O_CREAT);
62 ret = os_lseek(fd, pos, OS_SEEK_SET);
67 size = os_write(fd, buffer, towrite);
80 int sandbox_fs_ls(const char *dirname)
82 struct os_dirent_node *head, *node;
85 ret = os_dirent_ls(dirname, &head);
89 for (node = head; node; node = node->next) {
90 printf("%s %10lu %s\n", os_dirent_get_typename(node->type),
91 node->size, node->name);
97 int sandbox_fs_exists(const char *filename)
102 ret = os_get_filesize(filename, &size);
106 int sandbox_fs_size(const char *filename, loff_t *size)
108 return os_get_filesize(filename, size);
111 void sandbox_fs_close(void)
115 int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t len,
120 ret = sandbox_fs_read_at(filename, offset, buf, len, actread);
122 printf("** Unable to read file %s **\n", filename);
127 int fs_write_sandbox(const char *filename, void *buf, loff_t offset,
128 loff_t len, loff_t *actwrite)
132 ret = sandbox_fs_write_at(filename, offset, buf, len, actwrite);
134 printf("** Unable to write file %s **\n", filename);