ihandle: Refactor ih_open to split out ih_attachfd
[openafs.git] / src / vol / ihandle.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* An IHandle_t is an abstraction allowing the file and volume operations to
11  * pass the elements required to identify a file to the underlying file
12  * systen. For the usual Vice inode operations, this is no more than the
13  * usual device and inode numbers. For the user space file system used on NT
14  * we also need the volume id to identify the file.
15  *
16  * An FdHandle_t is an abstraction used to associate file descroptors
17  * with Inode handles. IH_OPEN is used to get a file descriptor that
18  * can be used in subsequent I/O operations. File descriptor handles are
19  * cached by IO_CLOSE. To make sure a file descriptor is really closed call
20  * IH_REALLYCLOSE.
21  *
22  * The IHandle_t also provides a place to do other optimizations. In the
23  * NT user space file system, we keep a separate special file for the
24  * link counts and using the IHandle_t allows keeping the details of
25  * that at a lower level than the IDEC and IINC calls.
26  *
27  * To use the IHandle_t there are a new set of IH_xxxx/FDH_XXXX operations.
28  * Each takes a pointer to an IHandle_t or an FdHandle_t as the first
29  * argument. This pointer is  considered an in/out variable. In particular,
30  * the open file descriptors for a given Inode are stored in a linked list
31  * of FdHandle_t hanging off of each IHandle_t. IH_OPEN returns NULL on error,
32  * and a valid FdHandle_t otherwise. All other IH_xxxx/FDH_xxxx macros return
33  * -1 on error and 0 on success.
34  *
35  * Inode handle operations:
36  * IH_INIT - Initialize the Inode handle with the device, volume id, and ino
37  * IH_COPY - Copy Inode handle info to a new handle with no open descriptors.
38  * IH_REALLYCLOSE - Close all cached file descriptors for Inode handle
39  * IH_RELEASE - release a Inode handle, close all cached file descriptors
40  * IH_CONDSYNC -  snyc the Inode if it has any open file descriptors
41  *
42  * Inode operation replacements:
43  * IH_CREATE - create a file in the underlying filesystem and setup the
44  *      information needed to reference this file in the IHandle_t.
45  * IH_OPEN - open the file belonging to the associated inode and set the
46  *      file descriptor.
47  * IH_IREAD/IH_IWRITE - read/write an Inode.
48  * IH_INC/IH_DEC - increment/decrement the link count.
49  *
50  * Replacements for C runtime file operations
51  * FDH_READ/FDH_WRITE - read/write using the file descriptor.
52  * FDH_READV/FDH_WRITEV - readv/writev (Unix only)
53  * FDH_SEEK - set file handle's read/write position
54  * FDH_CLOSE - return a file descriptor to the cache
55  * FDH_REALLYCLOSE - Close a file descriptor, do not return to the cache
56  * FDH_SYNC - Unconditionally sync an open file.
57  * FDH_TRUNC - Truncate a file
58  * FDH_LOCKFILE - Lock a whole file
59  * FDH_UNLOCKFILE - Unlock a whole file
60  *
61  * status information:
62  * FDH_SIZE - returns the size of the file.
63  * FDH_NLINK - returns the link count of the file.
64  * FDH_ISUNLINKED - returns if the file has been unlinked out from under us
65  *
66  * Miscellaneous:
67  * FDH_FDOPEN - create a descriptor for buffered I/O
68  * STREAM_READ/STREAM_WRITE - buffered file I/O
69  */
70
71 #ifndef _IHANDLE_H_
72 #define _IHANDLE_H_
73
74 #ifdef AFS_PTHREAD_ENV
75 # include <pthread.h>
76 extern pthread_once_t ih_glock_once;
77 extern pthread_mutex_t ih_glock_mutex;
78 extern void ih_glock_init(void);
79 # define IH_LOCK \
80     do { opr_Verify(pthread_once(&ih_glock_once, ih_glock_init) == 0);  \
81         opr_mutex_enter(&ih_glock_mutex); \
82     } while (0)
83 # define IH_UNLOCK opr_mutex_exit(&ih_glock_mutex)
84 #else /* AFS_PTHREAD_ENV */
85 # define IH_LOCK
86 # define IH_UNLOCK
87 #endif /* AFS_PTHREAD_ENV */
88
89 #ifndef DLL_INIT_LIST
90 /*
91  * Macro to initialize a doubly linked list, lifted from Encina
92  */
93 # define DLL_INIT_LIST(head, tail)      \
94     do {                                \
95         (head) = NULL;                  \
96         (tail) = NULL;                  \
97     } while(0)
98
99 /*
100  * Macro to remove an element from a doubly linked list
101  */
102 # define DLL_DELETE(ptr,head,tail,next,prev)    \
103     do {                                        \
104         if ((ptr)->next)                        \
105             (ptr)->next->prev = (ptr)->prev;    \
106         else                                    \
107             (tail) = (ptr)->prev;               \
108         if ((ptr)->prev)                        \
109             (ptr)->prev->next = (ptr)->next;    \
110         else                                    \
111             (head) = (ptr)->next;               \
112         (ptr)->next = (ptr)->prev = NULL;       \
113         opr_Assert(!(head) || !((head)->prev)); \
114     } while(0)
115
116 /*
117  * Macro to insert an element at the tail of a doubly linked list
118  */
119 # define DLL_INSERT_TAIL(ptr,head,tail,next,prev) \
120     do {                                         \
121         (ptr)->next = NULL;                      \
122         (ptr)->prev = (tail);                    \
123         (tail) = (ptr);                          \
124         if ((ptr)->prev)                         \
125             (ptr)->prev->next = (ptr);           \
126         else                                     \
127             (head) = (ptr);                      \
128         opr_Assert((head) && ((head)->prev == NULL));   \
129     } while(0)
130
131 #endif /* DLL_INIT_LIST */
132
133 #ifdef AFS_NT40_ENV
134 typedef __int64 Inode;
135 #else
136 # include <afs/afssyscalls.h>
137 #endif
138
139 /* The dir package's page hashing function is dependent upon the layout of
140  * IHandle_t as well as the containing DirHandle in viced/viced.h. Make
141  * Sure the volume id is still used as the hash after any changes to either
142  * structure.
143  */
144
145 /* forward declaration */
146 struct IHandle_s;
147
148 /* File descriptors are HANDLE's on NT. The following typedef helps catch
149  * type errors. duplicated in libadmin/vos/afs_vosAdmin.c
150  */
151 #ifdef AFS_NT40_ENV
152 typedef HANDLE FD_t;
153 # define INVALID_FD INVALID_HANDLE_VALUE
154 #else
155 typedef int FD_t;
156 # define INVALID_FD ((FD_t)-1)
157 #endif
158
159 /* file descriptor handle */
160 typedef struct FdHandle_s {
161     int fd_status;              /* status flags */
162     int fd_refcnt;              /* refcnt */
163     FD_t fd_fd;                 /* file descriptor */
164     struct IHandle_s *fd_ih;    /* Pointer to Inode handle */
165     struct FdHandle_s *fd_next; /* LRU/Avail list pointers */
166     struct FdHandle_s *fd_prev;
167     struct FdHandle_s *fd_ihnext;       /* Inode handle's list of file descriptors */
168     struct FdHandle_s *fd_ihprev;
169 } FdHandle_t;
170
171 /* File descriptor status values */
172 #define FD_HANDLE_AVAIL         1       /* handle is not open and available */
173 #define FD_HANDLE_OPEN          2       /* handle is open and not in use */
174 #define FD_HANDLE_INUSE         3       /* handle is open and in use */
175 #define FD_HANDLE_CLOSING       4       /* handle is open, in use, and has been
176                                          * IH_REALLYCLOSE'd. It should not be
177                                          * used for subsequent opens. */
178
179 /* buffered file descriptor handle */
180 #define STREAM_HANDLE_BUFSIZE   2048    /* buffer size for STR_READ/STR_WRITE */
181 typedef struct StreamHandle_s {
182     FD_t str_fd;                /* file descriptor */
183     int str_direction;          /* current read/write direction */
184     afs_sfsize_t str_buflen;    /* bytes remaining in buffer */
185     afs_foff_t str_bufoff;      /* current offset into buffer */
186     afs_foff_t str_fdoff;       /* current offset into file */
187     int str_error;              /* error code */
188     int str_eof;                /* end of file flag */
189     struct StreamHandle_s *str_next;    /* Avail list pointers */
190     struct StreamHandle_s *str_prev;
191     char str_buffer[STREAM_HANDLE_BUFSIZE];     /* data buffer */
192 } StreamHandle_t;
193
194 #define STREAM_DIRECTION_NONE   1       /* stream is in initial mode */
195 #define STREAM_DIRECTION_READ   2       /* stream is in input mode */
196 #define STREAM_DIRECTION_WRITE  3       /* stream is in output mode */
197
198 /* number handles allocated at a shot */
199 #define I_HANDLE_MALLOCSIZE     ((size_t)((4096/sizeof(IHandle_t))))
200 #define FD_HANDLE_MALLOCSIZE    ((size_t)((4096/sizeof(FdHandle_t))))
201 #define STREAM_HANDLE_MALLOCSIZE 1
202
203 /* Possible values for the vol_io_params.sync_behavior option.
204  * These dictate what actually happens when you call FDH_SYNC or IH_CONDSYNC. */
205 #define IH_SYNC_ALWAYS  (1) /* This makes FDH_SYNCs do what you'd probably
206                              * expect: a synchronous fsync() */
207 #define IH_SYNC_ONCLOSE (2) /* This makes FDH_SYNCs just flag the ih as "I
208                              * need to sync", and does not perform the actual
209                              * fsync() until we IH_REALLYCLOSE. This provides a
210                              * little assurance over IH_SYNC_NEVER when a volume
211                              * has gone offline, and a few other situations. */
212 #define IH_SYNC_NEVER   (3) /* This makes FDH_SYNCs do nothing. Faster, but
213                              * obviously less durable. The OS may ensure that
214                              * our data hits the disk eventually, depending on
215                              * the platform and various OS-specific tuning
216                              * parameters. */
217
218
219 /* READ THIS.
220  *
221  * On modern platforms tuned for I/O intensive workloads, there may be
222  * thousands of file descriptors available (64K on 32-bit Solaris 7,
223  * for example), and threading in Solaris 9 and Linux 2.6 (NPTL) are
224  * tuned for (many) thousands of concurrent threads at peak.
225  *
226  * On these platforms, it makes sense to allow administrators to set
227  * appropriate limits for their hardware.  Clients may now set desired
228  * values in the exported vol_io_params, of type ih_init_params.
229  */
230
231 typedef struct ih_init_params
232 {
233     afs_uint32 fd_handle_setaside; /* for non-cached i/o, trad. was 128 */
234     afs_uint32 fd_initial_cachesize; /* what was 'default' */
235     afs_uint32 fd_max_cachesize; /* max open files if large-cache activated */
236
237     int sync_behavior; /* one of the IH_SYNC_* constants */
238 } ih_init_params;
239
240 /* Number of file descriptors needed for non-cached I/O */
241 #define FD_HANDLE_SETASIDE      128 /* Match to MAX_FILESERVER_THREAD */
242
243 /* Which systems have 8-bit fileno?  On GNU/Linux systems, the
244  * fileno member of FILE is an int.  On NetBSD 5, it's a short.
245  * Ditto for OpenBSD 4.5. Through Solaris 10 8/07 it's unsigned char.
246  */
247
248 /* Don't try to have more than 256 files open at once if you are planning
249  * to use fopen or fdopen. The FILE structure has an eight bit field for
250  * the file descriptor.  */
251 #define FD_DEFAULT_CACHESIZE (255-FD_HANDLE_SETASIDE)
252
253 /* We need some limit on the number of files open at once. Some systems
254  * say we can open lots of files, but when we do they run out of slots
255  * in the file table.
256  */
257 #define FD_MAX_CACHESIZE (2000 - FD_HANDLE_SETASIDE)
258
259 /* On modern platforms, this is sized higher than the note implies.
260  * For HP, see http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1242508538748+28353475&threadId=302950
261  * On AIX, it's said to be self-tuning (sar -v)
262  * On Solaris, http://www.princeton.edu/~unix/Solaris/troubleshoot/kerntune.html
263  * says stdio limit (FILE) may exist, but then backtracks and says the 64bit
264  * solaris and POLL (rather than select) io avoid the issue.  Solaris Internals
265  * states that Solaris 7 and above deal with up to 64K on 32bit.
266  * However, extended FILE must be enabled to use this. See
267  * enable_extended_FILE_stdio(3C)
268  */
269
270 /* Inode handle */
271 typedef struct IHandle_s {
272     VolumeId ih_vid;            /* Parent volume id. */
273     int ih_dev;                 /* device id. */
274     int ih_flags;               /* Flags */
275     int ih_synced;              /* should be synced next time */
276     Inode ih_ino;               /* Inode number */
277     int ih_refcnt;              /* reference count */
278     struct FdHandle_s *ih_fdhead;       /* List of open file desciptors */
279     struct FdHandle_s *ih_fdtail;
280     struct IHandle_s *ih_next;  /* Links for avail list/hash chains */
281     struct IHandle_s *ih_prev;
282 } IHandle_t;
283
284 /* Flags for the Inode handle */
285 #define IH_REALLY_CLOSED                1
286
287 /* Hash function for inode handles */
288 #define I_HANDLE_HASH_SIZE      2048    /* power of 2 */
289
290 /* The casts to int's ensure NT gets the xor operation correct. */
291 #define IH_HASH(D, V, I) ((int)(((D)^(V)^((int)(I)))&(I_HANDLE_HASH_SIZE-1)))
292
293 /*
294  * Hash buckets for inode handles
295  */
296 typedef struct IHashBucket_s {
297     IHandle_t *ihash_head;
298     IHandle_t *ihash_tail;
299 } IHashBucket_t;
300
301 /* Prototypes for handle support routines. */
302 #ifdef AFS_NAMEI_ENV
303 # ifdef AFS_NT40_ENV
304 #  include "ntops.h"
305 # endif
306 # include "namei_ops.h"
307
308 extern void ih_clear(IHandle_t * h);
309 extern Inode ih_create(IHandle_t * h, int dev, char *part, Inode nI, int p1,
310                        int p2, int p3, int p4);
311 extern FD_t *ih_fdopen(FdHandle_t * h, char *fdperms);
312 #endif /* AFS_NAMEI_ENV */
313
314 /*
315  * Prototypes for file descriptor cache routines
316  */
317 extern void ih_PkgDefaults(void);
318 extern void ih_Initialize(void);
319 extern void ih_UseLargeCache(void);
320 extern int ih_SetSyncBehavior(const char *behavior);
321 extern IHandle_t *ih_init(int /*@alt Device@ */ dev, int /*@alt VolId@ */ vid,
322                           Inode ino);
323 extern IHandle_t *ih_copy(IHandle_t * ihP);
324 extern FdHandle_t *ih_open(IHandle_t * ihP);
325 extern int fd_close(FdHandle_t * fdP);
326 extern int fd_reallyclose(FdHandle_t * fdP);
327 extern StreamHandle_t *stream_fdopen(FD_t fd);
328 extern StreamHandle_t *stream_open(const char *file, const char *mode);
329 extern afs_sfsize_t stream_read(void *ptr, afs_fsize_t size,
330                                 afs_fsize_t nitems, StreamHandle_t * streamP);
331 extern afs_sfsize_t stream_write(void *ptr, afs_fsize_t size,
332                                  afs_fsize_t nitems,
333                                  StreamHandle_t * streamP);
334 extern int stream_aseek(StreamHandle_t * streamP, afs_foff_t offset);
335 extern int stream_flush(StreamHandle_t * streamP);
336 extern int stream_close(StreamHandle_t * streamP, int reallyClose);
337 extern int ih_reallyclose(IHandle_t * ihP);
338 extern int ih_release(IHandle_t * ihP);
339 extern int ih_condsync(IHandle_t * ihP);
340 extern FdHandle_t *ih_attachfd(IHandle_t * ihP, FD_t fd);
341
342 /* Macros common to user space and inode API's. */
343 #define IH_INIT(H, D, V, I) ((H) = ih_init((D), (V), (I)))
344
345 #define IH_COPY(D, S) ((D) = ih_copy(S))
346
347 #define IH_NLINK(H) ih_nlink(H)
348
349 #define IH_OPEN(H) ih_open(H)
350
351 #define FDH_CLOSE(H) (fd_close(H), (H)=NULL, 0)
352
353 #define FDH_REALLYCLOSE(H) (fd_reallyclose(H), (H)=NULL, 0)
354
355 #define FDH_FDOPEN(H, A) stream_fdopen((H)->fd_fd)
356
357 #define STREAM_FDOPEN(A, B) stream_fdopen(A)
358
359 #define STREAM_OPEN(A, B) stream_open(A, B)
360
361 #define STREAM_READ(A, B, C, H) stream_read(A, B, C, H)
362
363 #define STREAM_WRITE(A, B, C, H) stream_write(A, B, C, H)
364
365 #define STREAM_ASEEK(H, A) stream_aseek(H, A)
366
367 #define STREAM_FLUSH(H) stream_flush(H)
368
369 #define STREAM_ERROR(H) ((H)->str_error)
370
371 #define STREAM_EOF(H) ((H)->str_eof)
372
373 #define STREAM_CLOSE(H) stream_close(H, 0)
374
375 #define STREAM_REALLYCLOSE(H) stream_close(H, 1)
376
377 #define IH_RELEASE(H) (ih_release(H), (H)=NULL, 0)
378
379 #define IH_REALLYCLOSE(H) ih_reallyclose(H)
380
381 #define IH_CONDSYNC(H) ih_condsync(H)
382
383 #ifdef HAVE_PIO
384 # ifdef AFS_NT40_ENV
385 #  define OS_PREAD(FD, B, S, O) nt_pread(FD, B, S, O)
386 #  define OS_PWRITE(FD, B, S, O) nt_pwrite(FD, B, S, O)
387 # else
388 #  ifdef O_LARGEFILE
389 #   define OS_PREAD(FD, B, S, O) pread64(FD, B, S, O)
390 #   define OS_PWRITE(FD, B, S, O) pwrite64(FD, B, S, O)
391 #  else /* !O_LARGEFILE */
392 #   define OS_PREAD(FD, B, S, O) pread(FD, B, S, O)
393 #   define OS_PWRITE(FD, B, S, O) pwrite(FD, B, S, O)
394 #  endif /* !O_LARGEFILE */
395 # endif /* AFS_NT40_ENV */
396 #else /* !HAVE_PIO */
397 extern ssize_t ih_pread(FD_t fd, void * buf, size_t count, afs_foff_t offset);
398 extern ssize_t ih_pwrite(FD_t fd, const void * buf, size_t count, afs_foff_t offset);
399 # define OS_PREAD(FD, B, S, O) ih_pread(FD, B, S, O)
400 # define OS_PWRITE(FD, B, S, O) ih_pwrite(FD, B, S, O)
401 #endif /* !HAVE_PIO */
402
403 #ifdef AFS_NT40_ENV
404 # define OS_LOCKFILE(FD, O) (!LockFile(FD, (DWORD)((O) & 0xFFFFFFFF), (DWORD)((O) >> 32), 2, 0))
405 # define OS_UNLOCKFILE(FD, O) (!UnlockFile(FD, (DWORD)((O) & 0xFFFFFFFF), (DWORD)((O) >> 32), 2, 0))
406 # define OS_ERROR(X) nterr_nt2unix(GetLastError(), X)
407 # define OS_UNLINK(X) nt_unlink(X)
408 /* we can't have a file unlinked out from under us on NT */
409 # define OS_ISUNLINKED(X) (0)
410 # define OS_DIRSEP "\\"
411 # define OS_DIRSEPC '\\'
412 #else
413 # define OS_LOCKFILE(FD, O) flock(FD, LOCK_EX)
414 # define OS_UNLOCKFILE(FD, O) flock(FD, LOCK_UN)
415 # define OS_ERROR(X) X
416 # define OS_UNLINK(X) unlink(X)
417 # define OS_ISUNLINKED(X) ih_isunlinked(X)
418 extern int ih_isunlinked(FD_t fd);
419 # define OS_DIRSEP "/"
420 # define OS_DIRSEPC '/'
421 #endif
422
423 #ifdef AFS_NAMEI_ENV
424
425 # ifdef AFS_NT40_ENV
426 #  define OS_OPEN(F, M, P) nt_open(F, M, P)
427 #  define OS_CLOSE(FD) nt_close(FD)
428
429 #  define OS_READ(FD, B, S) nt_read(FD, B, S)
430 #  define OS_WRITE(FD, B, S) nt_write(FD, B, S)
431 #  define OS_SEEK(FD, O, F) nt_seek(FD, O, F)
432
433 #  define OS_SYNC(FD) nt_fsync(FD)
434 #  define OS_TRUNC(FD, L) nt_ftruncate(FD, L)
435
436 # else /* AFS_NT40_ENV */
437
438 /*@+fcnmacros +macrofcndecl@*/
439 #  ifdef S_SPLINT_S
440 extern Inode IH_CREATE(IHandle_t * H, int /*@alt Device @ */ D,
441                        char *P, Inode N, int /*@alt VolumeId @ */ P1,
442                        int /*@alt VnodeId @ */ P2,
443                        int /*@alt Unique @ */ P3,
444                        int /*@alt unsigned @ */ P4);
445 extern FD_t OS_IOPEN(IHandle_t * H);
446 extern int OS_OPEN(const char *F, int M, mode_t P);
447 extern int OS_CLOSE(FD_t FD);
448 extern ssize_t OS_READ(FD_t FD, void *B, size_t S);
449 extern ssize_t OS_WRITE(FD_t FD, void *B, size_t S);
450 extern ssize_t OS_PREAD(FD_t FD, void *B, size_t S, afs_foff_t O);
451 extern ssize_t OS_PWRITE(FD_t FD, void *B, size_t S, afs_foff_t O);
452 extern int OS_SYNC(FD_t FD);
453 extern afs_sfsize_t OS_SIZE(FD_t FD);
454 extern int IH_INC(IHandle_t * H, Inode I, int /*@alt VolId, VolumeId @ */ P);
455 extern int IH_DEC(IHandle_t * H, Inode I, int /*@alt VolId, VolumeId @ */ P);
456 extern afs_sfsize_t IH_IREAD(IHandle_t * H, afs_foff_t O, void *B,
457                              afs_fsize_t S);
458 extern afs_sfsize_t IH_IWRITE(IHandle_t * H, afs_foff_t O, void *B,
459                               afs_fsize_t S);
460 #   ifdef O_LARGEFILE
461 #    define OFFT off64_t
462 #   else
463 #    define OFFT off_t
464 #   endif
465
466 extern OFFT OS_SEEK(FD_t FD, OFFT O, int F);
467 extern int OS_TRUNC(FD_t FD, OFFT L);
468 #  endif /*S_SPLINT_S */
469
470 #  ifdef O_LARGEFILE
471 #   define OS_OPEN(F, M, P) open64(F, M, P)
472 #  else /* !O_LARGEFILE */
473 #   define OS_OPEN(F, M, P) open(F, M, P)
474 #  endif /* !O_LARGEFILE */
475 #  define OS_CLOSE(FD) close(FD)
476
477 #  define OS_READ(FD, B, S) read(FD, B, S)
478 #  define OS_WRITE(FD, B, S) write(FD, B, S)
479 #  ifdef O_LARGEFILE
480 #   define OS_SEEK(FD, O, F) lseek64(FD, (off64_t) (O), F)
481 #   define OS_TRUNC(FD, L) ftruncate64(FD, (off64_t) (L))
482 #  else /* !O_LARGEFILE */
483 #   define OS_SEEK(FD, O, F) lseek(FD, (off_t) (O), F)
484 #   define OS_TRUNC(FD, L) ftruncate(FD, (off_t) (L))
485 #  endif /* !O_LARGEFILE */
486
487 #  define OS_SYNC(FD) fsync(FD)
488
489 /*@=fcnmacros =macrofcndecl@*/
490 # endif /* AFS_NT40_ENV */
491 # define IH_INC(H, I, P) namei_inc(H, I, P)
492 # define IH_DEC(H, I, P) namei_dec(H, I, P)
493 # define IH_IREAD(H, O, B, S) namei_iread(H, O, B, S)
494 # define IH_IWRITE(H, O, B, S) namei_iwrite(H, O, B, S)
495 # define IH_CREATE(H, D, P, N, P1, P2, P3, P4) \
496          namei_icreate(H, P, P1, P2, P3, P4)
497 # define OS_IOPEN(H) namei_iopen(H)
498
499
500 #else /* AFS_NAMEI_ENV */
501 extern Inode ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1,
502                         int p2, int p3, int p4);
503
504 # define IH_CREATE(H, D, P, N, P1, P2, P3, P4) \
505         ih_icreate(H, D, P, N, P1, P2, P3, P4)
506
507 # ifdef AFS_LINUX22_ENV
508 #  define OS_IOPEN(H) -1
509 # else
510 #  ifdef O_LARGEFILE
511 #   define OS_IOPEN(H) (IOPEN((H)->ih_dev, (H)->ih_ino, O_RDWR|O_LARGEFILE))
512 #  else
513 #   define OS_IOPEN(H) (IOPEN((H)->ih_dev, (H)->ih_ino, O_RDWR))
514 #  endif
515 # endif
516 # define OS_OPEN(F, M, P) open(F, M, P)
517 # define OS_CLOSE(FD) close(FD)
518
519 # define OS_READ(FD, B, S) read(FD, B, S)
520 # define OS_WRITE(FD, B, S) write(FD, B, S)
521 # ifdef O_LARGEFILE
522 #  define OS_SEEK(FD, O, F) lseek64(FD, (off64_t) (O), F)
523 #  define OS_TRUNC(FD, L) ftruncate64(FD, (off64_t) (L))
524 # else /* !O_LARGEFILE */
525 #  define OS_SEEK(FD, O, F) lseek(FD, (off_t) (O), F)
526 #  define OS_TRUNC(FD, L) ftruncate(FD, (off_t) (L))
527 # endif /* !O_LARGEFILE */
528
529 # define OS_SYNC(FD) fsync(FD)
530
531 # ifdef AFS_LINUX22_ENV
532 #  define IH_INC(H, I, P) -1
533 #  define IH_DEC(H, I, P) -1
534 #  define IH_IREAD(H, O, B, S) -1
535 #  define IH_IWRITE(H, O, B, S) -1
536 # else
537 #  define IH_INC(H, I, P) IINC((H)->ih_dev, I, P)
538 #  define IH_DEC(H, I, P) IDEC((H)->ih_dev, I, P)
539 #  define IH_IREAD(H, O, B, S) inode_read((H)->ih_dev, (H)->ih_ino, (H)->ih_vid,\
540                                           O, B, S)
541 #  define IH_IWRITE(H, O, B, S) \
542           inode_write((H)->ih_dev, (H)->ih_ino, (H)->ih_vid, O, B, S)
543 # endif /* AFS_LINUX22_ENV */
544
545 #endif /* AFS_NAMEI_ENV */
546
547 #define OS_SIZE(FD) ih_size(FD)
548 extern afs_sfsize_t ih_size(FD_t);
549
550 #ifndef AFS_NT40_ENV
551 # define FDH_READV(H, I, N) readv((H)->fd_fd, I, N)
552 # define FDH_WRITEV(H, I, N) writev((H)->fd_fd, I, N)
553 #endif
554
555 #ifdef HAVE_PIOV
556 # ifdef O_LARGEFILE
557 #  define FDH_PREADV(H, I, N, O) preadv64((H)->fd_fd, I, N, O)
558 #  define FDH_PWRITEV(H, I, N, O) pwritev64((H)->fd_fd, I, N, O)
559 # else /* !O_LARGEFILE */
560 #  define FDH_PREADV(H, I, N, O) preadv((H)->fd_fd, I, N, O)
561 #  define FDH_PWRITEV(H, I, N, O) pwritev((H)->fd_fd, I, N, O)
562 # endif /* !O_LARGEFILE */
563 #endif
564
565 #define FDH_PREAD(H, B, S, O) OS_PREAD((H)->fd_fd, B, S, O)
566 #define FDH_PWRITE(H, B, S, O) OS_PWRITE((H)->fd_fd, B, S, O)
567 #define FDH_READ(H, B, S) OS_READ((H)->fd_fd, B, S)
568 #define FDH_WRITE(H, B, S) OS_WRITE((H)->fd_fd, B, S)
569 #define FDH_SEEK(H, O, F) OS_SEEK((H)->fd_fd, O, F)
570
571 #define FDH_SYNC(H) ih_fdsync(H)
572 #define FDH_TRUNC(H, L) OS_TRUNC((H)->fd_fd, L)
573 #define FDH_SIZE(H) OS_SIZE((H)->fd_fd)
574 #define FDH_LOCKFILE(H, O) OS_LOCKFILE((H)->fd_fd, O)
575 #define FDH_UNLOCKFILE(H, O) OS_UNLOCKFILE((H)->fd_fd, O)
576 #define FDH_ISUNLINKED(H) OS_ISUNLINKED((H)->fd_fd)
577
578 extern int ih_fdsync(FdHandle_t *fdP);
579
580 #ifdef AFS_NT40_ENV
581 # define afs_stat_st     __stat64
582 # define afs_stat       _stat64
583 # define afs_fstat      _fstat64
584 # define afs_fopen      fopen
585 # define afs_open       open
586 # define afs_lseek(FD, O, F)    _lseeki64(FD, O, F)
587 #else /* AFS_NT40_ENV */
588 # ifdef O_LARGEFILE
589 #  define afs_stat_st     stat64
590 #  define afs_stat      stat64
591 #  define afs_fstat     fstat64
592 #  define afs_fopen     fopen64
593 #  define afs_open      open64
594 #  ifdef S_SPLINT_S
595 extern off64_t afs_lseek(int FD, off64_t O, int F);
596 #  endif /*S_SPLINT_S */
597 #  define afs_lseek(FD, O, F)   lseek64(FD, (off64_t) (O), F)
598 #  define afs_ftruncate           ftruncate64
599 #  define afs_mmap                mmap64
600 #  ifdef AFS_AIX_ENV
601 extern void * mmap64();  /* ugly hack since aix build env appears to be somewhat broken */
602 #  endif
603 # else /* !O_LARGEFILE */
604 #  define afs_stat_st     stat
605 #  define       afs_stat        stat
606 #  define       afs_fstat       fstat
607 #  define afs_fopen     fopen
608 #  define afs_open      open
609 #  ifdef S_SPLINT_S
610 extern off_t afs_lseek(int FD, off_t O, int F);
611 #  endif /*S_SPLINT_S */
612 #  define afs_lseek(FD, O, F)   lseek(FD, (off_t) (O), F)
613 #  define afs_ftruncate           ftruncate
614 #  define afs_mmap                mmap
615 # endif /* !O_LARGEFILE */
616 # if AFS_HAVE_STATVFS64
617 #  define afs_statvfs   statvfs64
618 # else
619 #  if AFS_HAVE_STATFS64
620 #   define afs_statfs   statfs64
621 #  else
622 #   if AFS_HAVE_STATVFS
623 #    define afs_statvfs statvfs
624 #   else
625 #    define afs_statfs  statfs
626 #   endif /* !AFS_HAVE_STATVFS */
627 #  endif /* !AFS_HAVE_STATFS64 */
628 # endif /* !AFS_HAVE_STATVFS64 */
629 #endif /* !AFS_NT40_ENV */
630
631 #endif /* _IHANDLE_H_ */