aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2011-12-17 16:09:16 +0000
committerdrh <drh@noemail.net>2011-12-17 16:09:16 +0000
commit1da88f025f3df80020872726071be8b0973901cb (patch)
treed7de0b3fe99edbc9cd3fd7cfde3c83a6c59619c6 /src/os_unix.c
parentfe6163d7cfbf5d61ca90611bcafada91fe5372ea (diff)
downloadsqlite-1da88f025f3df80020872726071be8b0973901cb.tar.gz
sqlite-1da88f025f3df80020872726071be8b0973901cb.zip
Add support for statvfs() in os_unix.c, for determining the sector size.
This causes many TCL test failures under Linux. FossilOrigin-Name: e0d44450b9bec8ea7b057c1ad0a2088cd3f1f221
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index ee5971f10..9f88d24b4 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -122,6 +122,10 @@
#ifndef SQLITE_OMIT_WAL
#include <sys/mman.h>
#endif
+#ifndef MISSING_STATVFS
+#include <sys/statvfs.h>
+#endif
+
#if SQLITE_ENABLE_LOCKING_STYLE
# include <sys/ioctl.h>
@@ -217,6 +221,7 @@ struct unixFile {
const char *zPath; /* Name of the file */
unixShm *pShm; /* Shared memory segment information */
int szChunk; /* Configured by FCNTL_CHUNK_SIZE */
+ int szSector; /* Sector size */
#if SQLITE_ENABLE_LOCKING_STYLE
int openFlags; /* The flags specified at open() */
#endif
@@ -414,6 +419,14 @@ static struct unix_syscall {
{ "rmdir", (sqlite3_syscall_ptr)rmdir, 0 },
#define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent)
+#if defined(MISSING_STATVFS)
+ { "statvfs", (sqlite3_syscall_ptr)0, 0 },
+#define osStatvfs ((int(*)(const char*,void*))aSyscall[20].pCurrent)
+#else
+ { "statvfs", (sqlite3_syscall_ptr)statvfs, 0 },
+#define osStatvfs ((int(*)(const char*,struct statvfs*))aSyscall[20].pCurrent)
+#endif
+
}; /* End of the overrideable system calls */
/*
@@ -3572,9 +3585,23 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
** a database and its journal file) that the sector size will be the
** same for both.
*/
-static int unixSectorSize(sqlite3_file *NotUsed){
- UNUSED_PARAMETER(NotUsed);
- return SQLITE_DEFAULT_SECTOR_SIZE;
+static int unixSectorSize(sqlite3_file *pFile){
+ unixFile *p = (unixFile*)pFile;
+ if( p->szSector==0 ){
+#ifdef MISSING_STATVFS
+ p->szSector = SQLITE_DEFAULT_SECTOR_SIZE;
+#else
+ struct statvfs x;
+ int sz;
+ memset(&x, 0, sizeof(x));
+ osStatvfs(p->zPath, &x);
+ p->szSector = sz = (int)x.f_frsize;
+ if( sz<512 || sz>65536 || (sz&(sz-1))!=0 ){
+ p->szSector = SQLITE_DEFAULT_SECTOR_SIZE;
+ }
+ }
+#endif
+ return p->szSector;
}
/*
@@ -6777,7 +6804,7 @@ int sqlite3_os_init(void){
/* Double-check that the aSyscall[] array has been constructed
** correctly. See ticket [bb3a86e890c8e96ab] */
- assert( ArraySize(aSyscall)==20 );
+ assert( ArraySize(aSyscall)==21 );
/* Register all VFSes defined in the aVfs[] array */
for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){