Make the "unix-excl" VFS work exactly like "unix" if the database

file is read-only.

FossilOrigin-Name: d9846834993079fb2e42d6bd2644b2154ef324d1
This commit is contained in:
drh 2011-03-15 19:08:48 +00:00
parent 77ec9ba3f8
commit 7719711b81
3 changed files with 31 additions and 17 deletions

View File

@ -1,8 +1,8 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Fix\san\sout-of-order\svariable\sdeclaration\sin\sshell.c.
D 2011-03-15T18:35:44.256
C Make\sthe\s"unix-excl"\sVFS\swork\sexactly\slike\s"unix"\sif\sthe\sdatabase\nfile\sis\sread-only.
D 2011-03-15T19:08:48.027
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -165,7 +165,7 @@ F src/os.c 22ac61d06e72a0dac900400147333b07b13d8e1d
F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 2596fd2d5d0976c6c0c628d0c3c7c4e7a724f4cf
F src/os_unix.c 1debf5ea6efd0f35335a2a615198a7a1017ffd4b
F src/os_unix.c 919972244dd7267815f9fc176b662390ff0b2348
F src/os_win.c 24d72407a90551969744cf9bcbb1b4c72c5fa845
F src/pager.c 6aa906b60a59664ba58d3f746164bb010d407ce1
F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1
@ -916,14 +916,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P def98fd23e42bda13547e38ab13fed0e6554ce99
R 2ceb7e2495de2e32fa2e2aca83b58f09
P 725708465072fc63736e99610cc9cb0ac336145a
R c6fd073182d6b083be2e4d503e5f99b8
U drh
Z e7ee1c18a6d623c4d19a0ae664dea8d8
Z 981ae6e8a2633665045ed876d4741a1e
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFNf7GDoxKgR168RlERAhc+AJ9qHfOaDlOtj2TqHpdpAXpIiMjRTwCeP6Tv
esEJjmOwgIx+D+pi9BcOh8Y=
=lte8
iD8DBQFNf7lCoxKgR168RlERAhprAJkB1y4SWHLxKnmODUA6QMdw7pgj8wCgi+YB
9Q1erlHqYv/DtUPtH7mUHBE=
=2haN
-----END PGP SIGNATURE-----

View File

@ -1 +1 @@
725708465072fc63736e99610cc9cb0ac336145a
d9846834993079fb2e42d6bd2644b2154ef324d1

View File

@ -247,6 +247,7 @@ struct unixFile {
** Allowed values for the unixFile.ctrlFlags bitmask:
*/
#define UNIXFILE_EXCL 0x01 /* Connections from one process only */
#define UNIXFILE_RDONLY 0x02 /* Connection is read only */
/*
** Include code that is common to all os_*.c files
@ -1192,20 +1193,26 @@ static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){
** Attempt to set a system-lock on the file pFile. The lock is
** described by pLock.
**
** If the pFile was opened from unix-excl, then the only lock ever
** obtained is an exclusive lock, and it is obtained exactly once
** If the pFile was opened read/write from unix-excl, then the only lock
** ever obtained is an exclusive lock, and it is obtained exactly once
** the first time any lock is attempted. All subsequent system locking
** operations become no-ops. Locking operations still happen internally,
** in order to coordinate access between separate database connections
** within this process, but all of that is handled in memory and the
** operating system does not participate.
**
** This function is a pass-through to fcntl(F_SETLK) if pFile is using
** any VFS other than "unix-excl" or if pFile is opened on "unix-excl"
** and is read-only.
*/
static int unixFileLock(unixFile *pFile, struct flock *pLock){
int rc;
unixInodeInfo *pInode = pFile->pInode;
assert( unixMutexHeld() );
assert( pInode!=0 );
if( (pFile->ctrlFlags & UNIXFILE_EXCL)!=0 || pInode->bProcessLock ){
if( ((pFile->ctrlFlags & UNIXFILE_EXCL)!=0 || pInode->bProcessLock)
&& ((pFile->ctrlFlags & UNIXFILE_RDONLY)==0)
){
if( pInode->bProcessLock==0 ){
struct flock lock;
assert( pInode->nLock==0 );
@ -4402,7 +4409,8 @@ static int fillInUnixFile(
sqlite3_file *pId, /* Write to the unixFile structure here */
const char *zFilename, /* Name of the file being opened */
int noLock, /* Omit locking if true */
int isDelete /* Delete on close if true */
int isDelete, /* Delete on close if true */
int isReadOnly /* True if the file is opened read-only */
){
const sqlite3_io_methods *pLockingStyle;
unixFile *pNew = (unixFile *)pId;
@ -4435,6 +4443,9 @@ static int fillInUnixFile(
}else{
pNew->ctrlFlags = 0;
}
if( isReadOnly ){
pNew->ctrlFlags |= UNIXFILE_RDONLY;
}
#if OS_VXWORKS
pNew->pId = vxworksFindFileId(zFilename);
@ -4942,6 +4953,7 @@ static int unixOpen(
openFlags &= ~(O_RDWR|O_CREAT);
flags |= SQLITE_OPEN_READONLY;
openFlags |= O_RDONLY;
isReadonly = 1;
fd = robust_open(zName, openFlags, openMode);
}
if( fd<0 ){
@ -5038,7 +5050,8 @@ static int unixOpen(
useProxy = !(fsInfo.f_flags&MNT_LOCAL);
}
if( useProxy ){
rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock, isDelete);
rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock,
isDelete, isReadonly);
if( rc==SQLITE_OK ){
rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
if( rc!=SQLITE_OK ){
@ -5055,7 +5068,8 @@ static int unixOpen(
}
#endif
rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock, isDelete);
rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock,
isDelete, isReadonly);
open_finished:
if( rc!=SQLITE_OK ){
sqlite3_free(p->pUnused);
@ -5717,7 +5731,7 @@ static int proxyCreateUnixFile(
pUnused->flags = openFlags;
pNew->pUnused = pUnused;
rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0);
rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0, 0);
if( rc==SQLITE_OK ){
*ppFile = pNew;
return SQLITE_OK;