]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: Prepare API change for files greater than 2GB
authorSuriyan Ramasami <suriyan.r@gmail.com>
Mon, 17 Nov 2014 22:39:37 +0000 (14:39 -0800)
committerTom Rini <trini@ti.com>
Sun, 23 Nov 2014 11:49:04 +0000 (06:49 -0500)
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>
arch/sandbox/cpu/os.c
arch/sandbox/cpu/state.c
common/board_f.c
fs/sandbox/sandboxfs.c
include/os.h
include/sandboxfs.h

index 1c4aa3f9bc4c4d054b7cbcd502163693a44319bc..31c93443dba008036e49723fe284eab58a40bda1 100644 (file)
@@ -385,7 +385,7 @@ const char *os_dirent_get_typename(enum os_dirent_t type)
        return os_dirent_typename[OS_FILET_UNKNOWN];
 }
 
-ssize_t os_get_filesize(const char *fname)
+int os_get_filesize(const char *fname, loff_t *size)
 {
        struct stat buf;
        int ret;
@@ -393,7 +393,8 @@ ssize_t os_get_filesize(const char *fname)
        ret = stat(fname, &buf);
        if (ret)
                return ret;
-       return buf.st_size;
+       *size = buf.st_size;
+       return 0;
 }
 
 void os_putc(int ch)
@@ -427,11 +428,11 @@ int os_read_ram_buf(const char *fname)
 {
        struct sandbox_state *state = state_get_current();
        int fd, ret;
-       int size;
+       loff_t size;
 
-       size = os_get_filesize(fname);
-       if (size < 0)
-               return -ENOENT;
+       ret = os_get_filesize(fname, &size);
+       if (ret < 0)
+               return ret;
        if (size != state->ram_size)
                return -ENOSPC;
        fd = open(fname, O_RDONLY);
index 59adad653c2a9f59741ec0276363ea73eee2a3b2..ba73b7e251040831f45a38d29132479b605c0abc 100644 (file)
@@ -49,14 +49,14 @@ static int state_ensure_space(int extra_size)
 
 static int state_read_file(struct sandbox_state *state, const char *fname)
 {
-       int size;
+       loff_t size;
        int ret;
        int fd;
 
-       size = os_get_filesize(fname);
-       if (size < 0) {
+       ret = os_get_filesize(fname, &size);
+       if (ret < 0) {
                printf("Cannot find sandbox state file '%s'\n", fname);
-               return -ENOENT;
+               return ret;
        }
        state->state_fdt = os_malloc(size);
        if (!state->state_fdt) {
index d4d25d79551affe2f644623bdd9cfc93c58ab733..c6e38f3b117141987f666fafc1e051387d260482 100644 (file)
@@ -287,7 +287,7 @@ static int read_fdt_from_file(void)
        struct sandbox_state *state = state_get_current();
        const char *fname = state->fdt_fname;
        void *blob;
-       ssize_t size;
+       loff_t size;
        int err;
        int fd;
 
@@ -300,10 +300,10 @@ static int read_fdt_from_file(void)
                return -EINVAL;
        }
 
-       size = os_get_filesize(fname);
-       if (size < 0) {
+       err = os_get_filesize(fname, &size);
+       if (err < 0) {
                printf("Failed to file FDT file '%s'\n", fname);
-               return -ENOENT;
+               return err;
        }
        fd = os_open(fname, OS_O_RDONLY);
        if (fd < 0) {
index ba6402c81c0a5a16ac10838cf0c5981331e9031c..d11c087cc169c6db7b23adb784b3d3f08df8961a 100644 (file)
@@ -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;
 }
index 0230a7f40da07893ff2d9d92f1929e7b9cabc1d2..e3645e01169b4a84ae7802ecf95a16298041499a 100644 (file)
@@ -217,9 +217,10 @@ const char *os_dirent_get_typename(enum os_dirent_t type);
  * Get the size of a file
  *
  * @param fname                Filename to check
- * @return size of file, or -1 if an error ocurred
+ * @param size         size of file is returned if no error
+ * @return 0 on success or -1 if an error ocurred
  */
-ssize_t os_get_filesize(const char *fname);
+int os_get_filesize(const char *fname, loff_t *size);
 
 /**
  * Write a character to the controlling OS terminal
index e7c32623e101e31dde107d94468090dc3f041d4d..8e5da6bc6b0242a654c8bbae5e447a98f14e63fc 100644 (file)
 
 int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
 
-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);
+int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,
+                       loff_t maxsize, loff_t *actwrite);
 
 void sandbox_fs_close(void);
 int sandbox_fs_ls(const char *dirname);