00001 #ifndef __SFS_INTERFACE_H__ 00002 #define __SFS_INTERFACE_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S f s I n t e r f a c e . h h */ 00006 /* */ 00007 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <string.h> // For strlcpy() 00033 #include <errno.h> 00034 #include <sys/types.h> 00035 #include <sys/stat.h> 00036 00037 #include "XrdOuc/XrdOucErrInfo.hh" 00038 #include "XrdOuc/XrdOucIOVec.hh" 00039 #include "XrdOuc/XrdOucSFVec.hh" 00040 00041 /******************************************************************************/ 00042 /* O p e n M o d e s */ 00043 /******************************************************************************/ 00044 00045 #define SFS_O_RDONLY 0 // open read/only 00046 #define SFS_O_WRONLY 1 // open write/only 00047 #define SFS_O_RDWR 2 // open read/write 00048 #define SFS_O_CREAT 0x100 // used for file creation 00049 #define SFS_O_TRUNC 0x200 // used for file truncation 00050 #define SFS_O_POSC 0x0100000 // persist on successful close 00051 #define SFS_O_FORCE 0x0200000 // used for locate only 00052 #define SFS_O_HNAME 0x0400000 // used for locate only 00053 #define SFS_O_LOCAL 0x0800000 // used for locate only (local cmd) 00054 #define SFS_O_NOWAIT 0x01000000 // do not impose operational delays 00055 #define SFS_O_RAWIO 0x02000000 // allow client-side decompression 00056 #define SFS_O_RESET 0x04000000 // Reset any cached information 00057 #define SFS_O_REPLICA 0x08000000 // Open for replication 00058 00059 // The following flag may be set in the access mode arg for open() & mkdir() 00060 // Note that on some systems mode_t is 16-bits so we use a careful value! 00061 // 00062 #define SFS_O_MKPTH 0x00004000 // Make directory path if missing 00063 00064 // The following options are here to provide a uniform clustering interface. 00065 // They may be passed through open/locate/stat, as applicable. 00066 // 00067 #define SFS_O_LOCATE 0x10000000 // This request generated by locate() 00068 #define SFS_O_STAT 0x20000000 // This request generated by stat() 00069 #define SFS_O_META 0x40000000 // This request generated by metaop 00070 00071 /******************************************************************************/ 00072 /* D e f i n e s */ 00073 /******************************************************************************/ 00074 00075 // Common fctl command values (0 to 255) 00076 // 00077 #define SFS_FCTL_GETFD 1 // Return file descriptor if possible 00078 #define SFS_FCTL_STATV 2 // Return visa information 00079 #define SFS_FCTL_SPEC1 3 // Return implementation defined information 00080 00081 #define SFS_SFIO_FDVAL 0x80000000 // Use SendData() method GETFD response value 00082 00083 // Common fsctl command values (0 to 255) 00084 // 00085 #define SFS_FSCTL_CMD 255 00086 00087 #define SFS_FSCTL_LOCATE 1 // Locate a file 00088 #define SFS_FSCTL_STATFS 2 // Return FS data 00089 #define SFS_FSCTL_STATLS 3 // Return LS data 00090 #define SFS_FSCTL_STATXA 4 // Return XA data 00091 #define SFS_FSCTL_STATCC 5 // Return Cluster Config status 00092 #define SFS_FSCTL_PLUGIN 8 // Return Implementation Dependent Data 00093 #define SFS_FSCTL_PLUGIO 16 // Return Implementation Dependent Data 00094 00095 // Return values for integer & XrdSfsXferSize returning XrdSfs methods 00096 // 00097 #define SFS_STALL 1 // Return value -> Seconds to stall client 00098 #define SFS_OK 0 // ErrInfo code -> All is well 00099 #define SFS_ERROR -1 // ErrInfo code -> Error occurred 00100 #define SFS_REDIRECT -256 // ErrInfo code -> Port number to redirect to 00101 #define SFS_STARTED -512 // ErrInfo code -> Estimated seconds to completion 00102 #define SFS_DATA -1024 // ErrInfo code -> Length of data 00103 00104 // The following macros are used for dealing with special local paths 00105 // 00106 #define SFS_LCLPRFX "/=/" 00107 #define SFS_LCLPLEN 3 00108 #define SFS_LCLPATH(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN) 00109 #define SFS_LCLPRFY "/=" 00110 #define SFS_LCLROOT(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN-1) \ 00111 && (*(x+SFS_LCLPLEN-1) == '/' || *(x+SFS_LCLPLEN-1) == 0) 00112 00113 /******************************************************************************/ 00114 /* S t r u c t u r e s & T y p e d e f s */ 00115 /******************************************************************************/ 00116 00117 typedef long long XrdSfsFileOffset; 00118 typedef int XrdSfsFileOpenMode; 00119 typedef int XrdSfsMode; 00120 typedef int XrdSfsXferSize; 00121 00122 enum XrdSfsFileExistence 00123 { 00124 XrdSfsFileExistNo, 00125 XrdSfsFileExistIsFile, 00126 XrdSfsFileExistIsDirectory, 00127 XrdSfsFileExistIsOffline, 00128 XrdSfsFileExistIsOther 00129 }; 00130 //------------------------------------------------ 00131 00132 #define Prep_PRTY0 0 00133 #define Prep_PRTY1 1 00134 #define Prep_PRTY2 2 00135 #define Prep_PRTY3 3 00136 #define Prep_PMASK 3 00137 #define Prep_SENDAOK 4 00138 #define Prep_SENDERR 8 00139 #define Prep_SENDACK 12 00140 #define Prep_WMODE 16 00141 #define Prep_STAGE 32 00142 #define Prep_COLOC 64 00143 #define Prep_FRESH 128 00144 00145 class XrdOucTList; 00146 00147 struct XrdSfsFSctl 00148 { 00149 const char *Arg1; 00150 int Arg1Len; 00151 int Arg2Len; 00152 const char *Arg2; 00153 }; 00154 00155 struct XrdSfsPrep 00156 { 00157 char *reqid; 00158 char *notify; 00159 int opts; 00160 XrdOucTList *paths; 00161 XrdOucTList *oinfo; 00162 }; 00163 00164 /******************************************************************************/ 00165 /* A b s t r a c t C l a s s e s */ 00166 /******************************************************************************/ 00167 00168 class XrdSfsFile; 00169 class XrdSfsDirectory; 00170 class XrdOucEnv; 00171 class XrdOucTList; 00172 class XrdSecEntity; 00173 00174 /******************************************************************************/ 00175 /* X r d S f s F i l e S y s t e m */ 00176 /******************************************************************************/ 00177 00178 //----------------------------------------------------------------------------- 00202 //----------------------------------------------------------------------------- 00203 00204 class XrdSfsFileSystem 00205 { 00206 public: 00207 00208 //----------------------------------------------------------------------------- 00218 //----------------------------------------------------------------------------- 00219 00220 virtual XrdSfsDirectory *newDir(char *user=0, int MonID=0) = 0; 00221 00222 //----------------------------------------------------------------------------- 00232 //----------------------------------------------------------------------------- 00233 00234 virtual XrdSfsFile *newFile(char *user=0, int MonID=0) = 0; 00235 00236 //----------------------------------------------------------------------------- 00255 //----------------------------------------------------------------------------- 00256 00257 enum csFunc {csCalc = 0, csGet, csSize}; 00258 00259 virtual int chksum( csFunc Func, 00260 const char *csName, 00261 const char *path, 00262 XrdOucErrInfo &eInfo, 00263 const XrdSecEntity *client = 0, 00264 const char *opaque = 0) 00265 { 00266 (void)Func; (void)csName; (void)path; (void)eInfo; (void)client; 00267 (void)opaque; 00268 eInfo.setErrInfo(ENOTSUP, "Not supported."); 00269 return SFS_ERROR; 00270 } 00271 00272 //----------------------------------------------------------------------------- 00282 //----------------------------------------------------------------------------- 00283 00284 virtual int chmod(const char *path, 00285 XrdSfsMode mode, 00286 XrdOucErrInfo &eInfo, 00287 const XrdSecEntity *client = 0, 00288 const char *opaque = 0) = 0; 00289 00290 //----------------------------------------------------------------------------- 00294 //----------------------------------------------------------------------------- 00295 00296 virtual void Disc(const XrdSecEntity *client = 0) 00297 { 00298 (void)client; 00299 } 00300 00301 //----------------------------------------------------------------------------- 00306 //----------------------------------------------------------------------------- 00307 00308 virtual void EnvInfo(XrdOucEnv *envP) 00309 { 00310 (void)envP; 00311 } 00312 00313 //----------------------------------------------------------------------------- 00341 //----------------------------------------------------------------------------- 00342 00343 virtual int FSctl(const int cmd, 00344 XrdSfsFSctl &args, 00345 XrdOucErrInfo &eInfo, 00346 const XrdSecEntity *client = 0) 00347 { 00348 (void)cmd; (void)args; (void)eInfo; (void)client; 00349 return SFS_OK; 00350 } 00351 00352 //----------------------------------------------------------------------------- 00368 //----------------------------------------------------------------------------- 00369 00370 virtual int fsctl(const int cmd, 00371 const char *args, 00372 XrdOucErrInfo &eInfo, 00373 const XrdSecEntity *client = 0) = 0; 00374 00375 //----------------------------------------------------------------------------- 00385 //----------------------------------------------------------------------------- 00386 00387 virtual int getStats(char *buff, int blen) = 0; 00388 00389 //----------------------------------------------------------------------------- 00393 //----------------------------------------------------------------------------- 00394 00395 virtual const char *getVersion() = 0; 00396 00397 //----------------------------------------------------------------------------- 00413 //----------------------------------------------------------------------------- 00414 00415 virtual int exists(const char *path, 00416 XrdSfsFileExistence &eFlag, 00417 XrdOucErrInfo &eInfo, 00418 const XrdSecEntity *client = 0, 00419 const char *opaque = 0) = 0; 00420 00421 //----------------------------------------------------------------------------- 00431 //----------------------------------------------------------------------------- 00432 00433 virtual int mkdir(const char *path, 00434 XrdSfsMode mode, 00435 XrdOucErrInfo &eInfo, 00436 const XrdSecEntity *client = 0, 00437 const char *opaque = 0) = 0; 00438 00439 //----------------------------------------------------------------------------- 00447 //----------------------------------------------------------------------------- 00448 00449 virtual int prepare( XrdSfsPrep &pargs, 00450 XrdOucErrInfo &eInfo, 00451 const XrdSecEntity *client = 0) = 0; 00452 00453 //----------------------------------------------------------------------------- 00462 //----------------------------------------------------------------------------- 00463 00464 virtual int rem(const char *path, 00465 XrdOucErrInfo &eInfo, 00466 const XrdSecEntity *client = 0, 00467 const char *opaque = 0) = 0; 00468 00469 //----------------------------------------------------------------------------- 00478 //----------------------------------------------------------------------------- 00479 00480 virtual int remdir(const char *path, 00481 XrdOucErrInfo &eInfo, 00482 const XrdSecEntity *client = 0, 00483 const char *opaque = 0) = 0; 00484 00485 //----------------------------------------------------------------------------- 00496 //----------------------------------------------------------------------------- 00497 00498 virtual int rename(const char *oPath, 00499 const char *nPath, 00500 XrdOucErrInfo &eInfo, 00501 const XrdSecEntity *client = 0, 00502 const char *opaqueO = 0, 00503 const char *opaqueN = 0) = 0; 00504 00505 //----------------------------------------------------------------------------- 00516 //----------------------------------------------------------------------------- 00517 00518 virtual int stat(const char *Name, 00519 struct stat *buf, 00520 XrdOucErrInfo &eInfo, 00521 const XrdSecEntity *client = 0, 00522 const char *opaque = 0) = 0; 00523 00524 //----------------------------------------------------------------------------- 00536 //----------------------------------------------------------------------------- 00537 00538 virtual int stat(const char *path, 00539 mode_t &mode, 00540 XrdOucErrInfo &eInfo, 00541 const XrdSecEntity *client = 0, 00542 const char *opaque = 0) = 0; 00543 00544 //----------------------------------------------------------------------------- 00554 //----------------------------------------------------------------------------- 00555 00556 virtual int truncate(const char *path, 00557 XrdSfsFileOffset fsize, 00558 XrdOucErrInfo &eInfo, 00559 const XrdSecEntity *client = 0, 00560 const char *opaque = 0) = 0; 00561 00562 //----------------------------------------------------------------------------- 00564 //----------------------------------------------------------------------------- 00565 00566 XrdSfsFileSystem() {} 00567 virtual ~XrdSfsFileSystem() {} 00568 }; 00569 00570 /******************************************************************************/ 00571 /* F i l e S y s t e m I n s t a n t i a t o r */ 00572 /******************************************************************************/ 00573 00574 //----------------------------------------------------------------------------- 00593 //----------------------------------------------------------------------------- 00594 00595 //------------------------------------------------------------------------------ 00607 //------------------------------------------------------------------------------ 00608 00609 /******************************************************************************/ 00610 /* X r d S f s F i l e */ 00611 /******************************************************************************/ 00612 00613 //------------------------------------------------------------------------------ 00616 //------------------------------------------------------------------------------ 00617 00618 class XrdSfsAio; 00619 class XrdSfsDio; 00620 class XrdSfsXio; 00621 00622 class XrdSfsFile 00623 { 00624 public: 00625 00626 //----------------------------------------------------------------------------- 00629 //----------------------------------------------------------------------------- 00630 00631 XrdOucErrInfo error; 00632 00633 //----------------------------------------------------------------------------- 00654 //----------------------------------------------------------------------------- 00655 00656 virtual int open(const char *fileName, 00657 XrdSfsFileOpenMode openMode, 00658 mode_t createMode, 00659 const XrdSecEntity *client = 0, 00660 const char *opaque = 0) = 0; 00661 00662 //----------------------------------------------------------------------------- 00666 //----------------------------------------------------------------------------- 00667 00668 virtual int close() = 0; 00669 00670 //----------------------------------------------------------------------------- 00687 //----------------------------------------------------------------------------- 00688 00689 virtual int fctl(const int cmd, 00690 const char *args, 00691 XrdOucErrInfo &eInfo) = 0; 00692 00693 //----------------------------------------------------------------------------- 00706 //----------------------------------------------------------------------------- 00707 00708 virtual int fctl(const int cmd, 00709 int alen, 00710 const char *args, 00711 const XrdSecEntity *client = 0) 00712 { 00713 (void)cmd; (void)alen; (void)args; (void)client; 00714 return SFS_OK; 00715 } 00716 00717 //----------------------------------------------------------------------------- 00721 //----------------------------------------------------------------------------- 00722 00723 virtual const char *FName() = 0; 00724 00725 00726 //----------------------------------------------------------------------------- 00733 //----------------------------------------------------------------------------- 00734 00735 virtual int getMmap(void **Addr, off_t &Size) = 0; 00736 00737 //----------------------------------------------------------------------------- 00745 //----------------------------------------------------------------------------- 00746 00747 virtual XrdSfsXferSize read(XrdSfsFileOffset offset, 00748 XrdSfsXferSize size) = 0; 00749 00750 //----------------------------------------------------------------------------- 00759 //----------------------------------------------------------------------------- 00760 00761 virtual XrdSfsXferSize read(XrdSfsFileOffset offset, 00762 char *buffer, 00763 XrdSfsXferSize size) = 0; 00764 00765 //----------------------------------------------------------------------------- 00772 //----------------------------------------------------------------------------- 00773 00774 virtual XrdSfsXferSize read(XrdSfsAio *aioparm) = 0; 00775 00776 //----------------------------------------------------------------------------- 00786 //----------------------------------------------------------------------------- 00787 00788 virtual XrdSfsXferSize readv(XrdOucIOVec *readV, 00789 int rdvCnt) 00790 {XrdSfsXferSize rdsz, totbytes = 0; 00791 for (int i = 0; i < rdvCnt; i++) 00792 {rdsz = read(readV[i].offset, 00793 readV[i].data, readV[i].size); 00794 if (rdsz != readV[i].size) 00795 {if (rdsz < 0) return rdsz; 00796 error.setErrInfo(ESPIPE,"read past eof"); 00797 return SFS_ERROR; 00798 } 00799 totbytes += rdsz; 00800 } 00801 return totbytes; 00802 } 00803 00804 //----------------------------------------------------------------------------- 00814 //----------------------------------------------------------------------------- 00815 00816 virtual int SendData(XrdSfsDio *sfDio, 00817 XrdSfsFileOffset offset, 00818 XrdSfsXferSize size) 00819 { 00820 (void)sfDio; (void)offset; (void)size; 00821 return SFS_OK; 00822 } 00823 00824 //----------------------------------------------------------------------------- 00833 //----------------------------------------------------------------------------- 00834 00835 virtual XrdSfsXferSize write(XrdSfsFileOffset offset, 00836 const char *buffer, 00837 XrdSfsXferSize size) = 0; 00838 00839 //----------------------------------------------------------------------------- 00846 //----------------------------------------------------------------------------- 00847 00848 virtual int write(XrdSfsAio *aioparm) = 0; 00849 00850 //----------------------------------------------------------------------------- 00860 //----------------------------------------------------------------------------- 00861 00862 virtual XrdSfsXferSize writev(XrdOucIOVec *writeV, 00863 int wdvCnt) 00864 {XrdSfsXferSize wrsz, totbytes = 0; 00865 for (int i = 0; i < wdvCnt; i++) 00866 {wrsz = write(writeV[i].offset, 00867 writeV[i].data, writeV[i].size); 00868 if (wrsz != writeV[i].size) 00869 {if (wrsz < 0) return wrsz; 00870 error.setErrInfo(ESPIPE,"write past eof"); 00871 return SFS_ERROR; 00872 } 00873 totbytes += wrsz; 00874 } 00875 return totbytes; 00876 } 00877 00878 //----------------------------------------------------------------------------- 00885 //----------------------------------------------------------------------------- 00886 00887 virtual int stat(struct stat *buf) = 0; 00888 00889 //----------------------------------------------------------------------------- 00893 //----------------------------------------------------------------------------- 00894 00895 virtual int sync() = 0; 00896 00897 //----------------------------------------------------------------------------- 00902 //----------------------------------------------------------------------------- 00903 00904 virtual int sync(XrdSfsAio *aiop) = 0; 00905 00906 //----------------------------------------------------------------------------- 00912 //----------------------------------------------------------------------------- 00913 00914 virtual int truncate(XrdSfsFileOffset fsize) = 0; 00915 00916 //----------------------------------------------------------------------------- 00924 //----------------------------------------------------------------------------- 00925 00926 virtual int getCXinfo(char cxtype[4], int &cxrsz) = 0; 00927 00928 //----------------------------------------------------------------------------- 00932 //----------------------------------------------------------------------------- 00933 00934 virtual void setXio(XrdSfsXio *xioP) { (void)xioP; } 00935 00936 //----------------------------------------------------------------------------- 00943 //----------------------------------------------------------------------------- 00944 00945 XrdSfsFile(const char *user=0, int MonID=0) 00946 : error(user, MonID) {} 00947 00948 //----------------------------------------------------------------------------- 00950 //----------------------------------------------------------------------------- 00951 00952 virtual ~XrdSfsFile() {} 00953 00954 }; // class XrdSfsFile 00955 00956 /******************************************************************************/ 00957 /* X r d S f s D i r e c t o r y */ 00958 /******************************************************************************/ 00959 00960 //------------------------------------------------------------------------------ 00963 //------------------------------------------------------------------------------ 00964 00965 class XrdSfsDirectory 00966 { 00967 public: 00968 00969 //----------------------------------------------------------------------------- 00972 //----------------------------------------------------------------------------- 00973 00974 XrdOucErrInfo error; 00975 00976 //----------------------------------------------------------------------------- 00984 //----------------------------------------------------------------------------- 00985 00986 virtual int open(const char *path, 00987 const XrdSecEntity *client = 0, 00988 const char *opaque = 0) = 0; 00989 00990 //----------------------------------------------------------------------------- 00998 //----------------------------------------------------------------------------- 00999 01000 virtual const char *nextEntry() = 0; 01001 01002 //----------------------------------------------------------------------------- 01006 //----------------------------------------------------------------------------- 01007 01008 virtual int close() = 0; 01009 01010 //----------------------------------------------------------------------------- 01014 //----------------------------------------------------------------------------- 01015 01016 virtual const char *FName() = 0; 01017 01018 //----------------------------------------------------------------------------- 01024 //----------------------------------------------------------------------------- 01025 01026 virtual int autoStat(struct stat *buf) 01027 {(void)buf; 01028 error.setErrInfo(ENOTSUP, "Not supported."); 01029 return SFS_ERROR; 01030 } 01031 01032 //----------------------------------------------------------------------------- 01039 //----------------------------------------------------------------------------- 01040 01041 XrdSfsDirectory(const char *user=0, int MonID=0) 01042 : error(user, MonID) {} 01043 01044 //----------------------------------------------------------------------------- 01046 //----------------------------------------------------------------------------- 01047 01048 virtual ~XrdSfsDirectory() {} 01049 01050 }; // class XrdSfsDirectory 01051 #endif