YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/* Associates a file descriptor with an existing operating-system file handle.*/
File my_open_osfhandle(HANDLE handle, int oflag)
{ int offset= -1;
uint i;
DBUG_ENTER("my_open_osfhandle");
File my_win_sopen(constchar *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 */
DBUG_ENTER("my_win_sopen");
if (check_if_legal_filename(path))
{
errno= EACCES;
DBUG_RETURN(-1);
}
/* 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;
DBUG_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;
DBUG_RETURN(-1);
}
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;
DBUG_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; elseif (oflag & _O_RANDOM)
fileattrib|= FILE_FLAG_RANDOM_ACCESS;
/* try to open/create the file */ if ((osfh= my_create_file_with_retries(path, fileaccess, fileshare,my_win_file_secattr(),
filecreate, fileattrib, NULL)) == INVALID_HANDLE_VALUE)
{
DWORD last_error= GetLastError(); if (last_error == ERROR_PATH_NOT_FOUND && strlen(path) >= MAX_PATH)
errno= ENAMETOOLONG; else
my_osmaperr(last_error); /* map error */
DBUG_RETURN(-1);
}
/* Get the file descriptor for stdin,stdout or stderr */ static File my_get_stdfile_descriptor(FILE *stream)
{
HANDLE hFile;
DWORD nStdHandle;
DBUG_ENTER("my_get_stdfile_descriptor");
retval= _fstati64(crt_fd, buf); if(retval == 0)
{ /* File size returned by stat is not accurate (may be outdated), fix it*/
GetFileSizeEx(hDup, (PLARGE_INTEGER) (&(buf->st_size)));
}
_close(crt_fd);
DBUG_RETURN(retval);
}
int my_win_stat( constchar *path, struct _stati64 *buf)
{
DBUG_ENTER("my_win_stat"); if(_stati64( path, buf) == 0)
{ /* File size returned by stat is not accurate (may be outdated), fix it*/
WIN32_FILE_ATTRIBUTE_DATA data; if (GetFileAttributesEx(path, GetFileExInfoStandard, &data))
{
LARGE_INTEGER li;
li.LowPart= data.nFileSizeLow;
li.HighPart= data.nFileSizeHigh;
buf->st_size= li.QuadPart;
}
DBUG_RETURN(0);
}
DBUG_RETURN(-1);
}
/* Dynamically load NtFlushBuffersFileEx, used in my_win_fsync_internal */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.