List:Internals« Previous MessageNext Message »
From:sergeyv Date:November 3 2005 5:30pm
Subject:bk commit into 5.0 tree (SergeyV:1.2026) BUG#13377
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of sergeyv. When sergeyv does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2026 05/11/03 19:29:52 SergeyV@selena. +4 -0
  Fixes bug #13377. my_open() & my_create() functions changed to use 
  my_sopen() on win32 which allows to use FILE_SHARE_DELETE flag to 
  allow deleting opened files. my_sopen() implementation is added to
  support this functionality.

  mysys/my_open.c
    1.22 05/11/03 19:29:44 SergeyV@selena. +184 -0
    Fixes bug #13377. my_open() function changed to use my_sopen() on win32 
    which allows to use FILE_SHARE_DELETE flag to allow deleting opened files.

  mysys/my_create.c
    1.11 05/11/03 19:26:27 SergeyV@selena. +4 -1
    Fixes bug #13377. my_create() function changed to use my_sopen() and which allows
    to use FILE_SHARE_DELETE flag on win32, which helps in deleting opened files.

  include/my_sys.h
    1.176 05/11/03 19:26:26 SergeyV@selena. +1 -0
    Fixes bug #13377. Added my_sopen function.

  include/my_global.h
    1.110 05/11/03 19:26:26 SergeyV@selena. +9 -0
    Fixes bug #13377. Added number of constants for share delete file
    open option.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	SergeyV
# Host:	selena.
# Root:	H:/MYSQL/src/#13377-mysql-5.0

--- 1.175/include/my_sys.h	2005-10-13 02:24:10 +04:00
+++ 1.176/include/my_sys.h	2005-11-03 19:26:26 +03:00
@@ -601,6 +601,7 @@
 
 #ifdef __WIN__
 extern int my_access(const char *path, int amode);
+extern File my_sopen(const char *path, int oflag, int shflag, int pmode);
 #else
 #define my_access access
 #endif

--- 1.10/mysys/my_create.c	2001-12-06 15:10:42 +03:00
+++ 1.11/mysys/my_create.c	2005-11-03 19:26:27 +03:00
@@ -47,13 +47,16 @@
 #elif defined(VMS)
   fd = open((my_string) FileName, access_flags | O_CREAT, 0,
 	    "ctx=stm","ctx=bin");
-#elif defined(MSDOS) || defined(__WIN__) || defined(__EMX__) || defined(OS2)
+#elif defined(MSDOS) || defined(__EMX__) || defined(OS2)
   if (access_flags & O_SHARE)
     fd = sopen((my_string) FileName, access_flags | O_CREAT | O_BINARY,
 	       SH_DENYNO, MY_S_IREAD | MY_S_IWRITE);
   else
     fd =  open((my_string) FileName, access_flags | O_CREAT | O_BINARY,
 	       MY_S_IREAD | MY_S_IWRITE);
+#elif defined(__WIN__)
+  fd= my_sopen((my_string) FileName, access_flags | O_CREAT | O_BINARY,
+	       SH_DENYNO, MY_S_IREAD | MY_S_IWRITE)
 #else
   fd = open(FileName, access_flags);
 #endif

--- 1.21/mysys/my_open.c	2005-05-26 21:54:23 +04:00
+++ 1.22/mysys/my_open.c	2005-11-03 19:29:44 +03:00
@@ -56,12 +56,18 @@
     DBUG_RETURN(my_register_filename(-1, FileName, FILE_BY_OPEN,
                                      EE_FILENOTFOUND, MyFlags));
   }
+#ifndef __WIN__
   if (Flags & O_SHARE)
     fd = sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO,
 	       MY_S_IREAD | MY_S_IWRITE);
   else
     fd = open((my_string) FileName, Flags | O_BINARY,
 	      MY_S_IREAD | MY_S_IWRITE);
+#else
+  fd= my_sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO,
+	       MY_S_IREAD | MY_S_IWRITE);
+#endif
+
 #elif !defined(NO_OPEN_3)
   fd = open(FileName, Flags, my_umask);	/* Normal unix */
 #else
@@ -167,3 +173,181 @@
 	     FileName, my_errno);
   return(fd);
 }
+
+#ifdef __WIN__
+
+extern void __cdecl _dosmaperr(unsigned long);
+
+/*
+  Open a file with sharing. Similar to _sopen() from libc, but allows managing
+  share delete on win32
+
+  SYNOPSIS
+    my_sopen()
+      path    fully qualified file name
+      oflag   operation flags
+      shflag	share flag
+      pmode   permission flags
+
+  RETURN VALUE
+    File descriptor of opened file if success
+    -1 and sets errno if fails.
+*/
+
+File my_sopen(const char *path, int oflag, int shflag, int pmode)
+{
+  int  fh;                                /* handle of opened file */
+  int mask;
+  HANDLE osfh;                            /* OS handle of opened file */
+  DWORD fileaccess;                       /* OS file access (requested) */
+  DWORD fileshare;                        /* OS file sharing mode */
+  DWORD filecreate;                       /* OS method of opening/creating */
+  DWORD fileattrib;                       /* OS file attribute flags */
+  SECURITY_ATTRIBUTES SecurityAttributes;
+
+  SecurityAttributes.nLength= sizeof(SecurityAttributes);
+  SecurityAttributes.lpSecurityDescriptor= NULL;
+  SecurityAttributes.bInheritHandle= !(oflag & _O_NOINHERIT);
+
+  /*
+   * decode the access flags
+   */
+  switch (oflag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {
+    case _O_RDONLY:         /* read access */
+      fileaccess= GENERIC_READ;
+      break;
+    case _O_WRONLY:         /* write access */
+      fileaccess= GENERIC_WRITE;
+      break;
+    case _O_RDWR:           /* read and write access */
+      fileaccess= GENERIC_READ | GENERIC_WRITE;
+      break;
+    default:                /* error, bad oflag */
+      errno= EINVAL;
+      _doserrno= 0L;        /* not an OS error */
+      return -1;
+  }
+
+  /*
+   * decode sharing flags
+   */
+  switch (shflag) {
+    case _SH_DENYRW:        /* exclusive access except delete */
+      fileshare= FILE_SHARE_DELETE;
+      break;
+    case _SH_DENYWR:        /* share read and delete access */
+      fileshare= FILE_SHARE_READ | FILE_SHARE_DELETE;
+      break;
+    case _SH_DENYRD:        /* share write and delete access */
+      fileshare= FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+      break;
+    case _SH_DENYNO:        /* share read, write and delete access */
+      fileshare= FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+      break;
+    case _SH_DENYRWD:       /* exclusive access */
+      fileshare= 0L;
+      break;
+    case _SH_DENYWRD:       /* share read access */
+      fileshare= FILE_SHARE_READ;
+      break;
+    case _SH_DENYRDD:       /* share write access */
+      fileshare= FILE_SHARE_WRITE;
+      break;
+    case _SH_DENYDEL:       /* share read and write access */
+      fileshare= FILE_SHARE_READ | FILE_SHARE_WRITE;
+      break;
+    default:                /* error, bad shflag */
+      errno= EINVAL;
+      _doserrno= 0L;        /* not an OS error */
+      return -1;
+  }
+
+  /*
+   * decode open/create method flags
+   */
+  switch (oflag & (_O_CREAT | _O_EXCL | _O_TRUNC)) {
+    case 0:
+    case _O_EXCL:                   // ignore EXCL w/o CREAT
+      filecreate= OPEN_EXISTING;
+      break;
+
+    case _O_CREAT:
+      filecreate= OPEN_ALWAYS;
+      break;
+
+    case _O_CREAT | _O_EXCL:
+    case _O_CREAT | _O_TRUNC | _O_EXCL:
+      filecreate= CREATE_NEW;
+      break;
+
+    case _O_TRUNC:
+    case _O_TRUNC | _O_EXCL:        // ignore EXCL w/o CREAT
+      filecreate= TRUNCATE_EXISTING;
+      break;
+
+    case _O_CREAT | _O_TRUNC:
+      filecreate= CREATE_ALWAYS;
+      break;
+
+    default:
+      // this can't happen ... all cases are covered
+      errno= EINVAL;
+      _doserrno= 0L;
+      return -1;
+  }
+
+  /*
+   * decode file attribute flags if _O_CREAT was specified
+   */
+  fileattrib= FILE_ATTRIBUTE_NORMAL;     /* default */
+  if (oflag & _O_CREAT) 
+  {
+    _umask((mask= _umask(0)));
+    
+    if (!((pmode & ~mask) & _S_IWRITE))
+      fileattrib= FILE_ATTRIBUTE_READONLY;
+  }
+
+  /*
+   * Set temporary file (delete-on-close) attribute if requested.
+   */
+  if (oflag & _O_TEMPORARY) 
+  {
+    fileattrib|= FILE_FLAG_DELETE_ON_CLOSE;
+    fileaccess|= DELETE;
+  }
+
+  /*
+   * Set temporary file (delay-flush-to-disk) attribute if requested.
+   */
+  if (oflag & _O_SHORT_LIVED)
+    fileattrib|= FILE_ATTRIBUTE_TEMPORARY;
+
+  /*
+   * Set sequential or random access attribute if requested.
+   */
+  if (oflag & _O_SEQUENTIAL)
+    fileattrib|= FILE_FLAG_SEQUENTIAL_SCAN;
+  else if (oflag & _O_RANDOM)
+    fileattrib|= FILE_FLAG_RANDOM_ACCESS;
+
+  /*
+   * try to open/create the file
+   */
+  if ((osfh= CreateFile(path, fileaccess, fileshare, &SecurityAttributes, 
+                        filecreate, fileattrib, NULL)) == (HANDLE)0xffffffff)
+  {
+    /*
+     * OS call to open/create file failed! map the error, release
+     * the lock, and return -1. note that it's not necessary to
+     * call _free_osfhnd (it hasn't been used yet).
+     */
+    _dosmaperr(GetLastError());     /* map error */
+    return -1;                      /* return error to caller */
+  }
+
+  fh= _open_osfhandle((long)osfh, oflag & (_O_APPEND | _O_RDONLY | _O_TEXT));
+
+  return fh;                        /* return handle */
+}
+#endif /* __WIN__ */

--- 1.109/include/my_global.h	2005-09-23 17:46:59 +04:00
+++ 1.110/include/my_global.h	2005-11-03 19:26:26 +03:00
@@ -553,6 +553,15 @@
 #define O_NOFOLLOW      0
 #endif
 
+/* additional file share flags for win32 */
+#ifdef __WIN__
+#define _SH_DENYRWD     0x110    /* deny read/write mode & delete */
+#define _SH_DENYWRD     0x120    /* deny write mode & delete      */
+#define _SH_DENYRDD     0x130    /* deny read mode & delete       */
+#define _SH_DENYDEL     0x140    /* deny delete only              */
+#endif /* __WIN__ */
+
+
 /* #define USE_RECORD_LOCK	*/
 
 	/* Unsigned types supported by the compiler */
Thread
bk commit into 5.0 tree (SergeyV:1.2026) BUG#13377sergeyv3 Nov