drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** 2004 May 22 |
| 3 | ** |
| 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
| 6 | ** |
| 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
| 10 | ** |
| 11 | ****************************************************************************** |
| 12 | ** |
| 13 | ** This header file defined OS-specific features for Unix. |
| 14 | */ |
| 15 | #ifndef _SQLITE_OS_UNIX_H_ |
| 16 | #define _SQLITE_OS_UNIX_H_ |
| 17 | |
| 18 | /* |
| 19 | ** Helpful hint: To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE |
| 20 | ** to the compiler command line. |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | ** These #defines should enable >2GB file support on Posix if the |
| 25 | ** underlying operating system supports it. If the OS lacks |
| 26 | ** large file support, or if the OS is windows, these should be no-ops. |
| 27 | ** |
| 28 | ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
| 29 | ** on the compiler command line. This is necessary if you are compiling |
| 30 | ** on a recent machine (ex: RedHat 7.2) but you want your code to work |
| 31 | ** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2 |
| 32 | ** without this option, LFS is enable. But LFS does not exist in the kernel |
| 33 | ** in RedHat 6.0, so the code won't work. Hence, for maximum binary |
| 34 | ** portability you should omit LFS. |
| 35 | ** |
| 36 | ** Similar is true for MacOS. LFS is only supported on MacOS 9 and later. |
| 37 | */ |
| 38 | #ifndef SQLITE_DISABLE_LFS |
| 39 | # define _LARGE_FILE 1 |
| 40 | # ifndef _FILE_OFFSET_BITS |
| 41 | # define _FILE_OFFSET_BITS 64 |
| 42 | # endif |
| 43 | # define _LARGEFILE_SOURCE 1 |
| 44 | #endif |
| 45 | |
| 46 | /* |
| 47 | ** standard include files. |
| 48 | */ |
| 49 | #include <sys/types.h> |
| 50 | #include <sys/stat.h> |
| 51 | #include <fcntl.h> |
| 52 | #include <unistd.h> |
| 53 | |
| 54 | /* |
drh | 2b4b596 | 2005-06-15 17:47:55 +0000 | [diff] [blame] | 55 | ** Macros used to determine whether or not to use threads. The |
| 56 | ** SQLITE_UNIX_THREADS macro is defined if we are synchronizing for |
| 57 | ** Posix threads and SQLITE_W32_THREADS is defined if we are |
| 58 | ** synchronizing using Win32 threads. |
| 59 | */ |
| 60 | #if defined(THREADSAFE) && THREADSAFE |
| 61 | # include <pthread.h> |
| 62 | # define SQLITE_UNIX_THREADS 1 |
| 63 | #endif |
| 64 | |
| 65 | /* |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 66 | ** The OsFile structure is a operating-system independing representation |
| 67 | ** of an open file handle. It is defined differently for each architecture. |
| 68 | ** |
| 69 | ** This is the definition for Unix. |
danielk1977 | 13adf8a | 2004-06-03 16:08:41 +0000 | [diff] [blame] | 70 | ** |
| 71 | ** OsFile.locktype takes one of the values SHARED_LOCK, RESERVED_LOCK, |
| 72 | ** PENDING_LOCK or EXCLUSIVE_LOCK. |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 73 | */ |
| 74 | typedef struct OsFile OsFile; |
| 75 | struct OsFile { |
drh | d5b447d | 2004-07-19 22:08:09 +0000 | [diff] [blame] | 76 | struct Pager *pPager; /* The pager that owns this OsFile. Might be 0 */ |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 77 | struct openCnt *pOpen; /* Info about all open fd's on this inode */ |
| 78 | struct lockInfo *pLock; /* Info about locks on this inode */ |
drh | a6abd04 | 2004-06-09 17:37:22 +0000 | [diff] [blame] | 79 | int h; /* The file descriptor */ |
drh | da71ce1 | 2004-06-21 18:14:45 +0000 | [diff] [blame] | 80 | unsigned char locktype; /* The type of lock held on this fd */ |
| 81 | unsigned char isOpen; /* True if needs to be closed */ |
drh | b851b2c | 2005-03-10 14:11:12 +0000 | [diff] [blame] | 82 | unsigned char fullSync; /* Use F_FULLSYNC if available */ |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 83 | int dirfd; /* File descriptor for the directory */ |
drh | 2b4b596 | 2005-06-15 17:47:55 +0000 | [diff] [blame] | 84 | #ifdef SQLITE_UNIX_THREADS |
| 85 | pthread_t tid; /* The thread authorized to use this OsFile */ |
| 86 | #endif |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /* |
drh | b851b2c | 2005-03-10 14:11:12 +0000 | [diff] [blame] | 90 | ** A macro to set the OsFile.fullSync flag, if it exists. |
| 91 | */ |
| 92 | #define SET_FULLSYNC(x,y) ((x).fullSync = (y)) |
| 93 | |
| 94 | /* |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 95 | ** Maximum number of characters in a temporary file name |
| 96 | */ |
| 97 | #define SQLITE_TEMPNAME_SIZE 200 |
| 98 | |
| 99 | /* |
| 100 | ** Minimum interval supported by sqlite3OsSleep(). |
| 101 | */ |
| 102 | #if defined(HAVE_USLEEP) && HAVE_USLEEP |
| 103 | # define SQLITE_MIN_SLEEP_MS 1 |
| 104 | #else |
| 105 | # define SQLITE_MIN_SLEEP_MS 1000 |
| 106 | #endif |
| 107 | |
drh | 8e85577 | 2005-05-17 11:25:31 +0000 | [diff] [blame] | 108 | /* |
| 109 | ** Default permissions when creating a new file |
| 110 | */ |
| 111 | #ifndef SQLITE_DEFAULT_FILE_PERMISSIONS |
| 112 | # define SQLITE_DEFAULT_FILE_PERMISSIONS 0644 |
| 113 | #endif |
| 114 | |
drh | bbd42a6 | 2004-05-22 17:41:58 +0000 | [diff] [blame] | 115 | |
| 116 | #endif /* _SQLITE_OS_UNIX_H_ */ |