summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author arbee <rb6502@users.noreply.github.com>2021-09-18 13:28:14 -0400
committer arbee <rb6502@users.noreply.github.com>2021-09-18 13:28:14 -0400
commit13201c72ec37e840545c629c01511bcf81c780db (patch)
tree172b0c35a00ec4a5229e19c725a7f1152f0be509
parent40c382bdbcb8a337fcaf9a7855a9ca483adc6161 (diff)
harddisk.cpp: Allow specifying the desired block size for loose files / verifying a CHD's block size. [R. Belmont]
-rw-r--r--src/lib/util/harddisk.cpp52
-rw-r--r--src/lib/util/harddisk.h2
2 files changed, 47 insertions, 7 deletions
diff --git a/src/lib/util/harddisk.cpp b/src/lib/util/harddisk.cpp
index 2e8d14f9a8a..66d98582bb6 100644
--- a/src/lib/util/harddisk.cpp
+++ b/src/lib/util/harddisk.cpp
@@ -147,7 +147,7 @@ chd_file *hard_disk_get_chd(hard_disk_file *file)
*
* @brief Hard disk get information.
*
- * @param [in,out] file If non-null, the file.
+ * @param [in,out] file The hard disk file object to operate on.
*
* @return null if it fails, else a hard_disk_info*.
*/
@@ -168,9 +168,9 @@ hard_disk_info *hard_disk_get_info(hard_disk_file *file)
*
* @brief Hard disk read.
*
- * @param [in,out] file If non-null, the file.
- * @param lbasector The lbasector.
- * @param [in,out] buffer If non-null, the buffer.
+ * @param [in,out] file The hard disk file object to operate on.
+ * @param lbasector The sector number (Linear Block Address) to read.
+ * @param buffer The buffer where the hard disk data will be placed.
*
* @return An uint32_t.
*/
@@ -202,9 +202,9 @@ uint32_t hard_disk_read(hard_disk_file *file, uint32_t lbasector, void *buffer)
*
* @brief Hard disk write.
*
- * @param [in,out] file If non-null, the file.
- * @param lbasector The lbasector.
- * @param buffer The buffer.
+ * @param [in,out] file The hard disk file object to operate on.
+ * @param lbasector The sector number (Linear Block Address) to write.
+ * @param buffer The buffer containing the data to write.
*
* @return An uint32_t.
*/
@@ -224,3 +224,41 @@ uint32_t hard_disk_write(hard_disk_file *file, uint32_t lbasector, const void *b
return (actual == file->info.sectorbytes);
}
}
+
+/*-------------------------------------------------
+ hard_disk_set_block_size - sets the block size
+ for a non-CHD-backed hard disk (a bare file).
+-------------------------------------------------*/
+
+/**
+ * @fn bool hard_disk_set_block_size(hard_disk_file *file, uint32_t blocksize)
+ *
+ * @brief Hard disk set block size (works only for non-CHD-files)
+ *
+ * @param [in,out] file The hard_disk_file object to operate on.
+ * @param blocksize The block size of this hard disk, in bytes.
+ *
+ * @return true on success, false on failure. Failure means a CHD is in use and the CHD
+ * block size does not match the passed in size. If a CHD is in use and the block
+ * sizes match, success is returned).
+ */
+
+bool hard_disk_set_block_size(hard_disk_file *file, uint32_t blocksize)
+{
+ if (file->chd)
+ {
+ // if the CHD block size matches our block size, we're OK.
+ if (file->chd->unit_bytes() == blocksize)
+ {
+ return true;
+ }
+
+ // indicate failure, since we can't change the block size of a CHD.
+ return false;
+ }
+ else
+ {
+ file->info.sectorbytes = blocksize;
+ }
+ return true;
+}
diff --git a/src/lib/util/harddisk.h b/src/lib/util/harddisk.h
index e6fae165f19..f6dd39acd70 100644
--- a/src/lib/util/harddisk.h
+++ b/src/lib/util/harddisk.h
@@ -48,6 +48,8 @@ void hard_disk_close(hard_disk_file *file);
chd_file *hard_disk_get_chd(hard_disk_file *file);
hard_disk_info *hard_disk_get_info(hard_disk_file *file);
+bool hard_disk_set_block_size(hard_disk_file *file, uint32_t blocksize);
+
uint32_t hard_disk_read(hard_disk_file *file, uint32_t lbasector, void *buffer);
uint32_t hard_disk_write(hard_disk_file *file, uint32_t lbasector, const void *buffer);