Hi,

I recently faced an issue on windows where one of the tests was
failing with 'unrecognized win32 error code: 123', see [1]. I figured
out that it was due to a wrong file name being sent to open() system
call (this error is of my own making and I fixed it for that thread).
The failure occurs in dosmaperr() in win32error.c due to an unmapped
errno for win32 error code. The error code 123 i.e. ERROR_INVALID_NAME
says "The file name, directory name, or volume label syntax is
incorrect." [2], the closest errno mapping would be ENOENT. I quickly
looked around for the other win32 error codes [2] that don't have
mapping. I filtered out some common error codes such as
ERROR_OUTOFMEMORY, ERROR_HANDLE_DISK_FULL, ERROR_INSUFFICIENT_BUFFER,
ERROR_NOACCESS. There may be many more, but these seemed common IMO.

Having a right errno mapping always helps recognize the errors correctly.

I'm attaching a patch that maps the above win32 error codes to errno
in win32error.c. I also think that we can add a note in win32error.c
by mentioning the link [2] to revisit the mapping whenever
"unrecognized win32 error code:XXX" error occurs.

Thoughts?

Thanks Michael Paquier for off list chat.

[1] 
https://www.postgresql.org/message-id/CALj2ACWKvjOO-JzYpMBpk-o_o9CeKGEqMcS=yxf-pc6m+jo...@mail.gmail.com
[2] 
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
From 5e7ea6dc32e60d5a4b0868596eb63516c6ad21d7 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Tue, 27 Sep 2022 08:43:02 +0000
Subject: [PATCH v1] Extend win32 error codes to errno mapping in win32error.c

---
 src/port/win32error.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/port/win32error.c b/src/port/win32error.c
index fca867ba3d..44ede0cfaa 100644
--- a/src/port/win32error.c
+++ b/src/port/win32error.c
@@ -164,6 +164,21 @@ static const struct
 	},
 	{
 		ERROR_DELETE_PENDING, ENOENT
+	},
+	{
+		ERROR_INVALID_NAME, ENOENT
+	},
+	{
+		ERROR_OUTOFMEMORY, ENOMEM
+	},
+	{
+		ERROR_HANDLE_DISK_FULL, ENOSPC
+	},
+	{
+		ERROR_INSUFFICIENT_BUFFER, EINVAL
+	},
+	{
+		ERROR_NOACCESS, EACCES
 	}
 };
 
-- 
2.34.1

Reply via email to