my_os2file64.c File Reference


Classes

class  File64bit

Defines

#define EIO   EINVAL
#define ESPIPE   EBADSEEK

Functions

void _OS2errno (APIRET rc)
longlong _lseek64 (int fd, longlong offset, int seektype)
int _lock64 (int fd, int locktype, my_off_t start, my_off_t length, myf MyFlags)
int _sopen64 (const char *name, int oflag, int shflag, int mask)
APIRET _SetFileLocksL (HFILE hFile, PFILELOCKL pflUnlock, PFILELOCKL pflLock, ULONG timeout, ULONG flags)
int sopen (const char *name, int oflag, int shflag, int mask)
int read (int fd, void *buffer, unsigned int count)
int write (int fd, const void *buffer, unsigned int count)
int close (int fd)
int open (const char *name, int oflag)
int open (const char *name, int oflag, int mask)

Variables

File64bit initFile64bit
APIRET(* APIENTRY )(PCSZ pszFileName, PHFILE phf, PULONG pulAction, LONGLONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2)
unsigned char const errno_tab []

Define Documentation

#define EIO   EINVAL
 

#define ESPIPE   EBADSEEK
 


Function Documentation

int _lock64 int  fd,
int  locktype,
my_off_t  start,
my_off_t  length,
myf  MyFlags
 

00219 {
00220   FILELOCKL LockArea = {0,0}, UnlockArea = {0,0};
00221   ULONG     readonly = 0;
00222   APIRET    rc = -1;
00223 
00224   switch (locktype) {
00225   case F_UNLCK:
00226     UnlockArea.lOffset = start;
00227     UnlockArea.lRange = length ? length : LONGLONG_MAX;
00228     break;
00229 
00230   case F_RDLCK:
00231   case F_WRLCK:
00232     LockArea.lOffset = start;
00233     LockArea.lRange = length ? length : LONGLONG_MAX;
00234     readonly = (locktype == F_RDLCK ? 1 : 0);
00235     break;
00236 
00237   default:
00238     errno = EINVAL;
00239     rc = -1;
00240     break;
00241   }
00242 
00243   if (MyFlags & MY_DONT_WAIT)
00244   {
00245     rc = _SetFileLocksL( fd, &UnlockArea, &LockArea, 0, readonly);
00246     /* printf("fd %d, locktype %d, rc %d (dont_wait)\n", fd, locktype, rc); */
00247     if (rc == 33) {  /* Lock Violation */
00248 
00249       DBUG_PRINT("info",("Was locked, trying with timeout"));
00250       rc = _SetFileLocksL( fd, &UnlockArea, &LockArea, 1 * 1000, readonly);
00251       /* printf( "fd %d, locktype %d, rc %d (dont_wait with timeout)\n", fd, locktype, rc); */
00252     }
00253   }
00254   else
00255   {
00256     while (rc = _SetFileLocksL( fd, &UnlockArea, &LockArea, 0, readonly) &&
00257            (rc == 33))
00258     {
00259       printf(".");
00260       DosSleep(1 * 1000);
00261     }
00262     /* printf( "fd %d, locktype %d, rc %d (wait2)\n", fd, locktype, rc); */
00263   }
00264   if (!rc)
00265     return(0);                          /* NO_ERROR */
00266   _OS2errno( rc);                               /* set errno */
00267   return(-1);                                   /* lock failed */
00268 }

longlong _lseek64 int  fd,
longlong  offset,
int  seektype
 

00170 {
00171   APIRET   rc;
00172   longlong actual;
00173 
00174   if (_DosSetFilePtrL)
00175     rc = _DosSetFilePtrL( fd, offset, seektype, &actual);
00176   else
00177   {
00178     ULONG ulActual;
00179     rc = DosSetFilePtr( fd, (long) offset, seektype, &ulActual);
00180     actual = ulActual;
00181   }
00182 
00183   if (!rc)
00184     return( actual);                            /* NO_ERROR */
00185 
00186   _OS2errno( rc);                               /* set errno */
00187   return(-1);                                   /* seek failed */
00188 }

void _OS2errno APIRET  rc  ) 
 

00161 {
00162   if (rc >= sizeof (errno_tab))
00163     errno = EINVAL;
00164   else
00165     errno = errno_tab[rc];
00166 }

APIRET _SetFileLocksL HFILE  hFile,
PFILELOCKL  pflUnlock,
PFILELOCKL  pflLock,
ULONG  timeout,
ULONG  flags
[inline]
 

00196 {
00197   if (_DosSetFileLocksL)
00198   {
00199     APIRET rc;
00200     rc = _DosSetFileLocksL( hFile, pflUnlock, pflLock, timeout, flags);
00201 
00202     /*
00203       on FAT/HPFS/LAN a INVALID_PARAMETER is returned, seems that
00204       only JFS can handle >2GB ranges.
00205     */
00206     if (rc != 87)
00207       return rc;
00208     /* got INVALID_PARAMETER, fallback to standard call */
00209   }
00210 
00211   FILELOCK flUnlock = { pflUnlock->lOffset, pflUnlock->lRange };
00212   FILELOCK flLock = { pflLock->lOffset, pflLock->lRange };
00213   return DosSetFileLocks( hFile, &flUnlock, &flLock, timeout, flags);
00214 }

int _sopen64 const char *  name,
int  oflag,
int  shflag,
int  mask
 

int close int  fd  ) 
 

00372 {
00373   APIRET   rc;
00374   ULONG    actual;
00375 
00376   rc = DosClose( fd);
00377 
00378   if (!rc)
00379     return( 0);                                 /* NO_ERROR */
00380   _OS2errno( rc);                               /* set errno */
00381   return(-1);                                   /* close failed */
00382 }

int open const char *  name,
int  oflag,
int  mask
 

00392 {
00393    return sopen( name, oflag, OPEN_SHARE_DENYNONE, mask);
00394 }

int open const char *  name,
int  oflag
 

00386 {
00387    return sopen( name, oflag, OPEN_SHARE_DENYNONE, S_IREAD | S_IWRITE);
00388 }

int read int  fd,
void *  buffer,
unsigned int  count
 

00344 {
00345   APIRET   rc;
00346   ULONG    actual;
00347 
00348   rc= DosRead( fd, (PVOID) buffer, count, &actual);
00349 
00350   if (!rc)
00351     return( actual);                            /* NO_ERROR */
00352   _OS2errno( rc);                               /* set errno */
00353   return(-1);                                   /* read failed */
00354 }

int sopen const char *  name,
int  oflag,
int  shflag,
int  mask
 

00272 {
00273   int       fail_errno;
00274   APIRET   rc = 0;
00275   HFILE    hf = 0;
00276   ULONG    ulAction = 0;
00277   LONGLONG cbFile = 0;
00278   ULONG    ulAttribute = FILE_NORMAL;
00279   ULONG    fsOpenFlags = 0;
00280   ULONG    fsOpenMode = 0;
00281 
00282   /* Extract the access mode and sharing mode bits. */
00283   fsOpenMode = (shflag & 0xFF) | (oflag & 0x03);
00284 
00285   /*
00286     Translate ERROR_OPEN_FAILED to ENOENT unless O_EXCL is set (see
00287     below).
00288   */
00289   fail_errno = ENOENT;
00290 
00291   /*
00292     Compute `open_flag' depending on `flags'.  Note that _SO_CREAT is
00293     set for O_CREAT.
00294   */
00295 
00296   if (oflag & O_CREAT)
00297   {
00298     if (oflag & O_EXCL)
00299     {
00300       fsOpenFlags = OPEN_ACTION_FAIL_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
00301       fail_errno = EEXIST;
00302     }
00303     else if (oflag & O_TRUNC)
00304       fsOpenFlags = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
00305     else
00306       fsOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
00307 
00308     if (mask & S_IWRITE)
00309       ulAttribute = FILE_NORMAL;
00310     else
00311       ulAttribute = FILE_READONLY;
00312 
00313   }
00314   else if (oflag & O_TRUNC)
00315     fsOpenFlags = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
00316   else
00317     fsOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
00318 
00319   /* Try to open the file and handle errors. */
00320   if (_DosOpenL)
00321     rc = _DosOpenL( name, &hf, &ulAction, cbFile,
00322                     ulAttribute, fsOpenFlags, fsOpenMode, NULL);
00323   else
00324     rc = DosOpen( name, &hf, &ulAction, (LONG) cbFile,
00325                   ulAttribute, fsOpenFlags, fsOpenMode, NULL);
00326 
00327   if (rc == ERROR_OPEN_FAILED)
00328   {
00329     errno = fail_errno;
00330     return -1;
00331   }
00332   if (rc != 0)
00333   {
00334     _OS2errno( rc);      /* set errno */
00335     return -1;
00336   }
00337   if (oflag & O_APPEND)
00338     _lseek64( hf, 0L, SEEK_END);
00339   return hf;
00340 }

int write int  fd,
const void *  buffer,
unsigned int  count
 

00358 {
00359   APIRET   rc;
00360   ULONG    actual;
00361 
00362   rc = DosWrite( fd, (PVOID) buffer, count, &actual);
00363 
00364   if (!rc)
00365     return( actual);                            /* NO_ERROR */
00366   _OS2errno( rc);                               /* set errno */
00367   return(-1);                                   /* write failed */
00368 }


Variable Documentation

APIRET(* APIENTRY)(HFILE hFile, PFILELOCKL pflUnlock, PFILELOCKL pflLock, ULONG timeout, ULONG flags) [static]
 

unsigned char const errno_tab[] [static]
 

class File64bit initFile64bit
 


Generated on Thu Feb 24 10:45:52 2005 for MySQL by  doxygen 1.3.9.1