win32 _dosmaperr()

From: "Qingqing Zhou" <zhouqq(at)cs(dot)toronto(dot)edu>
To: pgsql-hackers(at)postgresql(dot)org
Subject: win32 _dosmaperr()
Date: 2005-07-14 02:08:59
Message-ID: db4hlo$sm4$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

There were several reports of "unable to read/write" on Pg8.0.x win32 port:

http://archives.postgresql.org/pgsql-bugs/2005-02/msg00181.php

I encounter this several times and finally I catch the GetLastError()
number. It is

32, ERROR_SHARING_VIOLATION
The process cannot access the file because it is being used by another
process.

But PG server error message is "invalid parameter" which makes this error
difficult to understand and track. After examing win32 CRT's _dosmaperr()
implementation, I found they failed to transalte ERROR_SHARING_VIOLATION, so
the default errno is set to EINVAL. To solve it, we can do our own
_dosmaperr(GetLastError()) again if read/write failed. Unfortunately our
_dosmaperr() failed to do so either, so here is a patch of error.c. Also, I
raised the error level to NOTICE for better bug report. If this is
acceptable, I will patch FileRead()/FileWrite() etc.

However, I am very sure why this could happen. That is, who uses the data
file in a non-sharing mode? There are many possibilities, a common concensus
is [Anti-]virus software. Yes, I do have one installed. If we can confirm
this, then we could at least print a hint message.

Regards,
Qingqing

Index: error.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/port/win32/error.c,v
retrieving revision 1.4
diff -c -r1.4 error.c
*** error.c 31 Dec 2004 22:00:37 -0000 1.4
--- error.c 13 Jul 2005 09:04:57 -0000
***************
*** 72,77 ****
--- 72,80 ----
ERROR_NO_MORE_FILES, ENOENT
},
{
+ ERROR_SHARING_VIOLATION, EACCES
+ },
+ {
ERROR_LOCK_VIOLATION, EACCES
},
{
***************
*** 180,188 ****
}
}

! ereport(DEBUG4,
! (errmsg_internal("Unknown win32 error code: %i",
! (int) e)));
errno = EINVAL;
return;
}
--- 183,192 ----
}
}

! ereport(NOTICE,
! (errmsg_internal("Unknown win32 error code: %i. "
! "Please report to <pgsql-bugs(at)postgresql(dot)org>.",
! (int) e)));
errno = EINVAL;
return;
}

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2005-07-14 03:58:24 test
Previous Message David Fetter 2005-07-14 01:35:51 Toward pg_upgrade