BlueSCSI_disk.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * SCSI2SD V6 - Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
  3. * Copyright (C) 2014 Doug Brown <doug@downtowndougbrown.com
  4. * ZuluSCSI™ - Copyright (c) 2022 Rabbit Hole Computing™
  5. *
  6. * It is derived from disk.h in SCSI2SD V6.
  7. *
  8. * This file is licensed under the GPL version 3 or any later version. 
  9. *
  10. * https://www.gnu.org/licenses/gpl-3.0.html
  11. * ----
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version. 
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. * GNU General Public License for more details. 
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  24. **/
  25. // SCSI disk access routines
  26. // Implements both SCSI2SD V6 disk.h functions and some extra.
  27. #pragma once
  28. #include <stdint.h>
  29. #include <scsi2sd.h>
  30. #include <scsiPhy.h>
  31. #include "ImageBackingStore.h"
  32. #include "BlueSCSI_config.h"
  33. extern "C" {
  34. #include <disk.h>
  35. #include <config.h>
  36. #include <scsi.h>
  37. }
  38. // Extended configuration stored alongside the normal SCSI2SD target information
  39. struct image_config_t: public S2S_TargetCfg
  40. {
  41. image_config_t() {};
  42. ImageBackingStore file;
  43. // For CD-ROM drive ejection
  44. bool ejected;
  45. uint8_t cdrom_events;
  46. bool reinsert_on_inquiry; // Reinsert on Inquiry command (to reinsert automatically after boot)
  47. bool reinsert_after_eject; // Reinsert next image after ejection
  48. // selects a physical button channel that will cause an eject action
  49. // default option of '0' disables this functionality
  50. uint8_t ejectButton;
  51. // For tape drive emulation, current position in blocks
  52. uint32_t tape_pos;
  53. // True if there is a subdirectory of images for this target
  54. bool image_directory;
  55. // the name of the currently mounted image in a dynamic image directory
  56. char current_image[MAX_FILE_PATH];
  57. // Index of image, for when image on-the-fly switching is used for CD drives
  58. // This is also used for dynamic directories to track how many images have been seen
  59. // Negative value forces restart from first image.
  60. int image_index;
  61. // Cue sheet file for CD-ROM images
  62. FsFile cuesheetfile;
  63. // Right-align vendor / product type strings (for Apple)
  64. // Standard SCSI uses left alignment
  65. // This field uses -1 for default when field is not set in .ini
  66. int rightAlignStrings;
  67. // Maximum amount of bytes to prefetch
  68. int prefetchbytes;
  69. // Warning about geometry settings
  70. bool geometrywarningprinted;
  71. // Clear any image state to zeros
  72. void clear();
  73. private:
  74. // There should be only one global instance of this struct per device, so make copy constructor private.
  75. image_config_t(const image_config_t&) = default;
  76. };
  77. // Should be polled intermittently to update the platform eject buttons.
  78. // Call with 'true' only if ejections should be performed immediately (typically when not busy)
  79. // Returns a mask of the buttons that registered an 'eject' action.
  80. uint8_t diskEjectButtonUpdate(bool immediate);
  81. // Reset all image configuration to empty reset state, close all images.
  82. void scsiDiskResetImages();
  83. // Close any files opened from SD card (prepare for remounting SD)
  84. void scsiDiskCloseSDCardImages();
  85. bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int scsi_lun, int blocksize, S2S_CFG_TYPE type = S2S_CFG_FIXED);
  86. void scsiDiskLoadConfig(int target_idx);
  87. // Checks if a filename extension is appropriate for further processing as a disk image.
  88. // The current implementation does not check the the filename prefix for validity.
  89. bool scsiDiskFilenameValid(const char* name);
  90. // Clear the ROM drive header from flash
  91. bool scsiDiskClearRomDrive();
  92. // Program ROM drive and rename image file
  93. bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S2S_CFG_TYPE type);
  94. // Check if there is ROM drive configured in microcontroller flash
  95. bool scsiDiskCheckRomDrive();
  96. bool scsiDiskActivateRomDrive();
  97. // Returns true if there is at least one image active
  98. bool scsiDiskCheckAnyImagesConfigured();
  99. // Gets the next image filename for the target, if configured for multiple
  100. // images. As a side effect this advances image tracking to the next image.
  101. // Returns the length of the new image filename, or 0 if the target is not
  102. // configured for multiple images.
  103. int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen);
  104. // Get pointer to extended image configuration based on target idx
  105. image_config_t &scsiDiskGetImageConfig(int target_idx);
  106. // Start data transfer from disk image to SCSI bus
  107. // Can be called by device type specific command implementations (such as READ CD)
  108. void scsiDiskStartRead(uint32_t lba, uint32_t blocks);
  109. // Start data transfer from SCSI bus to disk image
  110. void scsiDiskStartWrite(uint32_t lba, uint32_t blocks);