OLD | NEW |
1 /* | 1 /* |
2 ** 2005 December 14 | 2 ** 2005 December 14 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 */ | 937 */ |
938 static int asyncFileControl(sqlite3_file *id, int op, void *pArg){ | 938 static int asyncFileControl(sqlite3_file *id, int op, void *pArg){ |
939 switch( op ){ | 939 switch( op ){ |
940 case SQLITE_FCNTL_LOCKSTATE: { | 940 case SQLITE_FCNTL_LOCKSTATE: { |
941 async_mutex_enter(ASYNC_MUTEX_LOCK); | 941 async_mutex_enter(ASYNC_MUTEX_LOCK); |
942 *(int*)pArg = ((AsyncFile*)id)->pData->lock.eLock; | 942 *(int*)pArg = ((AsyncFile*)id)->pData->lock.eLock; |
943 async_mutex_leave(ASYNC_MUTEX_LOCK); | 943 async_mutex_leave(ASYNC_MUTEX_LOCK); |
944 return SQLITE_OK; | 944 return SQLITE_OK; |
945 } | 945 } |
946 } | 946 } |
947 return SQLITE_ERROR; | 947 return SQLITE_NOTFOUND; |
948 } | 948 } |
949 | 949 |
950 /* | 950 /* |
951 ** Return the device characteristics and sector-size of the device. It | 951 ** Return the device characteristics and sector-size of the device. It |
952 ** is tricky to implement these correctly, as this backend might | 952 ** is tricky to implement these correctly, as this backend might |
953 ** not have an open file handle at this point. | 953 ** not have an open file handle at this point. |
954 */ | 954 */ |
955 static int asyncSectorSize(sqlite3_file *pFile){ | 955 static int asyncSectorSize(sqlite3_file *pFile){ |
956 UNUSED_PARAMETER(pFile); | 956 UNUSED_PARAMETER(pFile); |
957 return 512; | 957 return 512; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 sqlite3_vfs *pVfs = (sqlite3_vfs *)pAsyncVfs->pAppData; | 1037 sqlite3_vfs *pVfs = (sqlite3_vfs *)pAsyncVfs->pAppData; |
1038 AsyncFile *p = (AsyncFile *)pFile; | 1038 AsyncFile *p = (AsyncFile *)pFile; |
1039 int nName = 0; | 1039 int nName = 0; |
1040 int rc = SQLITE_OK; | 1040 int rc = SQLITE_OK; |
1041 int nByte; | 1041 int nByte; |
1042 AsyncFileData *pData; | 1042 AsyncFileData *pData; |
1043 AsyncLock *pLock = 0; | 1043 AsyncLock *pLock = 0; |
1044 char *z; | 1044 char *z; |
1045 int isAsyncOpen = doAsynchronousOpen(flags); | 1045 int isAsyncOpen = doAsynchronousOpen(flags); |
1046 | 1046 |
1047 /* If zName is NULL, then the upper layer is requesting an anonymous file */ | 1047 /* If zName is NULL, then the upper layer is requesting an anonymous file. |
| 1048 ** Otherwise, allocate enough space to make a copy of the file name (along |
| 1049 ** with the second nul-terminator byte required by xOpen). |
| 1050 */ |
1048 if( zName ){ | 1051 if( zName ){ |
1049 nName = (int)strlen(zName)+1; | 1052 nName = (int)strlen(zName); |
1050 } | 1053 } |
1051 | 1054 |
1052 nByte = ( | 1055 nByte = ( |
1053 sizeof(AsyncFileData) + /* AsyncFileData structure */ | 1056 sizeof(AsyncFileData) + /* AsyncFileData structure */ |
1054 2 * pVfs->szOsFile + /* AsyncFileData.pBaseRead and pBaseWrite */ | 1057 2 * pVfs->szOsFile + /* AsyncFileData.pBaseRead and pBaseWrite */ |
1055 nName /* AsyncFileData.zName */ | 1058 nName + 2 /* AsyncFileData.zName */ |
1056 ); | 1059 ); |
1057 z = sqlite3_malloc(nByte); | 1060 z = sqlite3_malloc(nByte); |
1058 if( !z ){ | 1061 if( !z ){ |
1059 return SQLITE_NOMEM; | 1062 return SQLITE_NOMEM; |
1060 } | 1063 } |
1061 memset(z, 0, nByte); | 1064 memset(z, 0, nByte); |
1062 pData = (AsyncFileData*)z; | 1065 pData = (AsyncFileData*)z; |
1063 z += sizeof(pData[0]); | 1066 z += sizeof(pData[0]); |
1064 pData->pBaseRead = (sqlite3_file*)z; | 1067 pData->pBaseRead = (sqlite3_file*)z; |
1065 z += pVfs->szOsFile; | 1068 z += pVfs->szOsFile; |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 assert(pData->lock.eAsyncLock>=pData->lock.eLock); | 1503 assert(pData->lock.eAsyncLock>=pData->lock.eLock); |
1501 rc = getFileLock(pData->pLock); | 1504 rc = getFileLock(pData->pLock); |
1502 async_mutex_leave(ASYNC_MUTEX_LOCK); | 1505 async_mutex_leave(ASYNC_MUTEX_LOCK); |
1503 } | 1506 } |
1504 break; | 1507 break; |
1505 } | 1508 } |
1506 | 1509 |
1507 case ASYNC_DELETE: | 1510 case ASYNC_DELETE: |
1508 ASYNC_TRACE(("DELETE %s\n", p->zBuf)); | 1511 ASYNC_TRACE(("DELETE %s\n", p->zBuf)); |
1509 rc = pVfs->xDelete(pVfs, p->zBuf, (int)p->iOffset); | 1512 rc = pVfs->xDelete(pVfs, p->zBuf, (int)p->iOffset); |
| 1513 if( rc==SQLITE_IOERR_DELETE_NOENT ) rc = SQLITE_OK; |
1510 break; | 1514 break; |
1511 | 1515 |
1512 case ASYNC_OPENEXCLUSIVE: { | 1516 case ASYNC_OPENEXCLUSIVE: { |
1513 int flags = (int)p->iOffset; | 1517 int flags = (int)p->iOffset; |
1514 AsyncFileData *pData = p->pFileData; | 1518 AsyncFileData *pData = p->pFileData; |
1515 ASYNC_TRACE(("OPEN %s flags=%d\n", p->zBuf, (int)p->iOffset)); | 1519 ASYNC_TRACE(("OPEN %s flags=%d\n", p->zBuf, (int)p->iOffset)); |
1516 assert(pData->pBaseRead->pMethods==0 && pData->pBaseWrite->pMethods==0); | 1520 assert(pData->pBaseRead->pMethods==0 && pData->pBaseWrite->pMethods==0); |
1517 rc = pVfs->xOpen(pVfs, pData->zName, pData->pBaseRead, flags, 0); | 1521 rc = pVfs->xOpen(pVfs, pData->zName, pData->pBaseRead, flags, 0); |
1518 assert( holdingMutex==0 ); | 1522 assert( holdingMutex==0 ); |
1519 async_mutex_enter(ASYNC_MUTEX_QUEUE); | 1523 async_mutex_enter(ASYNC_MUTEX_QUEUE); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1688 } | 1692 } |
1689 | 1693 |
1690 default: | 1694 default: |
1691 return SQLITE_ERROR; | 1695 return SQLITE_ERROR; |
1692 } | 1696 } |
1693 return SQLITE_OK; | 1697 return SQLITE_OK; |
1694 } | 1698 } |
1695 | 1699 |
1696 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ASYNCIO) */ | 1700 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ASYNCIO) */ |
1697 | 1701 |
OLD | NEW |