mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 16:52:14 +02:00
sandbox: Prepare API change for files greater than 2GB
Change the internal sandbox functions to use loff_t for file offsets. Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com> Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
committed by
Tom Rini
parent
9f12cd0e06
commit
96b1046d1c
@@ -13,10 +13,10 @@ int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
|
||||
return 0;
|
||||
}
|
||||
|
||||
long sandbox_fs_read_at(const char *filename, unsigned long pos,
|
||||
void *buffer, unsigned long maxsize)
|
||||
int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer,
|
||||
loff_t maxsize, loff_t *actread)
|
||||
{
|
||||
ssize_t size;
|
||||
loff_t size;
|
||||
int fd, ret;
|
||||
|
||||
fd = os_open(filename, OS_O_RDONLY);
|
||||
@@ -27,16 +27,31 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos,
|
||||
os_close(fd);
|
||||
return ret;
|
||||
}
|
||||
if (!maxsize)
|
||||
maxsize = os_get_filesize(filename);
|
||||
if (!maxsize) {
|
||||
ret = os_get_filesize(filename, &size);
|
||||
if (ret) {
|
||||
os_close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
maxsize = size;
|
||||
}
|
||||
|
||||
size = os_read(fd, buffer, maxsize);
|
||||
os_close(fd);
|
||||
|
||||
return size;
|
||||
if (size < 0) {
|
||||
ret = -1;
|
||||
} else {
|
||||
ret = 0;
|
||||
*actread = size;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
long sandbox_fs_write_at(const char *filename, unsigned long pos,
|
||||
void *buffer, unsigned long towrite)
|
||||
int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,
|
||||
loff_t towrite, loff_t *actwrite)
|
||||
{
|
||||
ssize_t size;
|
||||
int fd, ret;
|
||||
@@ -52,7 +67,14 @@ long sandbox_fs_write_at(const char *filename, unsigned long pos,
|
||||
size = os_write(fd, buffer, towrite);
|
||||
os_close(fd);
|
||||
|
||||
return size;
|
||||
if (size == -1) {
|
||||
ret = -1;
|
||||
} else {
|
||||
ret = 0;
|
||||
*actwrite = size;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sandbox_fs_ls(const char *dirname)
|
||||
@@ -74,15 +96,23 @@ int sandbox_fs_ls(const char *dirname)
|
||||
|
||||
int sandbox_fs_exists(const char *filename)
|
||||
{
|
||||
ssize_t sz;
|
||||
loff_t size;
|
||||
int ret;
|
||||
|
||||
sz = os_get_filesize(filename);
|
||||
return sz >= 0;
|
||||
ret = os_get_filesize(filename, &size);
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
int sandbox_fs_size(const char *filename)
|
||||
{
|
||||
return os_get_filesize(filename);
|
||||
loff_t size;
|
||||
int ret;
|
||||
|
||||
ret = os_get_filesize(filename, &size);
|
||||
if (ret)
|
||||
return ret;
|
||||
else
|
||||
return size;
|
||||
}
|
||||
|
||||
void sandbox_fs_close(void)
|
||||
@@ -91,26 +121,28 @@ void sandbox_fs_close(void)
|
||||
|
||||
int fs_read_sandbox(const char *filename, void *buf, int offset, int len)
|
||||
{
|
||||
int len_read;
|
||||
int ret;
|
||||
loff_t actread;
|
||||
|
||||
len_read = sandbox_fs_read_at(filename, offset, buf, len);
|
||||
if (len_read == -1) {
|
||||
ret = sandbox_fs_read_at(filename, offset, buf, len, &actread);
|
||||
if (ret) {
|
||||
printf("** Unable to read file %s **\n", filename);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return len_read;
|
||||
return actread;
|
||||
}
|
||||
|
||||
int fs_write_sandbox(const char *filename, void *buf, int offset, int len)
|
||||
{
|
||||
int len_written;
|
||||
int ret;
|
||||
loff_t actwrite;
|
||||
|
||||
len_written = sandbox_fs_write_at(filename, offset, buf, len);
|
||||
if (len_written == -1) {
|
||||
ret = sandbox_fs_write_at(filename, offset, buf, len, &actwrite);
|
||||
if (ret) {
|
||||
printf("** Unable to write file %s **\n", filename);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return len_written;
|
||||
return actwrite;
|
||||
}
|
||||
|
Reference in New Issue
Block a user