00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 const char *XrdPosixPreload32CVSID = "$Id: XrdPosixPreload32.cc 30949 2009-11-02 16:37:58Z ganis $";
00014
00015 #if !defined(SUNX86) && defined(__LP64__) && !defined(_LP64)
00016 #undef _LARGEFILE_SOURCE
00017 #undef _FILE_OFFSET_BITS
00018 #define _FILE_OFFSET_BITS 32
00019 #endif
00020 #define XRDPOSIXPRELOAD32
00021
00022 #include <errno.h>
00023 #include <dirent.h>
00024 #include <stdio.h>
00025 #include <stdarg.h>
00026 #include <sys/stat.h>
00027 #include <sys/types.h>
00028 #include <unistd.h>
00029
00030 #if defined(__macos__) || defined(__FreeBSD__)
00031 #include <sys/param.h>
00032 #include <sys/mount.h>
00033 #else
00034 #include <sys/statfs.h>
00035 #endif
00036
00037 #include "XrdPosix/XrdPosixExtern.hh"
00038 #include "XrdPosix/XrdPosixLinkage.hh"
00039 #include "XrdPosix/XrdPosixOsDep.hh"
00040 #include "XrdPosix/XrdPosixXrootd.hh"
00041 #include "XrdSys/XrdSysHeaders.hh"
00042 #include "XrdSys/XrdSysPlatform.hh"
00043
00044
00045
00046
00047
00048 extern XrdPosixLinkage Xunix;
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #if !defined(__LP64__) && !defined(_LP64)
00062 #if !defined( __macos__) && !defined(SUNX86) && !defined(__FreeBSD__)
00063 int XrdPosix_CopyDirent(struct dirent *dent, struct dirent64 *dent64)
00064 {
00065 const unsigned long long LLMask = 0xffffffff00000000LL;
00066 int isdiff = (dent->d_name-(char *)dent) != (dent64->d_name-(char *)dent64);
00067
00068 if (isdiff && ((dent64->d_ino & LLMask) || (dent64->d_off & LLMask)))
00069 {errno = EOVERFLOW; return EOVERFLOW;}
00070
00071 if (isdiff || (void *)dent != (void *)dent64)
00072 {dent->d_ino = dent64->d_ino;
00073 dent->d_off = dent64->d_off;
00074 dent->d_reclen = dent64->d_reclen;
00075 strcpy(dent->d_name, dent64->d_name);
00076 }
00077 return 0;
00078 }
00079 #endif
00080 #endif
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 #if !defined(__LP64__) && !defined(_LP64)
00093 #if !defined(SUNX86) && !defined(__FreeBSD__)
00094 int XrdPosix_CopyStat(struct stat *buf, struct stat64 &buf64)
00095 {
00096 const unsigned long long LLMask = 0xffffffff00000000LL;
00097 const int INTMax = 0x7fffffff;
00098
00099 if (buf64.st_size & LLMask)
00100 if (buf64.st_mode & S_IFREG || buf64.st_mode & S_IFDIR)
00101 {errno = EOVERFLOW; return -1;}
00102 else buf->st_size = INTMax;
00103 else buf->st_size = buf64.st_size;
00104
00105 buf->st_ino = buf64.st_ino & LLMask ? INTMax : buf64.st_ino;
00106 buf->st_blocks= buf64.st_blocks & LLMask ? INTMax : buf64.st_blocks;
00107 buf->st_mode = buf64.st_mode;
00108 buf->st_dev = buf64.st_dev;
00109 buf->st_rdev = buf64.st_rdev;
00110 buf->st_nlink = buf64.st_nlink;
00111 buf->st_uid = buf64.st_uid;
00112 buf->st_gid = buf64.st_gid;
00113 buf->st_atime = buf64.st_atime;
00114 buf->st_mtime = buf64.st_mtime;
00115 buf->st_ctime = buf64.st_ctime;
00116 buf->st_blksize=buf64.st_blksize;
00117 return 0;
00118 }
00119 #endif
00120 #endif
00121
00122
00123
00124
00125
00126 #if !defined(SUNX86) && !defined(__FreeBSD__)
00127 extern "C"
00128 {
00129 int creat(const char *path, mode_t mode)
00130 {
00131 static int Init = Xunix.Init(&Init);
00132
00133 return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
00134 }
00135 }
00136 #endif
00137
00138
00139
00140
00141
00142 extern "C"
00143 {
00144 int fcntl(int fd, int cmd, ...)
00145 {
00146 static int Init = Xunix.Init(&Init);
00147 va_list ap;
00148 void *theArg;
00149
00150 if (XrdPosixXrootd::myFD(fd)) return 0;
00151 va_start(ap, cmd);
00152 theArg = va_arg(ap, void *);
00153 va_end(ap);
00154 return Xunix.Fcntl(fd, cmd, theArg);
00155 }
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 #ifndef SUNX86
00179 extern "C"
00180 {
00181 int fseeko(FILE *stream, off_t offset, int whence)
00182 {
00183 static int Init = Xunix.Init(&Init);
00184
00185 return XrdPosix_Fseeko(stream, offset, whence);
00186 }
00187 }
00188 #endif
00189
00190
00191
00192
00193
00194 #if !defined(SUNX86) && !defined(__FreeBSD__)
00195 extern "C"
00196 {
00197 #if defined __linux__ && __GNUC__ && __GNUC__ >= 2
00198 int __fxstat(int ver, int fildes, struct stat *buf)
00199 #elif defined(__solaris__) && defined(__i386)
00200 int _fxstat(int ver, int fildes, struct stat *buf)
00201 #else
00202 int fstat( int fildes, struct stat *buf)
00203 #endif
00204 {
00205 static int Init = Xunix.Init(&Init);
00206
00207 #ifdef __linux__
00208 if (!XrdPosixXrootd::myFD(fildes)) return Xunix.Fstat(ver, fildes, buf);
00209 #else
00210 if (!XrdPosixXrootd::myFD(fildes)) return Xunix.Fstat( fildes, buf);
00211 #endif
00212
00213 #if defined(__LP64__) || defined(_LP64)
00214 return XrdPosix_Fstat(fildes, buf );
00215 #else
00216 int rc;
00217 struct stat64 buf64;
00218 if ((rc = XrdPosix_Fstat(fildes, (struct stat *)&buf64))) return rc;
00219 return XrdPosix_CopyStat(buf, buf64);
00220 #endif
00221 }
00222 }
00223 #endif
00224
00225
00226
00227
00228
00229
00230 #ifndef SUNX86
00231 extern "C"
00232 {
00233 off_t ftello(FILE *stream)
00234 {
00235 static int Init = Xunix.Init(&Init);
00236
00237 return static_cast<off_t>(XrdPosix_Ftello(stream));
00238 }
00239 }
00240 #endif
00241
00242
00243
00244
00245
00246 #if !defined(SUNX86) && !defined(__FreeBSD__)
00247 extern "C"
00248 {
00249 int ftruncate(int fildes, off_t offset)
00250 {
00251 static int Init = Xunix.Init(&Init);
00252
00253 return XrdPosix_Ftruncate(fildes, offset);
00254 }
00255 }
00256 #endif
00257
00258
00259
00260
00261
00262 #if !defined(SUNX86) && !defined(__FreeBSD__)
00263 extern "C"
00264 {
00265 off_t lseek(int fildes, off_t offset, int whence)
00266 {
00267 static int Init = Xunix.Init(&Init);
00268
00269 return XrdPosix_Lseek(fildes, offset, whence);
00270 }
00271 }
00272 #endif
00273
00274
00275
00276
00277
00278 #if !defined(SUNX86) && !defined(__FreeBSD__)
00279 extern "C"
00280 {
00281 #if defined __GNUC__ && __GNUC__ >= 2 && defined(__linux__)
00282 int __lxstat(int ver, const char *path, struct stat *buf)
00283 #elif defined(__solaris__) && defined(__i386)
00284 int _lxstat(int ver, const char *path, struct stat *buf)
00285 #else
00286 int lstat( const char *path, struct stat *buf)
00287 #endif
00288 {
00289 static int Init = Xunix.Init(&Init);
00290
00291 if (!XrdPosix_isMyPath(path))
00292 #ifdef __linux__
00293 return Xunix.Lstat(ver, path, buf);
00294 #else
00295 return Xunix.Lstat( path, buf);
00296 #endif
00297
00298 #if defined(__LP64__) || defined(_LP64)
00299 return XrdPosix_Lstat(path, buf );
00300 #else
00301 struct stat64 buf64;
00302 int rc;
00303 if ((rc = XrdPosix_Lstat(path, (struct stat *)&buf64))) return rc;
00304 return XrdPosix_CopyStat(buf, buf64);
00305 #endif
00306 }
00307 }
00308 #endif
00309
00310
00311
00312
00313
00314 #if !defined(SUNX86) && !defined(__FreeBSD__)
00315 extern "C"
00316 {
00317 int open(const char *path, int oflag, ...)
00318 {
00319 static int Init = Xunix.Init(&Init);
00320 va_list ap;
00321 int mode;
00322
00323 va_start(ap, oflag);
00324 mode = va_arg(ap, int);
00325 va_end(ap);
00326 return XrdPosix_Open(path, oflag, mode);
00327 }
00328 }
00329 #endif
00330
00331
00332
00333
00334
00335 #if !defined(SUNX86) && !defined(__FreeBSD__)
00336 extern "C"
00337 {
00338 ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
00339 {
00340 static int Init = Xunix.Init(&Init);
00341
00342 return XrdPosix_Pread(fildes, buf, nbyte, offset);
00343 }
00344 }
00345 #endif
00346
00347
00348
00349
00350
00351 #if !defined(SUNX86) && !defined(__FreeBSD__)
00352 extern "C"
00353 {
00354 struct dirent* readdir(DIR *dirp)
00355 {
00356 static int Init = Xunix.Init(&Init);
00357 struct dirent64 *dp64;
00358
00359 if (!(dp64 = XrdPosix_Readdir64(dirp))) return 0;
00360
00361 #if !defined(__macos__) && !defined(_LP64) && !defined(__LP64__)
00362 if (XrdPosix_CopyDirent((struct dirent *)dp64, dp64)) return 0;
00363 #endif
00364
00365 return (struct dirent *)dp64;
00366 }
00367 }
00368 #endif
00369
00370
00371
00372
00373
00374 #if !defined(SUNX86) && !defined(__FreeBSD__)
00375 extern "C"
00376 {
00377 int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
00378 {
00379 static int Init = Xunix.Init(&Init);
00380 #if defined(__macos__) || defined(__LP64__) || defined(_LP64)
00381 return XrdPosix_Readdir_r(dirp, entry, result);
00382 #else
00383 char buff[sizeof(struct dirent64) + 2048];
00384 struct dirent64 *dp64 = (struct dirent64 *)buff;
00385 struct dirent64 *mydirent;
00386 int rc;
00387
00388 if ((rc = XrdPosix_Readdir64_r(dirp, dp64, &mydirent)))
00389 return rc;
00390
00391 if (!mydirent) {*result = 0; return 0;}
00392
00393 if ((rc = XrdPosix_CopyDirent(entry, dp64))) return rc;
00394
00395 *result = entry;
00396 return 0;
00397 #endif
00398 }
00399 }
00400 #endif
00401
00402
00403
00404
00405
00406 #if !defined(SUNX86) && !defined(__FreeBSD__)
00407 extern "C"
00408 {
00409 ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
00410 {
00411 static int Init = Xunix.Init(&Init);
00412
00413 return XrdPosix_Pwrite(fildes, buf, nbyte, offset);
00414 }
00415 }
00416 #endif
00417
00418
00419
00420
00421
00422 #if !defined(SUNX86) && !defined(__FreeBSD__)
00423 extern "C"
00424 {
00425 #if defined __GNUC__ && __GNUC__ >= 2
00426 int __xstat(int ver, const char *path, struct stat *buf)
00427 #elif defined(__solaris__) && defined(__i386)
00428 int _xstat(int ver, const char *path, struct stat *buf)
00429 #else
00430 int stat( const char *path, struct stat *buf)
00431 #endif
00432 {
00433 static int Init = Xunix.Init(&Init);
00434
00435 if (!XrdPosix_isMyPath(path))
00436 #ifdef __linux__
00437 return Xunix.Stat(ver, path, buf);
00438 #else
00439 return Xunix.Stat( path, buf);
00440 #endif
00441
00442 #if defined(__LP64__) || defined(_LP64)
00443 return XrdPosix_Stat(path, buf );
00444 #else
00445 struct stat64 buf64;
00446 int rc;
00447 if ((rc = XrdPosix_Stat(path, (struct stat *)&buf64))) return rc;
00448 return XrdPosix_CopyStat(buf, buf64);
00449 #endif
00450 }
00451 }
00452 #endif
00453
00454
00455
00456
00457
00458 #if !defined(__solaris__) && !defined(__macos__) && !defined(__FreeBSD__)
00459 extern "C"
00460 {
00461 int statfs( const char *path, struct statfs *buf)
00462 {
00463 static int Init = Xunix.Init(&Init);
00464 struct statfs64 buf64;
00465 int rc;
00466
00467 if ((rc = XrdPosix_Statfs(path, (struct statfs *)&buf64))) return rc;
00468 memset(buf, 0, sizeof(buf));
00469 buf->f_type = buf64.f_type;
00470 buf->f_bsize = buf64.f_bsize;
00471 buf->f_blocks = buf64.f_blocks;
00472 buf->f_bfree = buf64.f_bfree;
00473 buf->f_files = buf64.f_files;
00474 buf->f_ffree = buf64.f_ffree;
00475 buf->f_fsid = buf64.f_fsid;
00476 buf->f_namelen = buf64.f_namelen;
00477 return 0;
00478 }
00479 }
00480 #endif
00481
00482
00483
00484
00485
00486 #if !defined(__macos__) && !defined(SUNX86) && !defined(__FreeBSD__)
00487 extern "C"
00488 {
00489 int statvfs( const char *path, struct statvfs *buf)
00490 {
00491 static int Init = Xunix.Init(&Init);
00492 struct statvfs64 buf64;
00493 int rc;
00494 if ((rc = XrdPosix_Statvfs(path, (struct statvfs *)&buf64))) return rc;
00495 memset(buf, 0, sizeof(buf));
00496 buf->f_flag = buf64.f_flag;
00497 buf->f_bsize = buf64.f_bsize;
00498 buf->f_blocks = buf64.f_blocks;
00499 buf->f_bfree = buf64.f_bfree;
00500 buf->f_files = buf64.f_files;
00501 buf->f_ffree = buf64.f_ffree;
00502 buf->f_fsid = buf64.f_fsid;
00503 buf->f_namemax = buf64.f_namemax;
00504 return 0;
00505 }
00506 }
00507 #endif
00508
00509
00510
00511
00512
00513 #if !defined(SUNX86) && !defined(__FreeBSD__)
00514 extern "C"
00515 {
00516 int truncate(const char *path, off_t offset)
00517 {
00518 static int Init = Xunix.Init(&Init);
00519
00520 return XrdPosix_Truncate(path, offset);
00521 }
00522 }
00523 #endif