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