2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * The only purpose of this file is help liblustre adaptive to more
22 * applications, and specifically for running on Linux. The ideal
23 * final solution would be remove this completely and only rely on
24 * system call interception. Unfortunately we failed to find that
27 * Initially we try the simplest implementation here, just get a confidence
31 #if !(defined(BSD) || defined(REDSTORM))
40 #include "sysio-symbols.h"
42 #if !defined(__USE_LARGEFILE64)
43 #error "__LARGEFILE64_SOURCE must be defined"
47 /***********************************************************
48 * dir series functions *
49 ***********************************************************/
57 loff_t filepos; /* current pos in dir file stream */
58 struct dirent *curent; /* current dirent pointer */
59 struct dirent64 *curent64; /* current dirent64 pointer */
60 struct dirent *retent; /* ent returned to caller */
61 struct dirent64 *retent64; /* ent64 returned to caller */
62 unsigned int effective; /* effective data size in buffer */
66 DIR* opendir(const char *name)
70 dir = (DIR *) malloc(sizeof(*dir));
77 dir->fd = open64(name, O_RDONLY);
79 dir->fd = open(name, O_RDONLY);
86 dir->curent = (struct dirent *) dir->buf;
87 dir->curent64 = (struct dirent64 *) dir->buf;
98 sysio_sym_weak_alias(opendir, __opendir);
100 struct dirent64 *readdir64(DIR *dir)
104 /* need to read new data? */
105 if ((char*)dir->curent64 - dir->buf >= dir->effective) {
106 rc = getdirentries64(dir->fd, dir->buf, BUFSIZE, &dir->base);
107 /* error or end-of-file */
111 dir->curent64 = (struct dirent64 *) dir->buf;
115 dir->retent64 = dir->curent64;
116 dir->curent64 = (struct dirent64*) ((char *)(dir->curent64) +
117 dir->curent64->d_reclen);
118 #ifdef _DIRENT_HAVE_D_OFF
119 dir->filepos = dir->curent64->d_off;
121 dir->filepos += dir->curent64->d_reclen;
123 return dir->retent64;
126 sysio_sym_weak_alias(readdir64, __readdir64);
128 /* XXX probably the following assumption is not true */
130 #define NATURAL_READDIR64
132 #undef NATURAL_READDIR64
135 #ifndef NATURAL_READDIR64
137 struct dirent *readdir(DIR *dir)
141 /* need to read new data? */
142 if ((char*)dir->curent - dir->buf >= dir->effective) {
143 rc = getdirentries(dir->fd, dir->buf, BUFSIZE, (off_t*) &dir->base);
144 /* error or end-of-file */
148 dir->curent = (struct dirent *) dir->buf;
152 dir->retent = dir->curent;
153 dir->curent = (struct dirent*) ((char *)(dir->curent) +
154 dir->curent->d_reclen);
155 #ifdef _DIRENT_HAVE_D_OFF
156 dir->filepos = dir->curent->d_off;
158 dir->filepos += dir->curent->d_reclen;
162 sysio_sym_weak_alias(readdir, __readdir);
164 #else /* NATURAL_READDIR64 */
166 struct dirent *readdir(DIR *dir) {
167 return (struct dirent *) readdir64(dir);
169 sysio_sym_weak_alias(readdir, __readdir);
171 #endif /* NATURAL_READDIR64 */
173 int closedir(DIR *dir)
183 sysio_sym_weak_alias(closedir, __closedir);
190 off_t telldir(DIR *dir)
192 return (dir->filepos);
195 void seekdir(DIR *dir, off_t offset)
197 dir->filepos = offset;
200 dir->curent64 = (struct dirent64 *) dir->buf;
201 dir->retent64 = NULL;
203 dir->curent = (struct dirent *) dir->buf;
207 void rewinddir(DIR *dir)
211 dir->curent64 = (struct dirent64 *) dir->buf;
212 dir->retent64 = NULL;
213 dir->curent = (struct dirent *) dir->buf;
219 int scandir(const char *dir, struct dirent ***namelist,
220 int(*select)(const struct dirent *),
221 int(*compar)(const void *, const void *))
227 int scandir64(const char *dir, struct dirent64 ***namelist,
228 int(*select)(const struct dirent64 *),
229 int(*compar)(const void *, const void *))
236 /***********************************************************
237 * FIXME workaround for linux only *
238 ***********************************************************/
242 ssize_t getxattr(char *path, char *name, void *value, size_t size)
248 ssize_t lgetxattr(char *path, char *name, void *value, size_t size)
254 ssize_t fgetxattr(int fd, char *name, void *value, size_t size)
260 long setxattr(char *path, char *name, void *value, size_t size, int flags)
266 long lsetxattr(char *path, char *name, void *value, size_t size, int flags)
272 long fsetxattr(int fd, char *name, void *value, size_t size, int flags)
278 long listxattr(char *path, char *list, size_t size)
284 long llistxattr(char *path, char *list, size_t size)
290 long flistxattr(int fd, char *list, size_t size)
296 long removexattr(char *path, char *name)
302 long lremovexattr(char *path, char *name)
308 long fremovexattr(int fd, char *name)