]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: scsi: Move file size into shared struct
authorSimon Glass <sjg@chromium.org>
Wed, 21 Sep 2022 14:21:40 +0000 (16:21 +0200)
committerSimon Glass <sjg@chromium.org>
Sun, 25 Sep 2022 14:30:05 +0000 (08:30 -0600)
Move this information into struct scsi_emul_info so we can use it in
common code.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/usb/emul/sandbox_flash.c
include/scsi_emul.h

index e4a8eb2e988209c2090c6d778196d100552da8f8..3c5bc675e3cc752aab323e32a98408eea62b4ada 100644 (file)
@@ -49,7 +49,6 @@ struct sandbox_flash_priv {
        bool error;
        u32 tag;
        int fd;
-       loff_t file_size;
        struct umass_bbb_csw status;
 };
 
@@ -258,8 +257,8 @@ static int handle_ufi_command(struct sandbox_flash_plat *plat,
                struct scsi_read_capacity_resp *resp = (void *)info->buff;
                uint blocks;
 
-               if (priv->file_size)
-                       blocks = priv->file_size / info->block_size - 1;
+               if (info->file_size)
+                       blocks = info->file_size / info->block_size - 1;
                else
                        blocks = 0;
                resp->last_block_addr = cpu_to_be32(blocks);
@@ -395,7 +394,7 @@ static int sandbox_flash_probe(struct udevice *dev)
 
        priv->fd = os_open(plat->pathname, OS_O_RDONLY);
        if (priv->fd != -1) {
-               ret = os_get_filesize(plat->pathname, &priv->file_size);
+               ret = os_get_filesize(plat->pathname, &info->file_size);
                if (ret)
                        return log_msg_ret("sz", ret);
        }
index 86c9379ca9e739fd267f26f162c1e29846d5ab89..3c52398e3ff177951dc195a8f79a4cf2e080934b 100644 (file)
@@ -18,6 +18,7 @@
  * @vendor: Vendor name
  * @product: Product name
  * @block_size: Block size of device in bytes (normally 512)
+ * @file_size: Size of the backing file for this emulator, in bytes
  *
  * @phase: Current SCSI phase
  * @buff_used: Number of bytes ready to transfer back to host
@@ -32,6 +33,7 @@ struct scsi_emul_info {
        const char *vendor;
        const char *product;
        int block_size;
+       loff_t file_size;
 
        /* state maintained by the emulator: */
        enum scsi_cmd_phase phase;