Merge branch 'master' into cde-next
[oweals/cde.git] / cde / lib / tt / mini_isam / isam.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: isam.h /main/3 1995/10/23 11:33:51 rswiston $                                                        */
28 /*
29 @(#)isam.h
30 1.17 90/01/20
31 SMI */
32
33 /*
34  * Copyright (c) 1988 by Sun Microsystems, Inc.
35  */
36
37 /*
38  * isam.h
39  *
40  * Description:
41  *      isam.h is to be included in NetISAM C application programs.
42  *
43  * Make sure all changes in this file are reflected in lib/db/tt_client_isam.h 
44  */
45
46
47 #ifndef _ISAM_H
48 #define _ISAM_H
49
50 #include <limits.h>
51 #ifndef LONG_BIT
52 #define LONG_BIT 32
53 #endif
54
55 extern short ldint();
56 extern long ldlong();
57 extern float ldfloat();
58 extern double lddbl();
59 extern short ldshort();
60 extern int ldchar(), stchar(), stlong(), stdbl();
61 extern int stint(short val, char *p);
62 extern int stfloat(float f, char *p);
63
64
65 extern int      iserrno;                     /* isam error number code */
66 extern long     isrecnum;                    /* record number of last call */
67 extern int      isreclen;                    /* used for variable length recs */
68 extern char     isstat1;                     /* cobol status characters */
69 extern char     isstat2;
70
71 #define CHARTYPE        0
72 #define CHARSIZE        1
73
74 #define INTTYPE         1
75 #define INTSIZE         2
76
77 #define LONGTYPE        2
78 #define LONGSIZE        LONG_BIT/8
79
80 #define DOUBLETYPE      3
81 #define DOUBLESIZE      8
82
83 #define FLOATTYPE       4
84 #define FLOATSIZE       4
85
86 #define BINTYPE         5
87 #define BINSIZE         1
88
89 #define MINTYPE         0
90 #define MAXTYPE         6
91
92 #define ISDESC          0x80                 /* add to make descending type */
93 #define TYPEMASK        0x7f                 /* type mask */
94
95 #define BYTEMASK        0xff                 /* mask for one byte */
96 #define BYTESHFT        8                    /* shift for one byte */
97
98 /* mode parameter in isread() and isstart() */
99
100 #define ISFIRST         0                    /* first record */
101 #define ISLAST          1                    /* last record */
102 #define ISNEXT          2                    /* next record */
103 #define ISPREV          3                    /* previous record */
104 #define ISCURR          4                    /* current record */
105
106 #define ISEQUAL         5                    /* equal value */
107 #define ISGREAT         6                    /* greater value */
108 #define ISGTEQ          7                    /* >= value */
109 #define ISLESS          8                    /* < */
110 #define ISLTEQ          9                    /* <= */
111
112 /* isopen, isbuild lock modes */
113 #define ISAUTOLOCK      0x200                /* automatic record lock */
114 #define ISMANULOCK      0x400                /* manual record lock */
115 #define ISEXCLLOCK      0x800                /* exclusive isam file lock */
116 #define ISFASTLOCK      0x4000               /* no locking when EXCLLOCK! */
117
118 /* isread lock modes */
119 #define ISLOCK          0x100                /* lock record before reading */
120 #define ISSKIPLOCK      0x1000               /* advance record pointer to */
121                                              /* locked record */
122 /* isstart lock mode for automatic record locking */
123 #define ISKEEPLOCK      0x2000               /* keep record locked */
124
125 /* Fix/Variable length records mode */
126 #define ISFIXLEN        0
127 #define ISVARLEN        0x10000
128
129 /* Access remote file via NFS */
130 #define ISNFS           0x20000
131
132
133 #define ISINPUT         0                    /* open for input only */
134 #define ISOUTPUT        1                    /* open for output only */
135 #define ISINOUT         2                    /* open for input and output */
136
137 #define MAXKEYSIZE      150                  /* max number of bytes in key */
138 #define NPARTS          8                    /* max number of key parts */
139
140 /*#define ISMAXRECLEN   8192    */           /* Maximum number of bytes in record */
141 #define ISMAXRECLEN     32767                /* 32K - 1 */
142 #define ISMINRECLEN        4                 /* Minimum number of bytes in record */
143
144 struct keypart {
145     unsigned short      kp_start;            /* starting byte of key part */
146     short       kp_leng;                     /* length in bytes */
147     short       kp_type;                     /* type of key part */
148 };
149
150 struct keydesc {
151     short       k_flags;                     /* flags */
152     short       k_nparts;                    /* number of parts in key */
153     struct keypart k_part[NPARTS];           /* each part */
154 };
155
156 /* The next three defines are for compatibility with X/OPEN */
157 #define k_start         k_part[0].kp_start
158 #define k_leng          k_part[0].kp_leng
159 #define k_type          k_part[0].kp_type
160
161 #define ISNODUPS        000                  /* no duplicates and  */
162                                              /* no compression */
163 #define ISDUPS          001                  /* duplicates allowed */
164 #define COMPRESS        020                  /* full compression */
165
166 struct dictinfo {
167     short       di_nkeys;                    /* number of keys defined */
168  unsigned short di_recsize;                  /* data record size */
169     short       di_idxsize;                  /* index record size */
170     long        di_nrecords;                 /* number of records in file */
171 };
172
173 /* msb in di_nkeys indicates that ISAM file supports variable length records */
174 #define DICTVARLENBIT   0x8000
175
176 /* mask to access the true number of keys */
177 #define DICTNKEYSMASK      (DICTVARLENBIT - 1) 
178                                                
179
180 #define ENOERROR          0                  /* No error */
181 #define EDUPL           100                  /* duplicate record */
182 #define ENOTOPEN        101                  /* file not open */
183 #define EBADARG         102                  /* illegal argument */
184 #define EBADKEY         103                  /* illegal key desc */
185 #define ETOOMANY        104                  /* too many files open */
186 #define EBADFILE        105                  /* bad ISAM file format */
187 #define ENOTEXCL        106                  /* non-exclusive access */
188 #define ELOCKED         107                  /* record locked */
189 #define EKEXISTS        108                  /* key already exists */
190 #define EPRIMKEY        109                  /* is primary key */
191 #define EENDFILE        110                  /* end/begin of file */
192 #define ENOREC          111                  /* no record found */
193 #define ENOCURR         112                  /* no current record */
194 #define EFLOCKED        113                  /* file locked */
195 #define EFNAME          114                  /* file name too long */
196 #define EBADMEM         116                  /* cannot allocate memory */
197
198 /* NetISAM specific error codes  non XOPEN compliant*/
199 #define ETIMEOUT        1117                 /* RPC timeout */
200 #define ERPC            1118                 /* Broken TCP/IP */
201 #define ETCP            1119                 /* Cannot connect to server */
202 #define EIMPORT         1120                 /* Cannot import */
203 #define ENODAEMON       1121                  /* no local daemon */
204 #define EFATAL          1122                  /* internal fatal error */
205 #define ELANG           1123                  /* Locale/LANG mismatch */
206
207
208 #define ISOK            0                    /* no error return code */
209 #define ISERROR         -1                   /* error return code */
210
211
212 extern struct keydesc *nokey;                /* May be used as parameter
213                                               * to isbuild() if no
214                                               * primary key is to be built
215                                               */
216
217 /* ischeckindex() diagmode values */
218 #define CHK_NODIAG      0                    /* do not print any messages */
219 #define CHK_DIAG        1                    /* Access Level module will print to stderr */
220
221 /* values of corrupt parameter of ischeckindex() */
222 #define CHK_OK          0                    /* ISAM file is not corrupted */
223 #define CHK_DAT         1                    /* .dat file is corrupted */
224 #define CHK_VAR         2                    /* .var file is corrupted */
225 #define CHK_IND         3                    /* .ind file is corrupted */
226
227
228 /* iscntl() definitions */
229 /* For one isfd - use iscntl(isfd, func, ...) */
230 #define ISCNTL_RPCS_TO_SET   1               /* short oper. timeout (in sec) */
231 #define ISCNTL_RPCS_TO_GET   2               /* short oper. timeout (in sec) */
232 #define ISCNTL_RPCL_TO_SET   3               /* long oper. timeout (in sec) */
233 #define ISCNTL_RPCL_TO_GET   4               /* long oper. timeout (in sec) */
234 #define ISCNTL_TCP_TO_SET    5               /* timeout to reconnect TCP?IP */
235 #define ISCNTL_TCP_TO_GET    6               /* timeout to reconnect TCP?IP */
236 #define ISCNTL_APPLMAGIC_WRITE 7             /* Write Appl. Magic */
237 #define ISCNTL_APPLMAGIC_READ  8             /* Read Appl. Magic */
238 #define ISCNTL_FSYNC            9            /* Flush pages to disk */
239 #define ISCNTL_FDLIMIT_SET      10           /* Set UNIX fd usage limit */
240 #define ISCNTL_FDLIMIT_GET      11           /* Get UNIX fd usage limit */
241 #define ISCNTL_FATAL    12                   /* Specify NetISAM fatal error hadler */
242 #define ISCNTL_MASKSIGNALS      13           /* Enable or Disable masking signals during NetISAM operations */
243
244 #define ISAPPLMAGICLEN          32
245
246 /*
247  * ALLISFD in iscntl() calls means that the operation should be done 
248  * on all open file descriptors, or the operation is not related to 
249  * any file descriptor (e.g: maskintg signals)
250  */
251 #define ALLISFD         (-2)    
252
253 /* isshowlocks() and isshowhostlocks() return an array of struct showlock */
254 #define IPADDRLEN       4                    /* IP address length */
255 struct showlock {
256     short       dev;                         /* Major/Minor device number,
257                                               * actually type dev_t */
258     long        inode;                       /* inode number */
259     long        recnum;                      /* record number */
260     char        hostid[IPADDRLEN];           /* IP address of host */
261     short       pid;                         /* UNIX process ID */
262     long        uid;                         /* User ID */
263     short       type;                        /* See below */
264 };
265
266
267 /* NetISAM Programmer Toolkit related definitions */
268         
269 struct isfldmap {
270         char    *flm_fldname;
271         short   flm_recoff;
272         short   flm_bufoff;
273         short   flm_type;
274         short   flm_length;
275 };
276
277 struct istableinfo {
278         char    *tbi_tablename;
279         int     tbi_reclength;
280         int     tbi_nfields;
281         struct isfldmap *tbi_fields;
282         int     tbi_nkeys;
283         struct keydesc *tbi_keys;
284         char    **tbi_keynames;
285 };
286
287 /* record descriptor isreadm/iswritem record descriptor */
288 struct recorddesc {
289         char    *rec_buffer;
290         long    rec_number;
291         short   rec_length;
292         short   rec_locked;
293 };
294
295 /*
296  * The following defines and variable definitions are not used by NetISAM 1.0.
297  * They are defined for compatibility with VSX 2.5.
298  */
299 #define EBADCOLL        (-1)
300
301 #define IO_OPEN         0x10                 /* open() */
302 #define IO_CREA         0x20                 /* creat() */
303 #define IO_SEEK         0x30                 /* lseek() */
304 #define IO_READ         0x40                 /* read() */
305 #define IO_WRIT         0x50                 /* write() */
306 #define IO_LOCK         0x60                 /* lockf() */
307 #define IO_IOCTL        0x70                 /* ioctl() */
308 #define IO_RENAME       0x80                 /* rename() */
309 #define IO_UNLINK       0x90                 /* unlink() */
310
311 extern int iserrio;
312
313
314 #endif /* !_ISAM_H */