XRootD
XrdPosix.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d P o s i x . c c */
4 /* */
5 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Andrew Hanushevsky for Stanford University under contract */
8 /* DE-AC02-76-SFO0515 with the Department of Energy */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 #include <cstdarg>
32 #include <cstdio>
33 #include <cstdlib>
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <fcntl.h>
38 #include <unistd.h>
39 #include <sys/uio.h>
40 
41 #include "XrdSys/XrdSysHeaders.hh"
45 
46 /******************************************************************************/
47 /* G l o b a l O b j e c t s */
48 /******************************************************************************/
49 
51 
53 
54 extern XrdPosixLinkage Xunix;
55 
56 /******************************************************************************/
57 /* U t i l i t y F u n c t i o n s */
58 /******************************************************************************/
59 
60 #ifdef MUSL
61 #include <stdio_ext.h>
62 #endif
63 
64 static inline void fseterr(FILE *fp)
65 {
66  /* Most systems provide FILE as a struct and the necessary bitmask in
67  <stdio.h>, because they need it for implementing getc() and putc() as
68  fast macros. This function is based on gnulib's fseterr.c */
69 #if defined _IO_ERR_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
70  /* GNU libc, BeOS, Haiku, Linux libc5 */
71  fp->_flags |= _IO_ERR_SEEN;
72 #elif defined __sferror || defined __APPLE__ || defined __DragonFly__ || defined __FreeBSD__ || defined __ANDROID__
73  /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
74  fp->_flags |= __SERR;
75 #elif defined _IOERR
76  /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */
77  fp->_flag |= _IOERR;
78 #elif defined __UCLIBC__ /* uClibc */
79  fp->__modeflags |= __FLAG_ERROR;
80 #elif defined MUSL /* musl libc */
81  __fseterr(fp);
82 #else
83  #error "Unsupported platform! Please report it as a bug."
84 #endif
85 }
86 
87 static inline void fseteof(FILE *fp)
88 {
89  /* Most systems provide FILE as a struct and the necessary bitmask in
90  <stdio.h>, because they need it for implementing getc() and putc() as
91  fast macros. */
92 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
93  /* GNU libc, BeOS, Haiku, Linux libc5 */
94  fp->_flags |= _IO_EOF_SEEN;
95 #elif defined __sferror || defined __APPLE__ || defined __DragonFly__ || defined __ANDROID__
96  /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
97  fp->_flags |= __SEOF;
98 #elif defined _IOEOF
99  /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */
100  fp->_flag |= _IOEOF;
101 #elif defined __UCLIBC__ /* uClibc */
102  fp->__modeflags |= __FLAG_EOF;
103 #else
104  (void) fseek(fp, 0L, SEEK_END);
105 #endif
106 }
107 
108 /******************************************************************************/
109 /* X r d P o s i x _ A c c e s s */
110 /******************************************************************************/
111 
112 extern "C"
113 {
114 int XrdPosix_Access(const char *path, int amode)
115 {
116  char *myPath, buff[2048];
117 
118 // Make sure a path was passed
119 //
120  if (!path) {errno = EFAULT; return -1;}
121 
122 // Return the results of a mkdir of a Unix file system
123 //
124  if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
125  return Xunix.Access( path, amode);
126 
127 // Return the results of our version of access()
128 //
129  return Xroot.Access(myPath, amode);
130 }
131 }
132 
133 /******************************************************************************/
134 /* X r d P o s i x _ A c l */
135 /******************************************************************************/
136 
137 // This is a required addition for Solaris 10+ systems
138 
139 extern "C"
140 {
141 int XrdPosix_Acl(const char *path, int cmd, int nentries, void *aclbufp)
142 {
143  return (XrootPath.URL(path, 0, 0)
144  ? Xunix.Acl("/tmp", cmd,nentries,aclbufp)
145  : Xunix.Acl(path, cmd,nentries,aclbufp));
146 }
147 }
148 
149 /******************************************************************************/
150 /* X r d P o s i x _ C h d i r */
151 /******************************************************************************/
152 
153 extern "C"
154 {
155 int XrdPosix_Chdir(const char *path)
156 {
157  int rc;
158 
159 // Set the working directory if the actual chdir succeeded
160 //
161  if (!(rc = Xunix.Chdir(path))) XrootPath.CWD(path);
162  return rc;
163 }
164 }
165 
166 /******************************************************************************/
167 /* X r d P o s i x _ C l o s e */
168 /******************************************************************************/
169 
170 extern "C"
171 {
172 int XrdPosix_Close(int fildes)
173 {
174 
175 // Return result of the close
176 //
177  return (Xroot.myFD(fildes) ? Xroot.Close(fildes) : Xunix.Close(fildes));
178 }
179 }
180 
181 /******************************************************************************/
182 /* X r d P o s i x _ C l o s e d i r */
183 /******************************************************************************/
184 
185 extern "C"
186 {
187 int XrdPosix_Closedir(DIR *dirp)
188 {
189 
190  return (Xroot.isXrootdDir(dirp) ? Xroot.Closedir(dirp)
191  : Xunix.Closedir(dirp));
192 }
193 }
194 
195 /******************************************************************************/
196 /* X r d P o s i x _ C r e a t */
197 /******************************************************************************/
198 
199 extern "C"
200 {
201 int XrdPosix_Creat(const char *path, mode_t mode)
202 {
203  extern int XrdPosix_Open(const char *path, int oflag, ...);
204 
205  return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
206 }
207 }
208 
209 /******************************************************************************/
210 /* X r d P o s i x _ F c l o s e */
211 /******************************************************************************/
212 
213 extern "C"
214 {
215 int XrdPosix_Fclose(FILE *stream)
216 {
217  int nullfd = fileno(stream);
218 
219 // Close the associated file
220 //
221  if (Xroot.myFD(nullfd)) Xroot.Close(nullfd);
222 
223 // Now close the stream
224 //
225  return Xunix.Fclose(stream);
226 }
227 }
228 
229 /******************************************************************************/
230 /* X r d P o s i x _ F c n t l */
231 /******************************************************************************/
232 
233 extern "C"
234 {
235 int XrdPosix_Fcntl(int fd, int cmd, ...)
236 {
237  va_list ap;
238  void *theArg;
239 
240  if (Xroot.myFD(fd)) return 0;
241  va_start(ap, cmd);
242  theArg = va_arg(ap, void *);
243  va_end(ap);
244  return Xunix.Fcntl64(fd, cmd, theArg);
245 }
246 }
247 
248 /******************************************************************************/
249 /* X r d P o s i x _ F d a t a s y n c */
250 /******************************************************************************/
251 
252 extern "C"
253 {
254 int XrdPosix_Fdatasync(int fildes)
255 {
256 
257 // Return the result of the sync
258 //
259  return (Xroot.myFD(fildes) ? Xroot.Fsync(fildes)
260  : Xunix.Fsync(fildes));
261 }
262 }
263 
264 /******************************************************************************/
265 /* X r d P o s i x _ F g e t x a t t r */
266 /******************************************************************************/
267 
268 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
269 extern "C"
270 {
271 ssize_t XrdPosix_Fgetxattr (int fd, const char *name, void *value, size_t size)
272 {
273  if (Xroot.myFD(fd)) {errno = ENOTSUP; return -1;}
274  return Xunix.Fgetxattr(fd, name, value, size);
275 }
276 }
277 #endif
278 
279 /******************************************************************************/
280 /* X r d P o s i x _ F f l u s h */
281 /******************************************************************************/
282 
283 extern "C"
284 {
285 int XrdPosix_Fflush(FILE *stream)
286 {
287 
288 // Return the result of the fseek
289 //
290  if (!stream || !Xroot.myFD(fileno(stream)))
291  return Xunix.Fflush(stream);
292 
293  return Xroot.Fsync(fileno(stream));
294 }
295 }
296 
297 /******************************************************************************/
298 /* X r d P o s i x _ F o p e n */
299 /******************************************************************************/
300 
301 #define ISMODE(x) !strcmp(mode, x)
302 
303 extern "C"
304 {
305 FILE *XrdPosix_Fopen(const char *path, const char *mode)
306 {
307  char *myPath, buff[2048];
308  int erc, fd, omode;
309  FILE *stream;
310 
311 // Transfer to unix if this is not our path
312 //
313  if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
314  return Xunix.Fopen64(path, mode);
315 
316 // Translate the mode flags
317 //
318  if (ISMODE("r") || ISMODE("rb")) omode = O_RDONLY;
319  else if (ISMODE("w") || ISMODE("wb")) omode = O_WRONLY
320  | O_CREAT | O_TRUNC;
321  else if (ISMODE("a") || ISMODE("ab")) omode = O_WRONLY
322  | O_CREAT | O_APPEND;
323  else if (ISMODE("r+") || ISMODE("rb+") || ISMODE("r+b")) omode = O_RDWR;
324  else if (ISMODE("w+") || ISMODE("wb+") || ISMODE("w+b")) omode = O_RDWR
325  | O_CREAT | O_TRUNC;
326  else if (ISMODE("a+") || ISMODE("ab+") || ISMODE("a+b")) omode = O_RDWR
327  | O_CREAT | O_APPEND;
328  else {errno = EINVAL; return 0;}
329 
330 // Now open the file
331 //
332  if ((fd = Xroot.Open(myPath, omode | XrdPosixXrootd::isStream , 0)) < 0)
333  return 0;
334 
335 // First obtain a free stream
336 //
337  if (!(stream = fdopen(fd, mode)))
338  {erc = errno; Xroot.Close(fd); errno = erc;}
339 
340 // All done
341 //
342  return stream;
343 }
344 }
345 
346 /******************************************************************************/
347 /* X r d P o s i x _ F r e a d */
348 /******************************************************************************/
349 
350 extern "C"
351 {
352 size_t XrdPosix_Fread(void *ptr, size_t size, size_t nitems, FILE *stream)
353 {
354  ssize_t bytes;
355  size_t rc = 0;
356  int fd = fileno(stream);
357 
358  if (!Xroot.myFD(fd)) return Xunix.Fread(ptr, size, nitems, stream);
359 
360  bytes = Xroot.Read(fd, ptr, size*nitems);
361 
362 // Get the right return code. Note that we cannot emulate the flags in sunx86
363 //
364  if (bytes > 0 && size) rc = bytes/size;
365  else if (bytes < 0) fseterr(stream);
366  else fseteof(stream);
367 
368  return rc;
369 }
370 }
371 
372 /******************************************************************************/
373 /* X r d P o s i x _ F s e e k */
374 /******************************************************************************/
375 
376 extern "C"
377 {
378 int XrdPosix_Fseek(FILE *stream, long offset, int whence)
379 {
380 
381 // Return the result of the fseek
382 //
383  if (!Xroot.myFD(fileno(stream)))
384  return Xunix.Fseek( stream, offset, whence);
385 
386  return (Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
387 }
388 }
389 
390 /******************************************************************************/
391 /* X r d P o s i x _ F s e e k o */
392 /******************************************************************************/
393 
394 extern "C"
395 {
396 int XrdPosix_Fseeko(FILE *stream, long long offset, int whence)
397 {
398 
399 // Return the result of the fseek
400 //
401  if (!Xroot.myFD(fileno(stream)))
402  return Xunix.Fseeko64(stream, offset, whence);
403 
404  return (Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
405 }
406 }
407 
408 /******************************************************************************/
409 /* X r d P o s i x _ F s t a t */
410 /******************************************************************************/
411 
412 extern "C"
413 {
414 int XrdPosix_Fstat(int fildes, struct stat *buf)
415 {
416 
417 // Return result of the close
418 //
419  return (Xroot.myFD(fildes)
420  ? Xroot.Fstat(fildes, buf)
421 #if defined(__linux__) and defined(_STAT_VER)
422  : Xunix.Fstat64(_STAT_VER, fildes, (struct stat64 *)buf));
423 #else
424  : Xunix.Fstat64( fildes, (struct stat64 *)buf));
425 #endif
426 }
427 
428 #ifdef __linux__
429 int XrdPosix_FstatV(int ver, int fildes, struct stat *buf)
430 {
431  return (Xroot.myFD(fildes)
432  ? Xroot.Fstat(fildes, buf)
433 #ifdef _STAT_VER
434  : Xunix.Fstat64(ver, fildes, (struct stat64 *)buf));
435 #else
436  : Xunix.Fstat64( fildes, (struct stat64 *)buf));
437 #endif
438 }
439 #endif
440 }
441 
442 /******************************************************************************/
443 /* X r d P o s i x _ F s y n c */
444 /******************************************************************************/
445 
446 extern "C"
447 {
448 int XrdPosix_Fsync(int fildes)
449 {
450 
451 // Return the result of the sync
452 //
453  return (Xroot.myFD(fildes) ? Xroot.Fsync(fildes)
454  : Xunix.Fsync(fildes));
455 }
456 }
457 
458 /******************************************************************************/
459 /* X r d P o s i x _ F t e l l */
460 /******************************************************************************/
461 
462 extern "C"
463 {
464 long XrdPosix_Ftell(FILE *stream)
465 {
466 
467 // Return the result of the tell
468 //
469  if (!Xroot.myFD(fileno(stream))) return Xunix.Ftell(stream);
470 
471  return static_cast<long>(Xroot.Lseek(fileno(stream), 0, SEEK_CUR));
472 }
473 }
474 
475 /******************************************************************************/
476 /* X r d P o s i x _ F t e l l o */
477 /******************************************************************************/
478 
479 extern "C"
480 {
481 long long XrdPosix_Ftello(FILE *stream)
482 {
483 
484 // Return the result of the tell
485 //
486  if (!Xroot.myFD(fileno(stream))) return Xunix.Ftello64(stream);
487 
488  return Xroot.Lseek(fileno(stream), 0, SEEK_CUR);
489 }
490 }
491 
492 /******************************************************************************/
493 /* X r d P o s i x _ F t r u n c a t e */
494 /******************************************************************************/
495 
496 extern "C"
497 {
498 int XrdPosix_Ftruncate(int fildes, long long offset)
499 {
500 
501 // Return the result of the ftruncate
502 //
503  return (Xroot.myFD(fildes) ? Xroot.Ftruncate (fildes, offset)
504  : Xunix.Ftruncate64(fildes, offset));
505 }
506 }
507 
508 /******************************************************************************/
509 /* X r d P o s i x _ F w r i t e */
510 /******************************************************************************/
511 
512 extern "C"
513 {
514 size_t XrdPosix_Fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream)
515 {
516  size_t bytes, rc = 0;
517  int fd = fileno(stream);
518 
519  if (!Xroot.myFD(fd)) return Xunix.Fwrite(ptr, size, nitems, stream);
520 
521  bytes = Xroot.Write(fd, ptr, size*nitems);
522 
523 // Get the right return code.
524 //
525  if (bytes > 0 && size) rc = bytes/size;
526  else fseterr(stream);
527 
528  return rc;
529 }
530 }
531 
532 /******************************************************************************/
533 /* X r d P o s i x _ G e t x a t t r */
534 /******************************************************************************/
535 
536 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
537 extern "C"
538 {
539 ssize_t XrdPosix_Getxattr (const char *path, const char *name, void *value, size_t size)
540 {
541  char *myPath, buff[2048];
542 
543  if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
544  return Xunix.Getxattr(path, name, value, size);
545 
546  return Xroot.Getxattr(myPath, name, value, size);
547 }
548 }
549 #endif
550 
551 /******************************************************************************/
552 /* X r d P o s i x _ L g e t x a t t r */
553 /******************************************************************************/
554 
555 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
556 extern "C"
557 {
558 ssize_t XrdPosix_Lgetxattr (const char *path, const char *name, void *value, size_t size)
559 {
560  if (XrootPath.URL(path, 0, 0)) {errno = ENOTSUP; return -1;}
561  return Xunix.Lgetxattr(path, name, value, size);
562 }
563 }
564 #endif
565 
566 /******************************************************************************/
567 /* X r d P o s i x _ L s e e k */
568 /******************************************************************************/
569 
570 extern "C"
571 {
572 off_t XrdPosix_Lseek(int fildes, off_t offset, int whence)
573 {
574 
575 // Return the operation of the seek
576 //
577  return (Xroot.myFD(fildes) ? Xroot.Lseek (fildes, offset, whence)
578  : Xunix.Lseek64(fildes, offset, whence));
579 }
580 }
581 
582 /******************************************************************************/
583 /* X r d P o s i x _ L s t a t */
584 /******************************************************************************/
585 
586 extern "C"
587 {
588 int XrdPosix_Lstat(const char *path, struct stat *buf)
589 {
590  char *myPath, buff[2048];
591 
592 // Make sure a path was passed
593 //
594  if (!path) {errno = EFAULT; return -1;}
595 
596 // Return the results of an open of a Unix file
597 //
598  return (!(myPath = XrootPath.URL(path, buff, sizeof(buff)))
599 #if defined(__linux__) and defined(_STAT_VER)
600  ? Xunix.Lstat64(_STAT_VER, path, (struct stat64 *)buf)
601 #else
602  ? Xunix.Lstat64( path, (struct stat64 *)buf)
603 #endif
604  : Xroot.Stat(myPath, buf));
605 }
606 }
607 
608 /******************************************************************************/
609 /* X r d P o s i x _ M k d i r */
610 /******************************************************************************/
611 
612 extern "C"
613 {
614 int XrdPosix_Mkdir(const char *path, mode_t mode)
615 {
616  char *myPath, buff[2048];
617 
618 // Make sure a path was passed
619 //
620  if (!path) {errno = EFAULT; return -1;}
621 
622 // Return the results of a mkdir of a Unix file system
623 //
624  if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
625  return Xunix.Mkdir(path, mode);
626 
627 // Return the results of an mkdir of an xrootd file system
628 //
629  return Xroot.Mkdir(myPath, mode);
630 }
631 }
632 
633 /******************************************************************************/
634 /* X r d P o s i x _ O p e n */
635 /******************************************************************************/
636 
637 extern "C"
638 {
639 int XrdPosix_Open(const char *path, int oflag, ...)
640 {
641  char *myPath, buff[2048];
642  va_list ap;
643  int mode;
644 
645 // Make sure a path was passed
646 //
647  if (!path) {errno = EFAULT; return -1;}
648 
649 // Return the results of an open of a Unix file
650 //
651  if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
652  {if (!(oflag & O_CREAT)) return Xunix.Open64(path, oflag);
653  va_start(ap, oflag);
654  mode = va_arg(ap, int);
655  va_end(ap);
656  return Xunix.Open64(path, oflag, (mode_t)mode);
657  }
658 
659 // Return the results of an open of an xrootd file
660 //
661  if (!(oflag & O_CREAT)) return Xroot.Open(myPath, oflag);
662  va_start(ap, oflag);
663  mode = va_arg(ap, int);
664  va_end(ap);
665  return Xroot.Open(myPath, oflag, (mode_t)mode);
666 }
667 }
668 
669 /******************************************************************************/
670 /* X r d P o s i x _ O p e n d i r */
671 /******************************************************************************/
672 
673 extern "C"
674 {
675 DIR* XrdPosix_Opendir(const char *path)
676 {
677  char *myPath, buff[2048];
678 
679 // Make sure a path was passed
680 //
681  if (!path) {errno = EFAULT; return 0;}
682 
683 // Unix opendir
684 //
685  if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
686  return Xunix.Opendir(path);
687 
688 // Xrootd opendir
689 //
690  return Xroot.Opendir(myPath);
691 }
692 }
693 
694 /******************************************************************************/
695 /* X r d P o s i x _ P a t h c o n f */
696 /******************************************************************************/
697 
698 // This is a required addition for Solaris 10+ systems
699 
700 extern "C"
701 {
702 long XrdPosix_Pathconf(const char *path, int name)
703 {
704  return (XrootPath.URL(path, 0, 0) ? Xunix.Pathconf("/tmp", name)
705  : Xunix.Pathconf(path, name));
706 }
707 }
708 
709 /******************************************************************************/
710 /* X r d P o s i x _ P r e a d */
711 /******************************************************************************/
712 
713 extern "C"
714 {
715 ssize_t XrdPosix_Pread(int fildes, void *buf, size_t nbyte, off_t offset)
716 {
717 
718 // Return the results of the read
719 //
720  return (Xroot.myFD(fildes) ? Xroot.Pread (fildes, buf, nbyte, offset)
721  : Xunix.Pread64(fildes, buf, nbyte, offset));
722 }
723 }
724 
725 /******************************************************************************/
726 /* X r d P o s i x _ P w r i t e */
727 /******************************************************************************/
728 
729 extern "C"
730 {
731 ssize_t XrdPosix_Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
732 {
733 
734 // Return the results of the write
735 //
736  return (Xroot.myFD(fildes) ? Xroot.Pwrite (fildes, buf, nbyte, offset)
737  : Xunix.Pwrite64(fildes, buf, nbyte, offset));
738 }
739 }
740 
741 /******************************************************************************/
742 /* X r d P o s i x _ R e a d */
743 /******************************************************************************/
744 
745 extern "C"
746 {
747 ssize_t XrdPosix_Read(int fildes, void *buf, size_t nbyte)
748 {
749 
750 // Return the results of the read
751 //
752  return (Xroot.myFD(fildes) ? Xroot.Read(fildes, buf, nbyte)
753  : Xunix.Read(fildes, buf, nbyte));
754 }
755 }
756 
757 /******************************************************************************/
758 /* X r d P o s i x _ R e a d v */
759 /******************************************************************************/
760 
761 extern "C"
762 {
763 ssize_t XrdPosix_Readv(int fildes, const struct iovec *iov, int iovcnt)
764 {
765 
766 // Return results of the readv
767 //
768  return (Xroot.myFD(fildes) ? Xroot.Readv(fildes, iov, iovcnt)
769  : Xunix.Readv(fildes, iov, iovcnt));
770 }
771 }
772 
773 /******************************************************************************/
774 /* X r d P o s i x _ R e a d d i r */
775 /******************************************************************************/
776 
777 extern "C"
778 {
779 // On some platforms both 32- and 64-bit versions are callable. so do the same
780 //
781 struct dirent * XrdPosix_Readdir (DIR *dirp)
782 {
783 
784 // Return result of readdir
785 //
786  return (Xroot.isXrootdDir(dirp) ? Xroot.Readdir(dirp)
787  : Xunix.Readdir(dirp));
788 }
789 
790 struct dirent64 * XrdPosix_Readdir64(DIR *dirp)
791 {
792 
793 // Return result of readdir
794 //
795  return (Xroot.isXrootdDir(dirp) ? Xroot.Readdir64(dirp)
796  : Xunix.Readdir64(dirp));
797 }
798 }
799 
800 /******************************************************************************/
801 /* X r d P o s i x _ R e a d d i r _ r */
802 /******************************************************************************/
803 
804 extern "C"
805 {
806 int XrdPosix_Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
807 {
808 
809 // Return result of readdir
810 //
811  return (Xroot.isXrootdDir(dirp) ? Xroot.Readdir_r(dirp,entry,result)
812  : Xunix.Readdir_r(dirp,entry,result));
813 }
814 
815 int XrdPosix_Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
816 {
817 
818 // Return result of readdir
819 //
820  return (Xroot.isXrootdDir(dirp) ? Xroot.Readdir64_r(dirp,entry,result)
821  : Xunix.Readdir64_r(dirp,entry,result));
822 }
823 }
824 
825 /******************************************************************************/
826 /* X r d P o s i x _ R e n a m e */
827 /******************************************************************************/
828 
829 extern "C"
830 {
831 int XrdPosix_Rename(const char *oldpath, const char *newpath)
832 {
833  char *oldPath, buffold[2048], *newPath, buffnew[2048];
834 
835 // Make sure a path was passed
836 //
837  if (!oldpath || !newpath) {errno = EFAULT; return -1;}
838 
839 // Return the results of a mkdir of a Unix file system
840 //
841  if (!(oldPath = XrootPath.URL(oldpath, buffold, sizeof(buffold)))
842  || !(newPath = XrootPath.URL(newpath, buffnew, sizeof(buffnew))))
843  return Xunix.Rename(oldpath, newpath);
844 
845 // Return the results of an mkdir of an xrootd file system
846 //
847  return Xroot.Rename(oldPath, newPath);
848 }
849 }
850 
851 /******************************************************************************/
852 /* X r d P o s i x _ R e w i n d d i r */
853 /******************************************************************************/
854 
855 extern "C"
856 {
857 void XrdPosix_Rewinddir(DIR *dirp)
858 {
859 
860 // Return result of rewind
861 //
862  return (Xroot.isXrootdDir(dirp) ? Xroot.Rewinddir(dirp)
863  : Xunix.Rewinddir(dirp));
864 }
865 }
866 
867 /******************************************************************************/
868 /* X r d P o s i x _ R m d i r */
869 /******************************************************************************/
870 
871 extern "C"
872 {
873 int XrdPosix_Rmdir(const char *path)
874 {
875  char *myPath, buff[2048];
876 
877 // Make sure a path was passed
878 //
879  if (!path) {errno = EFAULT; return -1;}
880 
881 // Return the results of a mkdir of a Unix file system
882 //
883  if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
884  return Xunix.Rmdir(path);
885 
886 // Return the results of an mkdir of an xrootd file system
887 //
888  return Xroot.Rmdir(myPath);
889 }
890 }
891 
892 /******************************************************************************/
893 /* X r d P o s i x _ S e e k d i r */
894 /******************************************************************************/
895 
896 extern "C"
897 {
898 void XrdPosix_Seekdir(DIR *dirp, long loc)
899 {
900 
901 // Call seekdir
902 //
903  (Xroot.isXrootdDir(dirp) ? Xroot.Seekdir(dirp, loc)
904  : Xunix.Seekdir(dirp, loc));
905 }
906 }
907 
908 /******************************************************************************/
909 /* X r d P o s i x _ S t a t */
910 /******************************************************************************/
911 
912 extern "C"
913 {
914 int XrdPosix_Stat(const char *path, struct stat *buf)
915 {
916  char *myPath, buff[2048];
917 
918 // Make sure a path was passed
919 //
920  if (!path) {errno = EFAULT; return -1;}
921 
922 // Return the results of an open of a Unix file
923 //
924  return (!(myPath = XrootPath.URL(path, buff, sizeof(buff)))
925 #if defined(__linux__) and defined(_STAT_VER)
926  ? Xunix.Stat64(_STAT_VER, path, (struct stat64 *)buf)
927 #else
928  ? Xunix.Stat64( path, (struct stat64 *)buf)
929 #endif
930  : Xroot.Stat(myPath, buf));
931 }
932 }
933 
934 /******************************************************************************/
935 /* X r d P o s i x _ S t a t f s */
936 /******************************************************************************/
937 
938 extern "C"
939 {
940 int XrdPosix_Statfs(const char *path, struct statfs *buf)
941 {
942  char *myPath, buff[2048];
943 
944 // Make sure a path was passed
945 //
946  if (!path) {errno = EFAULT; return -1;}
947 
948 // Return the results of an open of a Unix file
949 //
950  return ((myPath = XrootPath.URL(path, buff, sizeof(buff)))
951  ? Xroot.Statfs(myPath, buf)
952  : Xunix.Statfs64(path, (struct statfs64 *)buf));
953 }
954 }
955 
956 /******************************************************************************/
957 /* X r d P o s i x _ S t a t v f s */
958 /******************************************************************************/
959 
960 extern "C"
961 {
962 int XrdPosix_Statvfs(const char *path, struct statvfs *buf)
963 {
964  char *myPath, buff[2048];
965 
966 // Make sure a path was passed
967 //
968  if (!path) {errno = EFAULT; return -1;}
969 
970 // Return the results of an open of a Unix file
971 //
972  return ((myPath = XrootPath.URL(path, buff, sizeof(buff)))
973  ? Xroot.Statvfs(myPath, buf)
974  : Xunix.Statvfs64(path, (struct statvfs64 *)buf));
975 }
976 }
977 
978 /******************************************************************************/
979 /* X r d P o s i x _ T e l l d i r */
980 /******************************************************************************/
981 
982 extern "C"
983 {
984 long XrdPosix_Telldir(DIR *dirp)
985 {
986 
987 // Return result of telldir
988 //
989  return (Xroot.isXrootdDir(dirp) ? Xroot.Telldir(dirp)
990  : Xunix.Telldir(dirp));
991 }
992 }
993 
994 /******************************************************************************/
995 /* X r d P o s i x _ T r u n c a t e */
996 /******************************************************************************/
997 
998 extern "C"
999 {
1000 int XrdPosix_Truncate(const char *path, off_t offset)
1001 {
1002  char *myPath, buff[2048];
1003 
1004 // Make sure a path was passed
1005 //
1006  if (!path) {errno = EFAULT; return -1;}
1007 
1008 // Return the results of a truncate of a Unix file system
1009 //
1010  if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
1011  return Xunix.Truncate64(path, offset);
1012 
1013 // Return the results of an truncate of an xrootd file system
1014 //
1015  return Xroot.Truncate(myPath, offset);
1016 }
1017 }
1018 
1019 /******************************************************************************/
1020 /* X r d P o s i x _ U n l i n k */
1021 /******************************************************************************/
1022 
1023 extern "C"
1024 {
1025 int XrdPosix_Unlink(const char *path)
1026 {
1027  char *myPath, buff[2048];
1028 
1029 // Make sure a path was passed
1030 //
1031  if (!path) {errno = EFAULT; return -1;}
1032 
1033 // Return the result of a unlink of a Unix file
1034 //
1035  if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
1036  return Xunix.Unlink(path);
1037 
1038 // Return the results of an unlink of an xrootd file
1039 //
1040  return Xroot.Unlink(myPath);
1041 }
1042 }
1043 
1044 /******************************************************************************/
1045 /* X r d P o s i x _ W r i t e */
1046 /******************************************************************************/
1047 
1048 extern "C"
1049 {
1050 ssize_t XrdPosix_Write(int fildes, const void *buf, size_t nbyte)
1051 {
1052 
1053 // Return the results of the write
1054 //
1055  return (Xroot.myFD(fildes) ? Xroot.Write(fildes, buf, nbyte)
1056  : Xunix.Write(fildes, buf, nbyte));
1057 }
1058 }
1059 
1060 /******************************************************************************/
1061 /* X r d P o s i x _ W r i t e v */
1062 /******************************************************************************/
1063 
1064 extern "C"
1065 {
1066 ssize_t XrdPosix_Writev(int fildes, const struct iovec *iov, int iovcnt)
1067 {
1068 
1069 // Return results of the writev
1070 //
1071  return (Xroot.myFD(fildes) ? Xroot.Writev(fildes, iov, iovcnt)
1072  : Xunix.Writev(fildes, iov, iovcnt));
1073 }
1074 }
1075 
1076 /******************************************************************************/
1077 /* X r d P o s i x _ i s M y P a t h */
1078 /******************************************************************************/
1079 
1080 int XrdPosix_isMyPath(const char *path)
1081 {
1082  return (0 != XrootPath.URL(path, 0, 0));
1083 }
1084 
1085 /******************************************************************************/
1086 /* X r d P o s i x _ U R L */
1087 /******************************************************************************/
1088 
1089 char *XrdPosix_URL(const char *path, char *buff, int blen)
1090 {
1091  return XrootPath.URL(path, buff, blen);
1092 }
int statvfs64(const char *path, struct statvfs64 *buf)
int fseek(FILE *stream, long offset, int whence)
int statfs64(const char *path, struct statfs64 *buf)
int stat64(const char *path, struct stat64 *buf)
int XrdPosix_Statfs(const char *path, struct statfs *buf)
Definition: XrdPosix.cc:940
int XrdPosix_Truncate(const char *path, off_t offset)
Definition: XrdPosix.cc:1000
ssize_t XrdPosix_Read(int fildes, void *buf, size_t nbyte)
Definition: XrdPosix.cc:747
#define ISMODE(x)
Definition: XrdPosix.cc:301
int XrdPosix_Closedir(DIR *dirp)
Definition: XrdPosix.cc:187
int XrdPosix_Fsync(int fildes)
Definition: XrdPosix.cc:448
ssize_t XrdPosix_Readv(int fildes, const struct iovec *iov, int iovcnt)
Definition: XrdPosix.cc:763
static void fseterr(FILE *fp)
Definition: XrdPosix.cc:64
int XrdPosix_isMyPath(const char *path)
Definition: XrdPosix.cc:1080
long long XrdPosix_Ftello(FILE *stream)
Definition: XrdPosix.cc:481
int XrdPosix_Open(const char *path, int oflag,...)
Definition: XrdPosix.cc:639
void XrdPosix_Rewinddir(DIR *dirp)
Definition: XrdPosix.cc:857
ssize_t XrdPosix_Pread(int fildes, void *buf, size_t nbyte, off_t offset)
Definition: XrdPosix.cc:715
int XrdPosix_Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
Definition: XrdPosix.cc:815
int XrdPosix_Close(int fildes)
Definition: XrdPosix.cc:172
void XrdPosix_Seekdir(DIR *dirp, long loc)
Definition: XrdPosix.cc:898
int XrdPosix_Rmdir(const char *path)
Definition: XrdPosix.cc:873
int XrdPosix_Chdir(const char *path)
Definition: XrdPosix.cc:155
FILE * XrdPosix_Fopen(const char *path, const char *mode)
Definition: XrdPosix.cc:305
int XrdPosix_Stat(const char *path, struct stat *buf)
Definition: XrdPosix.cc:914
int XrdPosix_Rename(const char *oldpath, const char *newpath)
Definition: XrdPosix.cc:831
int XrdPosix_Fcntl(int fd, int cmd,...)
Definition: XrdPosix.cc:235
int XrdPosix_Fseek(FILE *stream, long offset, int whence)
Definition: XrdPosix.cc:378
long XrdPosix_Ftell(FILE *stream)
Definition: XrdPosix.cc:464
static void fseteof(FILE *fp)
Definition: XrdPosix.cc:87
int XrdPosix_Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
Definition: XrdPosix.cc:806
XrdPosixXrootd Xroot
Definition: XrdPosix.cc:50
int XrdPosix_Mkdir(const char *path, mode_t mode)
Definition: XrdPosix.cc:614
int XrdPosix_Fflush(FILE *stream)
Definition: XrdPosix.cc:285
char * XrdPosix_URL(const char *path, char *buff, int blen)
Definition: XrdPosix.cc:1089
ssize_t XrdPosix_Writev(int fildes, const struct iovec *iov, int iovcnt)
Definition: XrdPosix.cc:1066
XrdPosixXrootPath XrootPath
Definition: XrdPosix.cc:52
DIR * XrdPosix_Opendir(const char *path)
Definition: XrdPosix.cc:675
long XrdPosix_Telldir(DIR *dirp)
Definition: XrdPosix.cc:984
ssize_t XrdPosix_Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
Definition: XrdPosix.cc:731
int XrdPosix_Lstat(const char *path, struct stat *buf)
Definition: XrdPosix.cc:588
int XrdPosix_Creat(const char *path, mode_t mode)
Definition: XrdPosix.cc:201
int XrdPosix_Statvfs(const char *path, struct statvfs *buf)
Definition: XrdPosix.cc:962
int XrdPosix_Acl(const char *path, int cmd, int nentries, void *aclbufp)
Definition: XrdPosix.cc:141
int XrdPosix_Fstat(int fildes, struct stat *buf)
Definition: XrdPosix.cc:414
off_t XrdPosix_Lseek(int fildes, off_t offset, int whence)
Definition: XrdPosix.cc:572
ssize_t XrdPosix_Write(int fildes, const void *buf, size_t nbyte)
Definition: XrdPosix.cc:1050
XrdPosixLinkage Xunix
size_t XrdPosix_Fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream)
Definition: XrdPosix.cc:514
int XrdPosix_Fclose(FILE *stream)
Definition: XrdPosix.cc:215
int XrdPosix_Fdatasync(int fildes)
Definition: XrdPosix.cc:254
int XrdPosix_Ftruncate(int fildes, long long offset)
Definition: XrdPosix.cc:498
struct dirent64 * XrdPosix_Readdir64(DIR *dirp)
Definition: XrdPosix.cc:790
long XrdPosix_Pathconf(const char *path, int name)
Definition: XrdPosix.cc:702
struct dirent * XrdPosix_Readdir(DIR *dirp)
Definition: XrdPosix.cc:781
int XrdPosix_Unlink(const char *path)
Definition: XrdPosix.cc:1025
size_t XrdPosix_Fread(void *ptr, size_t size, size_t nitems, FILE *stream)
Definition: XrdPosix.cc:352
int XrdPosix_Fseeko(FILE *stream, long long offset, int whence)
Definition: XrdPosix.cc:396
int XrdPosix_Access(const char *path, int amode)
Definition: XrdPosix.cc:114
#define statvfs(a, b)
Definition: XrdPosix.hh:105
#define stat(a, b)
Definition: XrdPosix.hh:101
#define statfs(a, b)
Definition: XrdPosix.hh:103
Retv_Opendir(* Opendir)(Args_Opendir)
Retv_Mkdir(* Mkdir)(Args_Mkdir)
Retv_Readdir64(* Readdir64)(Args_Readdir64)
Retv_Fflush(* Fflush)(Args_Fflush)
Retv_Fstat64(* Fstat64)(Args_Fstat64)
Retv_Fclose(* Fclose)(Args_Fclose)
Retv_Fseek(* Fseek)(Args_Fseek)
Retv_Fwrite(* Fwrite)(Args_Fwrite)
Retv_Acl(* Acl)(Args_Acl)
Retv_Writev(* Writev)(Args_Writev)
Retv_Read(* Read)(Args_Read)
Retv_Fsync(* Fsync)(Args_Fsync)
Retv_Rename(* Rename)(Args_Rename)
Retv_Close(* Close)(Args_Close)
Retv_Statfs64(* Statfs64)(Args_Statfs64)
Retv_Lgetxattr(* Lgetxattr)(Args_Lgetxattr)
Retv_Ftruncate64(* Ftruncate64)(Args_Ftruncate64)
Retv_Rewinddir(* Rewinddir)(Args_Rewinddir)
Retv_Readdir(* Readdir)(Args_Readdir)
Retv_Lseek64(* Lseek64)(Args_Lseek64)
Retv_Statvfs64(* Statvfs64)(Args_Statvfs64)
Retv_Truncate64(* Truncate64)(Args_Truncate64)
Retv_Ftell(* Ftell)(Args_Ftell)
Retv_Fread(* Fread)(Args_Fread)
Retv_Open64(* Open64)(Args_Open64)
Retv_Fopen64(* Fopen64)(Args_Fopen64)
Retv_Telldir(* Telldir)(Args_Telldir)
Retv_Fseeko64(* Fseeko64)(Args_Fseeko64)
Retv_Readv(* Readv)(Args_Readv)
Retv_Stat64(* Stat64)(Args_Stat64)
Retv_Pread64(* Pread64)(Args_Pread64)
Retv_Readdir64_r(* Readdir64_r)(Args_Readdir64_r)
Retv_Fcntl64(* Fcntl64)(Args_Fcntl64)
Retv_Seekdir(* Seekdir)(Args_Seekdir)
Retv_Lstat64(* Lstat64)(Args_Lstat64)
Retv_Chdir(* Chdir)(Args_Chdir)
Retv_Getxattr(* Getxattr)(Args_Getxattr)
Retv_Access(* Access)(Args_Access)
Retv_Closedir(* Closedir)(Args_Closedir)
Retv_Pathconf(* Pathconf)(Args_Pathconf)
Retv_Write(* Write)(Args_Write)
Retv_Readdir_r(* Readdir_r)(Args_Readdir_r)
Retv_Rmdir(* Rmdir)(Args_Rmdir)
Retv_Fgetxattr(* Fgetxattr)(Args_Fgetxattr)
Retv_Unlink(* Unlink)(Args_Unlink)
Retv_Pwrite64(* Pwrite64)(Args_Pwrite64)
Retv_Ftello64(* Ftello64)(Args_Ftello64)
char * URL(const char *path, char *buff, int blen)
void CWD(const char *path)
POSIX interface to XRootD with some extensions, as noted.
static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt)
Readv() conforms to POSIX.1-2001 readv()
static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset)
Pread() conforms to POSIX.1-2001 pread()
static int Closedir(DIR *dirp)
Closedir() conforms to POSIX.1-2001 closedir()
static void Seekdir(DIR *dirp, long loc)
Seekdir() conforms to POSIX.1-2001 seekdir()
static const int isStream
static int Stat(const char *path, struct stat *buf)
Stat() conforms to POSIX.1-2001 stat()
static int Mkdir(const char *path, mode_t mode)
Mkdir() conforms to POSIX.1-2001 mkdir()
static int Unlink(const char *path)
Unlink() conforms to POSIX.1-2001 unlink()
static int Rmdir(const char *path)
Rmdir() conforms to POSIX.1-2001 rmdir()
static void Rewinddir(DIR *dirp)
Rewinddir() conforms to POSIX.1-2001 rewinddir()
static int Rename(const char *oldpath, const char *newpath)
Rename() conforms to POSIX.1-2001 rename()
static int Close(int fildes)
Close() conforms to POSIX.1-2001 close()
static int Statvfs(const char *path, struct statvfs *buf)
Statvfs() conforms to POSIX.1-2001 statvfs()
static ssize_t Write(int fildes, const void *buf, size_t nbyte)
Write() conforms to POSIX.1-2001 write()
static struct dirent * Readdir(DIR *dirp)
static int Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt)
Writev() conforms to POSIX.1-2001 writev()
static struct dirent64 * Readdir64(DIR *dirp)
static bool myFD(int fd)
static int Ftruncate(int fildes, off_t offset)
Ftruncate() conforms to POSIX.1-2001 ftruncate()
static long Telldir(DIR *dirp)
Telldir() conforms to POSIX.1-2001 telldir()
static bool isXrootdDir(DIR *dirp)
static int Access(const char *path, int amode)
Access() conforms to POSIX.1-2001 access()
static DIR * Opendir(const char *path)
Opendir() conforms to POSIX.1-2001 opendir()
static int Fsync(int fildes)
Fsync() conforms to POSIX.1-2001 fsync()
static long long Getxattr(const char *path, const char *name, void *value, unsigned long long size)
static int Statfs(const char *path, struct statfs *buf)
static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
static ssize_t Read(int fildes, void *buf, size_t nbyte)
Read() conforms to POSIX.1-2001 read()
static int Fstat(int fildes, struct stat *buf)
Fstat() conforms to POSIX.1-2001 fstat()
static off_t Lseek(int fildes, off_t offset, int whence)
Lseek() conforms to POSIX.1-2001 lseek()
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
Pwrite() conforms to POSIX.1-2001 pwrite()
static int Truncate(const char *path, off_t offset)
Telldir() conforms to POSIX.1-2001 telldir()