Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Use the pread()/pwrite() interface on Posix if compiled with -DUSE_PREAD=1. Note that on Linux this is slower and does not work for large files. (CVS 3147) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
5a24f61981df4d8b696f03372eba2d37 |
User & Date: | drh 2006-03-23 22:42:20.000 |
Context
2006-03-23
| ||
23:29 | Get autovacuum and in-memory databases working together. Ticket #1727. (CVS 3148) (check-in: 21446df642 user: drh tags: trunk) | |
22:42 | Use the pread()/pwrite() interface on Posix if compiled with -DUSE_PREAD=1. Note that on Linux this is slower and does not work for large files. (CVS 3147) (check-in: 5a24f61981 user: drh tags: trunk) | |
14:03 | Improvements to comments. No changes to code. (CVS 3146) (check-in: 01e164da67 user: drh tags: trunk) | |
Changes
Changes to src/os_unix.c.
︙ | ︙ | |||
76 77 78 79 80 81 82 83 84 85 86 87 88 89 | struct openCnt *pOpen; /* Info about all open fd's on this inode */ struct lockInfo *pLock; /* Info about locks on this inode */ int h; /* The file descriptor */ unsigned char locktype; /* The type of lock held on this fd */ unsigned char isOpen; /* True if needs to be closed */ unsigned char fullSync; /* Use F_FULLSYNC if available */ int dirfd; /* File descriptor for the directory */ #ifdef SQLITE_UNIX_THREADS pthread_t tid; /* The thread that "owns" this OsFile */ #endif }; /* ** Provide the ability to override some OS-layer functions during | > | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | struct openCnt *pOpen; /* Info about all open fd's on this inode */ struct lockInfo *pLock; /* Info about locks on this inode */ int h; /* The file descriptor */ unsigned char locktype; /* The type of lock held on this fd */ unsigned char isOpen; /* True if needs to be closed */ unsigned char fullSync; /* Use F_FULLSYNC if available */ int dirfd; /* File descriptor for the directory */ i64 offset; /* Seek offset */ #ifdef SQLITE_UNIX_THREADS pthread_t tid; /* The thread that "owns" this OsFile */ #endif }; /* ** Provide the ability to override some OS-layer functions during |
︙ | ︙ | |||
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 | if( zBuf[0]==0 ) return 0; if( stat(zBuf, &buf) ) return 0; if( !S_ISDIR(buf.st_mode) ) return 0; if( access(zBuf, 07) ) return 0; #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ return 1; } /* ** Read data from a file into a buffer. Return SQLITE_OK if all ** bytes were read successfully and SQLITE_IOERR if anything goes ** wrong. */ static int unixRead(OsFile *id, void *pBuf, int amt){ int got; assert( id ); SimulateIOError(SQLITE_IOERR); TIMER_START; | > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > | | 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 | if( zBuf[0]==0 ) return 0; if( stat(zBuf, &buf) ) return 0; if( !S_ISDIR(buf.st_mode) ) return 0; if( access(zBuf, 07) ) return 0; #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ return 1; } /* ** Seek to the offset in id->offset then read cnt bytes into pBuf. ** Return the number of bytes actually read. Update the offset. */ static int seekAndRead(unixFile *id, void *pBuf, int cnt){ int got; #ifdef USE_PREAD got = pread(id->h, pBuf, cnt, id->offset); #else lseek(id->h, id->offset, SEEK_SET); got = read(id->h, pBuf, cnt); #endif if( got>0 ){ id->offset += got; } return got; } /* ** Read data from a file into a buffer. Return SQLITE_OK if all ** bytes were read successfully and SQLITE_IOERR if anything goes ** wrong. */ static int unixRead(OsFile *id, void *pBuf, int amt){ int got; assert( id ); SimulateIOError(SQLITE_IOERR); TIMER_START; got = seekAndRead((unixFile*)id, pBuf, amt); TIMER_END; TRACE5("READ %-3d %5d %7d %d\n", ((unixFile*)id)->h, got, last_page, TIMER_ELAPSED); SEEK(0); /* if( got<0 ) got = 0; */ if( got==amt ){ return SQLITE_OK; }else{ return SQLITE_IOERR; } } /* ** Seek to the offset in id->offset then read cnt bytes into pBuf. ** Return the number of bytes actually read. Update the offset. */ static int seekAndWrite(unixFile *id, const void *pBuf, int cnt){ int got; #ifdef USE_PREAD got = pwrite(id->h, pBuf, cnt, id->offset); #else lseek(id->h, id->offset, SEEK_SET); got = write(id->h, pBuf, cnt); #endif if( got>0 ){ id->offset += got; } return got; } /* ** Write data from a buffer into a file. Return SQLITE_OK on success ** or some other error code on failure. */ static int unixWrite(OsFile *id, const void *pBuf, int amt){ int wrote = 0; assert( id ); assert( amt>0 ); SimulateIOError(SQLITE_IOERR); SimulateDiskfullError; TIMER_START; while( amt>0 && (wrote = seekAndWrite((unixFile*)id, pBuf, amt))>0 ){ amt -= wrote; pBuf = &((char*)pBuf)[wrote]; } TIMER_END; TRACE5("WRITE %-3d %5d %7d %d\n", ((unixFile*)id)->h, wrote, last_page, TIMER_ELAPSED); SEEK(0); |
︙ | ︙ | |||
957 958 959 960 961 962 963 | */ static int unixSeek(OsFile *id, i64 offset){ assert( id ); SEEK(offset/1024 + 1); #ifdef SQLITE_TEST if( offset ) SimulateDiskfullError #endif | | | 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | */ static int unixSeek(OsFile *id, i64 offset){ assert( id ); SEEK(offset/1024 + 1); #ifdef SQLITE_TEST if( offset ) SimulateDiskfullError #endif ((unixFile*)id)->offset = offset; return SQLITE_OK; } #ifdef SQLITE_TEST /* ** Count the number of fullsyncs and normal syncs. This is used to test ** that syncs and fullsyncs are occuring at the right times. |
︙ | ︙ | |||
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 | ** OsFile. If we run out of memory, close the file and return NULL. */ static int allocateUnixFile(unixFile *pInit, OsFile **pId){ unixFile *pNew; pInit->dirfd = -1; pInit->fullSync = 0; pInit->locktype = 0; SET_THREADID(pInit); pNew = sqlite3ThreadSafeMalloc( sizeof(unixFile) ); if( pNew==0 ){ close(pInit->h); sqlite3OsEnterMutex(); releaseLockInfo(pInit->pLock); releaseOpenCnt(pInit->pOpen); | > | 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 | ** OsFile. If we run out of memory, close the file and return NULL. */ static int allocateUnixFile(unixFile *pInit, OsFile **pId){ unixFile *pNew; pInit->dirfd = -1; pInit->fullSync = 0; pInit->locktype = 0; pInit->offset = 0; SET_THREADID(pInit); pNew = sqlite3ThreadSafeMalloc( sizeof(unixFile) ); if( pNew==0 ){ close(pInit->h); sqlite3OsEnterMutex(); releaseLockInfo(pInit->pLock); releaseOpenCnt(pInit->pOpen); |
︙ | ︙ |