-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdPosixPreload32.cc
546 lines (467 loc) · 17.9 KB
/
XrdPosixPreload32.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
/******************************************************************************/
/* */
/* X r d P o s i x P r e l o a d 3 2 . c c */
/* */
/* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#ifdef _LARGEFILE_SOURCE
#undef _LARGEFILE_SOURCE
#endif
#ifdef _LARGEFILE64_SOURCE
#undef _LARGEFILE64_SOURCE
#endif
#ifdef _FILE_OFFSET_BITS
#undef _FILE_OFFSET_BITS
#endif
#define XRDPOSIXPRELOAD32
#include <errno.h>
#include <dirent.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#if defined(__macos__) || defined(__FreeBSD__)
#include <sys/param.h>
#include <sys/mount.h>
#else
#include <sys/statfs.h>
#endif
#include "XrdPosix/XrdPosixExtern.hh"
#include "XrdPosix/XrdPosixLinkage.hh"
#include "XrdPosix/XrdPosixOsDep.hh"
#include "XrdPosix/XrdPosixXrootd.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysPlatform.hh"
/******************************************************************************/
/* G l o b a l D e c l a r a t i o n s */
/******************************************************************************/
extern XrdPosixLinkage Xunix;
/******************************************************************************/
/* 6 4 - t o 3 2 B i t C o n v e r s i o n s */
/******************************************************************************/
/******************************************************************************/
/* X r d P o s i x _ C o p y D i r e n t */
/******************************************************************************/
// Macos is a curious beast. It is not an LP64 platform but offsets are
// defined as 64 bits anyway. So, the dirent structure is 64-bit conformable
// making CopyDirent() superfluous. In Solaris x86 there are no 32 bit interfaces.
//
#if !defined(__LP64__) && !defined(_LP64)
#if !defined( __macos__) && !defined(SUNX86) && !defined(__FreeBSD__)
int XrdPosix_CopyDirent(struct dirent *dent, struct dirent64 *dent64)
{
const unsigned long long LLMask = 0xffffffff00000000LL;
int isdiff = (dent->d_name-(char *)dent) != (dent64->d_name-(char *)dent64);
if (isdiff && ((dent64->d_ino & LLMask) || (dent64->d_off & LLMask)))
{errno = EOVERFLOW; return EOVERFLOW;}
if (isdiff || (void *)dent != (void *)dent64)
{dent->d_ino = dent64->d_ino;
dent->d_off = dent64->d_off;
dent->d_reclen = dent64->d_reclen;
strcpy(dent->d_name, dent64->d_name);
}
return 0;
}
#endif
#endif
/******************************************************************************/
/* X r d P o s i x _ C o p y S t a t */
/******************************************************************************/
// Macos is a curious beast. It is not an LP64 platform but stat sizes are
// defined as 64 bits anyway. So, the stat structure is 64-bit conformable
// making CopyStat() seemingly superfluous. However, starting in Darwin 10.5
// stat and stat64 are defined separately making it necessary to use CopyStat().
// In Solaris x86 there are no 32 bit interfaces.
//
#if !defined(__LP64__) && !defined(_LP64)
#if !defined(SUNX86) && !defined(__FreeBSD__)
int XrdPosix_CopyStat(struct stat *buf, struct stat64 &buf64)
{
const unsigned long long LLMask = 0xffffffff00000000LL;
const int INTMax = 0x7fffffff;
if (buf64.st_size & LLMask)
if (buf64.st_mode & S_IFREG || buf64.st_mode & S_IFDIR)
{errno = EOVERFLOW; return -1;}
else buf->st_size = INTMax;
else buf->st_size = buf64.st_size; /* 64: File size in bytes */
buf->st_ino = buf64.st_ino & LLMask ? INTMax : buf64.st_ino;
buf->st_blocks= buf64.st_blocks & LLMask ? INTMax : buf64.st_blocks;
buf->st_mode = buf64.st_mode; /* File mode (see mknod(2)) */
buf->st_dev = buf64.st_dev;
buf->st_rdev = buf64.st_rdev; /* ID of device */
buf->st_nlink = buf64.st_nlink; /* Number of links */
buf->st_uid = buf64.st_uid; /* User ID of the file's owner */
buf->st_gid = buf64.st_gid; /* Group ID of the file's group */
buf->st_atime = buf64.st_atime; /* Time of last access */
buf->st_mtime = buf64.st_mtime; /* Time of last data modification */
buf->st_ctime = buf64.st_ctime; /* Time of last file status change */
buf->st_blksize=buf64.st_blksize; /* Preferred I/O block size */
return 0;
}
#endif
#endif
/******************************************************************************/
/* c r e a t */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
int creat(const char *path, mode_t mode)
{
static int Init = Xunix.Init(&Init);
return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
}
}
#endif
/******************************************************************************/
/* f c n t l */
/******************************************************************************/
extern "C"
{
int fcntl(int fd, int cmd, ...)
{
static int Init = Xunix.Init(&Init);
va_list ap;
void *theArg;
if (XrdPosixXrootd::myFD(fd)) return 0;
va_start(ap, cmd);
theArg = va_arg(ap, void *);
va_end(ap);
return Xunix.Fcntl(fd, cmd, theArg);
}
}
/******************************************************************************/
/* f o p e n */
/******************************************************************************/
/*
extern "C"
{
FILE *fopen(const char *path, const char *mode)
{
static int Init = Xunix.Init(&Init);
return XrdPosix_Fopen(path, mode);
}
}
*/
/******************************************************************************/
/* f s e e k o */
/******************************************************************************/
#ifndef SUNX86
extern "C"
{
int fseeko(FILE *stream, off_t offset, int whence)
{
static int Init = Xunix.Init(&Init);
return XrdPosix_Fseeko(stream, offset, whence);
}
}
#endif
/******************************************************************************/
/* f s t a t */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
#if defined __linux__ && __GNUC__ && __GNUC__ >= 2
int __fxstat(int ver, int fildes, struct stat *buf)
#elif defined(__solaris__) && defined(__i386)
int _fxstat(int ver, int fildes, struct stat *buf)
#else
int fstat( int fildes, struct stat *buf)
#endif
{
static int Init = Xunix.Init(&Init);
#ifdef __linux__
if (!XrdPosixXrootd::myFD(fildes)) return Xunix.Fstat(ver, fildes, buf);
#else
if (!XrdPosixXrootd::myFD(fildes)) return Xunix.Fstat( fildes, buf);
#endif
#if defined(__LP64__) || defined(_LP64)
return XrdPosix_Fstat(fildes, buf );
#else
int rc;
struct stat64 buf64;
if ((rc = XrdPosix_Fstat(fildes, (struct stat *)&buf64))) return rc;
return XrdPosix_CopyStat(buf, buf64);
#endif
}
}
#endif
/******************************************************************************/
/* f t e l l o */
/******************************************************************************/
#ifndef SUNX86
extern "C"
{
off_t ftello(FILE *stream)
{
static int Init = Xunix.Init(&Init);
return static_cast<off_t>(XrdPosix_Ftello(stream));
}
}
#endif
/******************************************************************************/
/* f t r u n c a t e */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
int ftruncate(int fildes, off_t offset)
{
static int Init = Xunix.Init(&Init);
return XrdPosix_Ftruncate(fildes, offset);
}
}
#endif
/******************************************************************************/
/* l s e e k */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
off_t lseek(int fildes, off_t offset, int whence)
{
static int Init = Xunix.Init(&Init);
return XrdPosix_Lseek(fildes, offset, whence);
}
}
#endif
/******************************************************************************/
/* l s t a t */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
#if defined __GNUC__ && __GNUC__ >= 2 && defined(__linux__)
int __lxstat(int ver, const char *path, struct stat *buf)
#elif defined(__solaris__) && defined(__i386)
int _lxstat(int ver, const char *path, struct stat *buf)
#else
int lstat( const char *path, struct stat *buf)
#endif
{
static int Init = Xunix.Init(&Init);
if (!XrdPosix_isMyPath(path))
#ifdef __linux__
return Xunix.Lstat(ver, path, buf);
#else
return Xunix.Lstat( path, buf);
#endif
#if defined(__LP64__) || defined(_LP64)
return XrdPosix_Lstat(path, buf );
#else
struct stat64 buf64;
int rc;
if ((rc = XrdPosix_Lstat(path, (struct stat *)&buf64))) return rc;
return XrdPosix_CopyStat(buf, buf64);
#endif
}
}
#endif
/******************************************************************************/
/* o p e n */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
int open(const char *path, int oflag, ...)
{
static int Init = Xunix.Init(&Init);
va_list ap;
int mode;
va_start(ap, oflag);
mode = va_arg(ap, int);
va_end(ap);
return XrdPosix_Open(path, oflag, mode);
}
}
#endif
/******************************************************************************/
/* p r e a d */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
{
static int Init = Xunix.Init(&Init);
return XrdPosix_Pread(fildes, buf, nbyte, offset);
}
}
#endif
/******************************************************************************/
/* r e a d d i r */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
struct dirent* readdir(DIR *dirp)
{
static int Init = Xunix.Init(&Init);
struct dirent64 *dp64;
if (!(dp64 = XrdPosix_Readdir64(dirp))) return 0;
#if !defined(__macos__) && !defined(_LP64) && !defined(__LP64__)
if (XrdPosix_CopyDirent((struct dirent *)dp64, dp64)) return 0;
#endif
return (struct dirent *)dp64;
}
}
#endif
/******************************************************************************/
/* r e a d d i r _ r */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
{
static int Init = Xunix.Init(&Init);
#if defined(__macos__) || defined(__LP64__) || defined(_LP64)
return XrdPosix_Readdir_r(dirp, entry, result);
#else
char buff[sizeof(struct dirent64) + 2048];
struct dirent64 *dp64 = (struct dirent64 *)buff;
struct dirent64 *mydirent;
int rc;
if ((rc = XrdPosix_Readdir64_r(dirp, dp64, &mydirent)))
return rc;
if (!mydirent) {*result = 0; return 0;}
if ((rc = XrdPosix_CopyDirent(entry, dp64))) return rc;
*result = entry;
return 0;
#endif
}
}
#endif
/******************************************************************************/
/* p w r i t e */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
{
static int Init = Xunix.Init(&Init);
return XrdPosix_Pwrite(fildes, buf, nbyte, offset);
}
}
#endif
/******************************************************************************/
/* s t a t */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
#if defined __GNUC__ && __GNUC__ >= 2
int __xstat(int ver, const char *path, struct stat *buf)
#elif defined(__solaris__) && defined(__i386)
int _xstat(int ver, const char *path, struct stat *buf)
#else
int stat( const char *path, struct stat *buf)
#endif
{
static int Init = Xunix.Init(&Init);
if (!XrdPosix_isMyPath(path))
#ifdef __linux__
return Xunix.Stat(ver, path, buf);
#else
return Xunix.Stat( path, buf);
#endif
#if defined(__LP64__) || defined(_LP64)
return XrdPosix_Stat(path, buf );
#else
struct stat64 buf64;
int rc;
if ((rc = XrdPosix_Stat(path, (struct stat *)&buf64))) return rc;
return XrdPosix_CopyStat(buf, buf64);
#endif
}
}
#endif
/******************************************************************************/
/* s t a t f s */
/******************************************************************************/
#if !defined(__solaris__) && !defined(__macos__) && !defined(__FreeBSD__)
extern "C"
{
int statfs( const char *path, struct statfs *buf)
{
static int Init = Xunix.Init(&Init);
struct statfs64 buf64;
int rc;
if ((rc = XrdPosix_Statfs(path, (struct statfs *)&buf64))) return rc;
memset(buf, 0, sizeof(struct statfs));
buf->f_type = buf64.f_type;
buf->f_bsize = buf64.f_bsize;
buf->f_blocks = buf64.f_blocks;
buf->f_bfree = buf64.f_bfree;
buf->f_files = buf64.f_files;
buf->f_ffree = buf64.f_ffree;
buf->f_fsid = buf64.f_fsid;
buf->f_namelen = buf64.f_namelen;
return 0;
}
}
#endif
/******************************************************************************/
/* s t a t v f s */
/******************************************************************************/
#if !defined(__macos__) && !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
int statvfs( const char *path, struct statvfs *buf)
{
static int Init = Xunix.Init(&Init);
struct statvfs64 buf64;
int rc;
if ((rc = XrdPosix_Statvfs(path, (struct statvfs *)&buf64))) return rc;
memset(buf, 0, sizeof(struct statvfs));
buf->f_flag = buf64.f_flag;
buf->f_bsize = buf64.f_bsize;
buf->f_blocks = buf64.f_blocks;
buf->f_bfree = buf64.f_bfree;
buf->f_files = buf64.f_files;
buf->f_ffree = buf64.f_ffree;
buf->f_fsid = buf64.f_fsid;
buf->f_namemax = buf64.f_namemax;
return 0;
}
}
#endif
/******************************************************************************/
/* t r u n c a t e */
/******************************************************************************/
#if !defined(SUNX86) && !defined(__FreeBSD__)
extern "C"
{
int truncate(const char *path, off_t offset)
{
static int Init = Xunix.Init(&Init);
return XrdPosix_Truncate(path, offset);
}
}
#endif