⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_os2.c

📁 嵌入式数据系统软件!
💻 C
📖 第 1 页 / 共 3 页
字号:
    }  }  /* Acquire a shared lock  */  if( locktype==SHARED_LOCK && res == NO_ERROR ){    assert( pFile->locktype==NO_LOCK );    res = getReadLock(pFile);    if( res == NO_ERROR ){      newLocktype = SHARED_LOCK;    }    OSTRACE3( "LOCK %d acquire shared lock. res=%d\n", pFile->h, res );  }  /* Acquire a RESERVED lock  */  if( locktype==RESERVED_LOCK && res == NO_ERROR ){    assert( pFile->locktype==SHARED_LOCK );    LockArea.lOffset = RESERVED_BYTE;    LockArea.lRange = 1L;    UnlockArea.lOffset = 0L;    UnlockArea.lRange = 0L;    res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );    if( res == NO_ERROR ){      newLocktype = RESERVED_LOCK;    }    OSTRACE3( "LOCK %d acquire reserved lock. res=%d\n", pFile->h, res );  }  /* Acquire a PENDING lock  */  if( locktype==EXCLUSIVE_LOCK && res == NO_ERROR ){    newLocktype = PENDING_LOCK;    gotPendingLock = 0;    OSTRACE2( "LOCK %d acquire pending lock. pending lock boolean unset.\n", pFile->h );  }  /* Acquire an EXCLUSIVE lock  */  if( locktype==EXCLUSIVE_LOCK && res == NO_ERROR ){    assert( pFile->locktype>=SHARED_LOCK );    res = unlockReadLock(pFile);    OSTRACE2( "unreadlock = %d\n", res );    LockArea.lOffset = SHARED_FIRST;    LockArea.lRange = SHARED_SIZE;    UnlockArea.lOffset = 0L;    UnlockArea.lRange = 0L;    res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );    if( res == NO_ERROR ){      newLocktype = EXCLUSIVE_LOCK;    }else{      OSTRACE2( "OS/2 error-code = %d\n", res );      getReadLock(pFile);    }    OSTRACE3( "LOCK %d acquire exclusive lock.  res=%d\n", pFile->h, res );  }  /* If we are holding a PENDING lock that ought to be released, then  ** release it now.  */  if( gotPendingLock && locktype==SHARED_LOCK ){    int r;    LockArea.lOffset = 0L;    LockArea.lRange = 0L;    UnlockArea.lOffset = PENDING_BYTE;    UnlockArea.lRange = 1L;    r = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );    OSTRACE3( "LOCK %d unlocking pending/is shared. r=%d\n", pFile->h, r );  }  /* Update the state of the lock has held in the file descriptor then  ** return the appropriate result code.  */  if( res == NO_ERROR ){    rc = SQLITE_OK;  }else{    OSTRACE4( "LOCK FAILED %d trying for %d but got %d\n", pFile->h,              locktype, newLocktype );    rc = SQLITE_BUSY;  }  pFile->locktype = newLocktype;  OSTRACE3( "LOCK %d now %d\n", pFile->h, pFile->locktype );  return rc;}/*** This routine checks if there is a RESERVED lock held on the specified** file by this or any other process. If such a lock is held, return** non-zero, otherwise zero.*/int os2CheckReservedLock( sqlite3_file *id ){  APIRET rc = NO_ERROR;  os2File *pFile = (os2File*)id;  assert( pFile!=0 );  if( pFile->locktype>=RESERVED_LOCK ){    rc = 1;    OSTRACE3( "TEST WR-LOCK %d %d (local)\n", pFile->h, rc );  }else{    FILELOCK  LockArea,              UnlockArea;    memset(&LockArea, 0, sizeof(LockArea));    memset(&UnlockArea, 0, sizeof(UnlockArea));    LockArea.lOffset = RESERVED_BYTE;    LockArea.lRange = 1L;    UnlockArea.lOffset = 0L;    UnlockArea.lRange = 0L;    rc = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );    OSTRACE3( "TEST WR-LOCK %d lock reserved byte rc=%d\n", pFile->h, rc );    if( rc == NO_ERROR ){      int r;      LockArea.lOffset = 0L;      LockArea.lRange = 0L;      UnlockArea.lOffset = RESERVED_BYTE;      UnlockArea.lRange = 1L;      r = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );      OSTRACE3( "TEST WR-LOCK %d unlock reserved byte r=%d\n", pFile->h, r );    }    OSTRACE3( "TEST WR-LOCK %d %d (remote)\n", pFile->h, rc );  }  return rc;}/*** Lower the locking level on file descriptor id to locktype.  locktype** must be either NO_LOCK or SHARED_LOCK.**** If the locking level of the file descriptor is already at or below** the requested locking level, this routine is a no-op.**** It is not possible for this routine to fail if the second argument** is NO_LOCK.  If the second argument is SHARED_LOCK then this routine** might return SQLITE_IOERR;*/int os2Unlock( sqlite3_file *id, int locktype ){  int type;  os2File *pFile = (os2File*)id;  APIRET rc = SQLITE_OK;  APIRET res = NO_ERROR;  FILELOCK  LockArea,            UnlockArea;  memset(&LockArea, 0, sizeof(LockArea));  memset(&UnlockArea, 0, sizeof(UnlockArea));  assert( pFile!=0 );  assert( locktype<=SHARED_LOCK );  OSTRACE4( "UNLOCK %d to %d was %d\n", pFile->h, locktype, pFile->locktype );  type = pFile->locktype;  if( type>=EXCLUSIVE_LOCK ){    LockArea.lOffset = 0L;    LockArea.lRange = 0L;    UnlockArea.lOffset = SHARED_FIRST;    UnlockArea.lRange = SHARED_SIZE;    res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );    OSTRACE3( "UNLOCK %d exclusive lock res=%d\n", pFile->h, res );    if( locktype==SHARED_LOCK && getReadLock(pFile) != NO_ERROR ){      /* This should never happen.  We should always be able to      ** reacquire the read lock */      OSTRACE3( "UNLOCK %d to %d getReadLock() failed\n", pFile->h, locktype );      rc = SQLITE_IOERR_UNLOCK;    }  }  if( type>=RESERVED_LOCK ){    LockArea.lOffset = 0L;    LockArea.lRange = 0L;    UnlockArea.lOffset = RESERVED_BYTE;    UnlockArea.lRange = 1L;    res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );    OSTRACE3( "UNLOCK %d reserved res=%d\n", pFile->h, res );  }  if( locktype==NO_LOCK && type>=SHARED_LOCK ){    res = unlockReadLock(pFile);    OSTRACE5( "UNLOCK %d is %d want %d res=%d\n", pFile->h, type, locktype, res );  }  if( type>=PENDING_LOCK ){    LockArea.lOffset = 0L;    LockArea.lRange = 0L;    UnlockArea.lOffset = PENDING_BYTE;    UnlockArea.lRange = 1L;    res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );    OSTRACE3( "UNLOCK %d pending res=%d\n", pFile->h, res );  }  pFile->locktype = locktype;  OSTRACE3( "UNLOCK %d now %d\n", pFile->h, pFile->locktype );  return rc;}/*** Control and query of the open file handle.*/static int os2FileControl(sqlite3_file *id, int op, void *pArg){  switch( op ){    case SQLITE_FCNTL_LOCKSTATE: {      *(int*)pArg = ((os2File*)id)->locktype;      OSTRACE3( "FCNTL_LOCKSTATE %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype );      return SQLITE_OK;    }  }  return SQLITE_ERROR;}/*** Return the sector size in bytes of the underlying block device for** the specified file. This is almost always 512 bytes, but may be** larger for some devices.**** SQLite code assumes this function cannot fail. It also assumes that** if two files are created in the same file-system directory (i.e.** a database and its journal file) that the sector size will be the** same for both.*/static int os2SectorSize(sqlite3_file *id){  return SQLITE_DEFAULT_SECTOR_SIZE;}/*** Return a vector of device characteristics.*/static int os2DeviceCharacteristics(sqlite3_file *id){  return 0;}/*** This vector defines all the methods that can operate on an** sqlite3_file for os2.*/static const sqlite3_io_methods os2IoMethod = {  1,                        /* iVersion */  os2Close,  os2Read,  os2Write,  os2Truncate,  os2Sync,  os2FileSize,  os2Lock,  os2Unlock,  os2CheckReservedLock,  os2FileControl,  os2SectorSize,  os2DeviceCharacteristics};/***************************************************************************** Here ends the I/O methods that form the sqlite3_io_methods object.**** The next block of code implements the VFS methods.****************************************************************************//*** Open a file.*/static int os2Open(  sqlite3_vfs *pVfs,            /* Not used */  const char *zName,            /* Name of the file */  sqlite3_file *id,             /* Write the SQLite file handle here */  int flags,                    /* Open mode flags */  int *pOutFlags                /* Status return flags */){  HFILE h;  ULONG ulFileAttribute = 0;  ULONG ulOpenFlags = 0;  ULONG ulOpenMode = 0;  os2File *pFile = (os2File*)id;  APIRET rc = NO_ERROR;  ULONG ulAction;  memset(pFile, 0, sizeof(*pFile));  OSTRACE2( "OPEN want %d\n", flags );  //ulOpenMode = flags & SQLITE_OPEN_READWRITE ? OPEN_ACCESS_READWRITE : OPEN_ACCESS_READONLY;  if( flags & SQLITE_OPEN_READWRITE ){    ulOpenMode |= OPEN_ACCESS_READWRITE;    OSTRACE1( "OPEN read/write\n" );  }else{    ulOpenMode |= OPEN_ACCESS_READONLY;    OSTRACE1( "OPEN read only\n" );  }  //ulOpenFlags = flags & SQLITE_OPEN_CREATE ? OPEN_ACTION_CREATE_IF_NEW : OPEN_ACTION_FAIL_IF_NEW;  if( flags & SQLITE_OPEN_CREATE ){    ulOpenFlags |= OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;    OSTRACE1( "OPEN open new/create\n" );  }else{    ulOpenFlags |= OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;    OSTRACE1( "OPEN open existing\n" );  }  //ulOpenMode |= flags & SQLITE_OPEN_MAIN_DB ? OPEN_SHARE_DENYNONE : OPEN_SHARE_DENYWRITE;  if( flags & SQLITE_OPEN_MAIN_DB ){    ulOpenMode |= OPEN_SHARE_DENYNONE;    OSTRACE1( "OPEN share read/write\n" );  }else{    ulOpenMode |= OPEN_SHARE_DENYWRITE;    OSTRACE1( "OPEN share read only\n" );  }  if( flags & (SQLITE_OPEN_TEMP_DB | SQLITE_OPEN_TEMP_JOURNAL               | SQLITE_OPEN_SUBJOURNAL) ){    //ulFileAttribute = FILE_HIDDEN;  //for debugging, we want to make sure it is deleted    ulFileAttribute = FILE_NORMAL;    pFile->delOnClose = 1;    pFile->pathToDel = (char*)malloc(sizeof(char) * pVfs->mxPathname);    sqlite3OsFullPathname(pVfs, zName, pVfs->mxPathname, pFile->pathToDel);    OSTRACE1( "OPEN hidden/delete on close file attributes\n" );  }else{    ulFileAttribute = FILE_ARCHIVED | FILE_NORMAL;    pFile->delOnClose = 0;    pFile->pathToDel = NULL;    OSTRACE1( "OPEN normal file attribute\n" );  }  //ulOpenMode |= flags & (SQLITE_OPEN_MAIN_DB | SQLITE_OPEN_TEMP_DB) ?  //                  OPEN_FLAGS_RANDOM : OPEN_FLAGS_SEQUENTIAL;  if( flags & (SQLITE_OPEN_MAIN_DB | SQLITE_OPEN_TEMP_DB) ){    ulOpenMode |= OPEN_FLAGS_RANDOM;    OSTRACE1( "OPEN random access\n" );  }else{    ulOpenMode |= OPEN_FLAGS_SEQUENTIAL;    OSTRACE1( "OPEN sequential access\n" );  }  ulOpenMode |= OPEN_FLAGS_FAIL_ON_ERROR;  rc = DosOpen( (PSZ)zName,                &h,                &ulAction,                0L,                ulFileAttribute,                ulOpenFlags,                ulOpenMode,                (PEAOP2)NULL );  if( rc != NO_ERROR ){    OSTRACE7( "OPEN Invalid handle rc=%d: zName=%s, ulAction=%#lx, ulAttr=%#lx, ulFlags=%#lx, ulMode=%#lx\n",              rc, zName, ulAction, ulFileAttribute, ulOpenFlags, ulOpenMode );    if( flags & SQLITE_OPEN_READWRITE ){      OSTRACE2( "OPEN %d Invalid handle\n", ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE) );      return os2Open( 0, zName, id,                      ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE),                      pOutFlags );    }else{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -