blob: 5fdfc2ff4ce17cb63f0378bc0fd41afc2dcbaf3c [file] [log] [blame]
drhbbd42a62004-05-22 17:41:58 +00001/*
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/*
drh2b4b5962005-06-15 17:47:55 +000055** 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/*
drhbbd42a62004-05-22 17:41:58 +000066** 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.
danielk197713adf8a2004-06-03 16:08:41 +000070**
71** OsFile.locktype takes one of the values SHARED_LOCK, RESERVED_LOCK,
72** PENDING_LOCK or EXCLUSIVE_LOCK.
drhbbd42a62004-05-22 17:41:58 +000073*/
74typedef struct OsFile OsFile;
75struct OsFile {
drhd5b447d2004-07-19 22:08:09 +000076 struct Pager *pPager; /* The pager that owns this OsFile. Might be 0 */
drhbbd42a62004-05-22 17:41:58 +000077 struct openCnt *pOpen; /* Info about all open fd's on this inode */
78 struct lockInfo *pLock; /* Info about locks on this inode */
drha6abd042004-06-09 17:37:22 +000079 int h; /* The file descriptor */
drhda71ce12004-06-21 18:14:45 +000080 unsigned char locktype; /* The type of lock held on this fd */
81 unsigned char isOpen; /* True if needs to be closed */
drhb851b2c2005-03-10 14:11:12 +000082 unsigned char fullSync; /* Use F_FULLSYNC if available */
drhbbd42a62004-05-22 17:41:58 +000083 int dirfd; /* File descriptor for the directory */
drh2b4b5962005-06-15 17:47:55 +000084#ifdef SQLITE_UNIX_THREADS
85 pthread_t tid; /* The thread authorized to use this OsFile */
86#endif
drhbbd42a62004-05-22 17:41:58 +000087};
88
89/*
drhb851b2c2005-03-10 14:11:12 +000090** A macro to set the OsFile.fullSync flag, if it exists.
91*/
92#define SET_FULLSYNC(x,y) ((x).fullSync = (y))
93
94/*
drhbbd42a62004-05-22 17:41:58 +000095** 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
drh8e855772005-05-17 11:25:31 +0000108/*
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
drhbbd42a62004-05-22 17:41:58 +0000115
116#endif /* _SQLITE_OS_UNIX_H_ */