Whamcloud - gitweb
b=21581 too long file / path names for old tar
[fs/lustre-release.git] / libsysio / include / file.h
1 /*
2  *    This Cplant(TM) source code is the property of Sandia National
3  *    Laboratories.
4  *
5  *    This Cplant(TM) source code is copyrighted by Sandia National
6  *    Laboratories.
7  *
8  *    The redistribution of this Cplant(TM) source code is subject to the
9  *    terms of the GNU Lesser General Public License
10  *    (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
11  *
12  *    Cplant(TM) Copyright 1998-2006 Sandia Corporation. 
13  *    Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
14  *    license for use of this work by or on behalf of the US Government.
15  *    Export of this program may require a license from the United States
16  *    Government.
17  */
18
19 /*
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  * 
25  * This library is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  * 
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33  *
34  * Questions or comments about this library should be sent to:
35  *
36  * Lee Ward
37  * Sandia National Laboratories, New Mexico
38  * P.O. Box 5800
39  * Albuquerque, NM 87185-1110
40  *
41  * lee@sandia.gov
42  */
43
44 /*
45  * Open file support.
46  */
47
48 /*
49  * Test whether large file support on this file.
50  */
51 #ifdef O_LARGEFILE
52 #define _F_LARGEFILE(fil) \
53         ((fil)->f_flags & O_LARGEFILE)
54 #else
55 #define _F_LARGEFILE(fil) \
56         (1)
57 #endif
58 /*
59  * Return max seek value for this file.
60  */
61 #define _SEEK_MAX(fil) \
62         (_F_LARGEFILE(fil) ? _SYSIO_OFF_T_MAX : LONG_MAX)
63
64 #ifdef _LARGEFILE64_SOURCE
65 #define _SYSIO_FLOCK    flock64
66 #else
67 #define _SYSIO_FLOCK    flock
68 #endif
69
70 /*
71  * A file record is maintained for each open file in the system. It holds
72  * all the info necessary to track the context and parameters for the
73  * operations that may be performed.
74  */
75 struct file {
76         struct inode *f_ino;                            /* path node */
77         _SYSIO_OFF_T f_pos;                             /* current stream pos */
78         unsigned f_ref;                                 /* ref count */
79         int     f_flags;                                /* open/fcntl flags */
80 };
81
82 /*
83  * Reference a file record.
84  */
85 #define F_REF(fil) \
86         do { \
87                 (fil)->f_ref++; \
88                 assert((fil)->f_ref); \
89         } while (0)
90
91 /*
92  * Release reference to a file record.
93  */
94 #define F_RELE(fil) \
95         do { \
96                 assert((fil)->f_ref); \
97                 (fil)->f_ref--; \
98                 if (!(fil)->f_ref) \
99                         _sysio_fgone(fil); \
100         } while (0)
101
102 /*
103  * Init file record.
104  *
105  * NB: Don't forget to take a reference to the inode too!
106  */
107 #define _SYSIO_FINIT(fil, ino, flags) \
108         do { \
109                 (fil)->f_ino = (ino); \
110                 (fil)->f_pos = 0; \
111                 (fil)->f_ref = 0; \
112                 (fil)->f_flags = (flags); \
113         } while (0)
114
115 /*
116  * Determine if a file may be read/written.
117  *
118  * Given a ptr to an open file table entry and a flag indicating desired
119  * access return non-zero if the file record indicates that the access is
120  * permitted or zero, if not.
121  *
122  * 'r'  for read access check
123  * 'w'  for write access check
124  */
125
126 #define F_CHKRW(_fil, _c) \
127         (((_c) == 'r' && !((_fil)->f_flags & O_WRONLY)) || \
128          ((_c) == 'w' && ((_fil)->f_flags & (O_WRONLY | O_RDWR))))
129
130 struct ioctx;
131
132 extern struct file *_sysio_fnew(struct inode *ino, int flags);
133 extern void _sysio_fgone(struct file *fil);
134 extern void _sysio_fcompletio(struct ioctx *ioctx, struct file *fil);
135 extern int _sysio_fd_close(int fd);
136 extern struct file *_sysio_fd_find(int fd);
137 extern int _sysio_fd_set(struct file *fil, int fd, int force);
138 extern int _sysio_fd_dup(int oldfd, int newfd, int force);
139 extern int _sysio_fd_close_all(void);
140 #ifdef ZERO_SUM_MEMORY
141 extern void _sysio_fd_shutdown(void);
142 #endif
143 extern _SYSIO_OFF_T _sysio_lseek_prepare(struct file *fil,
144                                          _SYSIO_OFF_T offset,
145                                          int whence,
146                                          _SYSIO_OFF_T max);