[PATCH 1/3] Tell user which HD type (interface) is in question on HD errors

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


E.g. if user selects same HD file for multiple interfaces, it's
impossible for user to know on which interface the file got rejected
(due to file lock failing) unless Hatari tells it.
---
 src/hdc.c          | 33 ++++++++++++++++++---------------
 src/ide.c          |  4 ++--
 src/includes/hdc.h |  4 ++--
 src/ncr5380.c      |  2 +-
 4 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/hdc.c b/src/hdc.c
index f0c728ce..509e6a36 100644
--- a/src/hdc.c
+++ b/src/hdc.c
@@ -774,7 +774,7 @@ int HDC_PartitionCount(FILE *fp, const Uint64 tracelevel, int *pIsByteSwapped)
  * Check file size for sane values (non-zero, multiple of 512),
  * and return the size
  */
-off_t HDC_CheckAndGetSize(const char *filename, unsigned long blockSize)
+off_t HDC_CheckAndGetSize(const char *hdtype, const char *filename, unsigned long blockSize)
 {
 	off_t filesize;
 	char shortname[48];
@@ -784,8 +784,8 @@ off_t HDC_CheckAndGetSize(const char *filename, unsigned long blockSize)
 	filesize = File_Length(filename);
 	if (filesize < 0)
 	{
-		Log_AlertDlg(LOG_ERROR, "Unable to get size of HD image file\n'%s'!",
-		             shortname);
+		Log_AlertDlg(LOG_ERROR, "Unable to get size of %s HD image file\n'%s'!",
+		             hdtype, shortname);
 		if (sizeof(off_t) < 8)
 		{
 			Log_Printf(LOG_ERROR, "Note: This version of Hatari has been built"
@@ -796,16 +796,16 @@ off_t HDC_CheckAndGetSize(const char *filename, unsigned long blockSize)
 	}
 	if (filesize == 0)
 	{
-		Log_AlertDlg(LOG_ERROR, "Can not use HD image file\n'%s'\n"
+		Log_AlertDlg(LOG_ERROR, "Can not use %s HD image file\n'%s'\n"
 		                        "since the file is empty.",
-		             shortname);
+		             hdtype, shortname);
 		return -EINVAL;
 	}
 	if ((filesize & (blockSize - 1)) != 0)
 	{
-		Log_AlertDlg(LOG_ERROR, "Can not use the hard disk image file\n"
+		Log_AlertDlg(LOG_ERROR, "Can not use the %s HD image file\n"
 		                        "'%s'\nsince its size is not a multiple"
-		                        " of %ld.", shortname, blockSize);
+		                        " of %ld.", hdtype, shortname, blockSize);
 		return -EINVAL;
 	}
 
@@ -815,16 +815,16 @@ off_t HDC_CheckAndGetSize(const char *filename, unsigned long blockSize)
 /**
  * Open a disk image file
  */
-int HDC_InitDevice(SCSI_DEV *dev, char *filename, unsigned long blockSize)
+int HDC_InitDevice(const char *hdtype, SCSI_DEV *dev, char *filename, unsigned long blockSize)
 {
 	off_t filesize;
 	FILE *fp;
 
 	dev->enabled = false;
-	Log_Printf(LOG_INFO, "Mounting hard drive image '%s'\n", filename);
+	Log_Printf(LOG_INFO, "Mounting %s HD image '%s'\n", hdtype, filename);
 
 	/* Check size for sanity */
-	filesize = HDC_CheckAndGetSize(filename, blockSize);
+	filesize = HDC_CheckAndGetSize(hdtype, filename, blockSize);
 	if (filesize < 0)
 		return filesize;
 
@@ -832,14 +832,17 @@ int HDC_InitDevice(SCSI_DEV *dev, char *filename, unsigned long blockSize)
 	{
 		if (!(fp = fopen(filename, "rb")))
 		{
-			Log_AlertDlg(LOG_ERROR, "Cannot open HD file for reading\n'%s'!\n", filename);
+			Log_AlertDlg(LOG_ERROR, "Cannot open %s HD file for reading\n'%s'!\n",
+				     hdtype, filename);
 			return -ENOENT;
 		}
-		Log_AlertDlg(LOG_WARN, "HD file is read-only, no writes will go through\n'%s'.\n", filename);
+		Log_AlertDlg(LOG_WARN, "%s HD file is read-only, no writes will go through\n'%s'.\n",
+			     hdtype, filename);
 	}
 	else if (!File_Lock(fp))
 	{
-		Log_AlertDlg(LOG_ERROR, "Locking HD file for writing failed\n'%s'!\n", filename);
+		Log_AlertDlg(LOG_ERROR, "Locking %s HD file for writing failed\n'%s'!\n",
+			     hdtype, filename);
 		fclose(fp);
 		return -ENOLCK;
 	}
@@ -875,7 +878,7 @@ bool HDC_Init(void)
 	{
 		if (!ConfigureParams.Acsi[i].bUseDevice)
 			continue;
-		if (HDC_InitDevice(&AcsiBus.devs[i], ConfigureParams.Acsi[i].sDeviceFile, ConfigureParams.Acsi[i].nBlockSize) == 0)
+		if (HDC_InitDevice("ACSI", &AcsiBus.devs[i], ConfigureParams.Acsi[i].sDeviceFile, ConfigureParams.Acsi[i].nBlockSize) == 0)
 			nAcsiPartitions += HDC_PartitionCount(AcsiBus.devs[i].image_file, TRACE_SCSI_CMD, NULL);
 	}
 	/* set total number of partitions */
@@ -1027,7 +1030,7 @@ static void Acsi_DmaTransfer(void)
 			int wlen = fwrite(&STRam[nDmaAddr], 1, AcsiBus.data_len, AcsiBus.dmawrite_to_fh);
 			if (wlen != AcsiBus.data_len)
 			{
-				Log_Printf(LOG_ERROR, "Could not write all bytes to hard disk image.\n");
+				Log_Printf(LOG_ERROR, "Could not write all bytes to ACSI HD image.\n");
 				AcsiBus.status = HD_STATUS_ERROR;
 			}
 #endif
diff --git a/src/ide.c b/src/ide.c
index b1955d21..55a75710 100644
--- a/src/ide.c
+++ b/src/ide.c
@@ -560,7 +560,7 @@ static int bdrv_open(BlockDriverState *bs, const char *filename, unsigned long b
 	Log_Printf(LOG_INFO, "Mounting IDE hard drive image %s\n", filename);
 
 	bs->read_only = 0;
-	bs->file_size = HDC_CheckAndGetSize(filename, blockSize);
+	bs->file_size = HDC_CheckAndGetSize("IDE", filename, blockSize);
 	if (bs->file_size <= 0)
 		return -1;
 	if (bs->file_size < 2 * 16 * 63 * bs->sector_size)
@@ -581,7 +581,7 @@ static int bdrv_open(BlockDriverState *bs, const char *filename, unsigned long b
 	}
 	else if (!File_Lock(bs->fhndl))
 	{
-		Log_Printf(LOG_ERROR, "Cannot lock HD file for writing!\n");
+		Log_Printf(LOG_ERROR, "Cannot lock IDE HD file for writing!\n");
 		fclose(bs->fhndl);
 		bs->fhndl = NULL;
 	}
diff --git a/src/includes/hdc.h b/src/includes/hdc.h
index df4445dc..201aa380 100644
--- a/src/includes/hdc.h
+++ b/src/includes/hdc.h
@@ -94,12 +94,12 @@ extern bool bAcsiEmuOn;
  */
 extern bool HDC_Init(void);
 extern void HDC_UnInit(void);
-extern int HDC_InitDevice(SCSI_DEV *dev, char *filename, unsigned long blockSize);
+extern int HDC_InitDevice(const char *hdtype, SCSI_DEV *dev, char *filename, unsigned long blockSize);
 extern void HDC_ResetCommandStatus(void);
 extern short int HDC_ReadCommandByte(int addr);
 extern void HDC_WriteCommandByte(int addr, Uint8 byte);
 extern int HDC_PartitionCount(FILE *fp, const Uint64 tracelevel, int *pIsByteSwapped);
-extern off_t HDC_CheckAndGetSize(const char *filename, unsigned long blockSize);
+extern off_t HDC_CheckAndGetSize(const char *hdtype, const char *filename, unsigned long blockSize);
 extern bool HDC_WriteCommandPacket(SCSI_CTRLR *ctr, Uint8 b);
 extern void HDC_DmaTransfer(void);
 
diff --git a/src/ncr5380.c b/src/ncr5380.c
index 44e6eaf7..aa8ec992 100644
--- a/src/ncr5380.c
+++ b/src/ncr5380.c
@@ -1036,7 +1036,7 @@ bool Ncr5380_Init(void)
 	{
 		if (!ConfigureParams.Scsi[i].bUseDevice)
 			continue;
-		if (HDC_InitDevice(&ScsiBus.devs[i], ConfigureParams.Scsi[i].sDeviceFile, ConfigureParams.Scsi[i].nBlockSize) == 0)
+		if (HDC_InitDevice("SCSI", &ScsiBus.devs[i], ConfigureParams.Scsi[i].sDeviceFile, ConfigureParams.Scsi[i].nBlockSize) == 0)
 			nScsiPartitions += HDC_PartitionCount(ScsiBus.devs[i].image_file, TRACE_SCSI_CMD, NULL);
 	}
 	nNumDrives += nScsiPartitions;
-- 
2.20.1


--------------5B665AC7BF12A75683BFBB6E
Content-Type: text/x-patch; charset=UTF-8;
 name="0003-Treat-IDE-HD-image-errors-similarly-to-ACSI-SCSI-err.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0003-Treat-IDE-HD-image-errors-similarly-to-ACSI-SCSI-err.pa";
 filename*1="tch"



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/