xrootd
XrdSfsInterface.hh
Go to the documentation of this file.
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 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /******************************************************************************/
00012 
00013 #include <string.h>      // For strlcpy()
00014 #include <sys/errno.h>
00015 #include <sys/types.h>
00016 #include <sys/stat.h>
00017 #include <sys/socket.h>  // for sockaddr
00018 
00019 #include "XrdOuc/XrdOucErrInfo.hh"
00020 
00021 /******************************************************************************/
00022 /*                            O p e n   M o d e s                             */
00023 /******************************************************************************/
00024 
00025 #define SFS_O_RDONLY           0         // open read/only
00026 #define SFS_O_WRONLY           1         // open write/only
00027 #define SFS_O_RDWR             2         // open read/write
00028 #define SFS_O_CREAT        0x100         // used for file creation
00029 #define SFS_O_TRUNC        0x200         // used for file truncation
00030 #define SFS_O_POSC     0x0100000         // persist on successful close
00031 #define SFS_O_NOWAIT  0x01000000         // do not impose operational delays
00032 #define SFS_O_RAWIO   0x02000000         // allow client-side decompression
00033 #define SFS_O_RESET   0x04000000         // Reset any cached information
00034 #define SFS_O_REPLICA 0x08000000         // Open for replication
00035 
00036 // The following flag may be set in the access mode arg for open() & mkdir()
00037 // Note that on some systems mode_t is 16-bits so we use a careful value!
00038 //
00039 #define SFS_O_MKPTH   0x00004000         // Make directory path if missing
00040 
00041 // The following options are here to provide a uniform clustering interface.
00042 // They may be passed through open/locate/stat, as applicable.
00043 //
00044 #define SFS_O_LOCATE  0x10000000         // This request generated by locate()
00045 #define SFS_O_STAT    0x20000000         // This request generated by stat()
00046 #define SFS_O_META    0x40000000         // This request generated by metaop
00047 
00048 /******************************************************************************/
00049 /*                               D e f i n e s                                */
00050 /******************************************************************************/
00051 
00052 // Common fctl  command values (0 to 255)
00053 //
00054 #define SFS_FCTL_GETFD    1 // Return file descriptor if possible
00055 #define SFS_FCTL_STATV    2 // Return visa information
00056 
00057 // Common fsctl command values (0 to 255)
00058 //
00059 #define SFS_FSCTL_CMD   255
00060 
00061 #define SFS_FSCTL_LOCATE  1 // Locate a file
00062 #define SFS_FSCTL_STATFS  2 // Return FS data
00063 #define SFS_FSCTL_STATLS  3 // Return LS data
00064 #define SFS_FSCTL_STATXA  4 // Return XA data
00065 #define SFS_FSCTL_PLUGIN  8 // Return Implementation Dependent Data
00066 #define SFS_FSCTL_PLUGIO 16 // Return Implementation Dependent Data
00067 
00068 // Return Values for Integer Returning XrdSfs Interface
00069 //
00070 #define SFS_STALL         1 // ErrInfo code -> Seconds to stall client
00071 #define SFS_OK            0 // ErrInfo code -> All is well
00072 #define SFS_ERROR        -1 // ErrInfo code -> Error occurred
00073 #define SFS_REDIRECT   -256 // ErrInfo code -> Port number to redirect to
00074 #define SFS_STARTED    -512 // ErrInfo code -> Estimated seconds to completion
00075 #define SFS_DATA      -1024 // ErrInfo code -> Length of data
00076 
00077 /******************************************************************************/
00078 /*                 S t r u c t u r e s   &   T y p e d e f s                  */
00079 /******************************************************************************/
00080 
00081 typedef long long     XrdSfsFileOffset;
00082 typedef int           XrdSfsFileOpenMode;
00083 typedef int           XrdSfsMode;
00084 typedef int           XrdSfsXferSize;
00085 
00086 enum XrdSfsFileExistence 
00087 {
00088      XrdSfsFileExistNo,
00089      XrdSfsFileExistIsFile,
00090      XrdSfsFileExistIsDirectory
00091 };
00092 //------------------------------------------------
00093 
00094 #define Prep_PRTY0 0
00095 #define Prep_PRTY1 1
00096 #define Prep_PRTY2 2
00097 #define Prep_PRTY3 3
00098 #define Prep_PMASK 3
00099 #define Prep_SENDAOK 4
00100 #define Prep_SENDERR 8
00101 #define Prep_SENDACK 12
00102 #define Prep_WMODE   16
00103 #define Prep_STAGE   32
00104 #define Prep_COLOC   64
00105 #define Prep_FRESH  128
00106 
00107 class XrdOucTList;
00108 
00109 struct XrdSfsFSctl // SFS_FSCTL_PLUGIN/PLUGIO parameters
00110 {
00111  const char            *Arg1;      // PLUGIO & PLUGIN
00112        int              Arg1Len;
00113        int              Arg2Len;
00114  const char            *Arg2;      // PLUGIN opaque string
00115 };
00116 
00117 struct XrdSfsPrep  // Prepare parameters
00118 {
00119        char            *reqid;     // Request ID
00120        char            *notify;    // Notification path or 0
00121        int              opts;      // Prep_xxx
00122        XrdOucTList     *paths;     // List of paths
00123        XrdOucTList     *oinfo;     // 1-to-1 correspondence of opaque info
00124 };
00125 
00126 /******************************************************************************/
00127 /*                      A b s t r a c t   C l a s s e s                       */
00128 /******************************************************************************/
00129 
00130 class  XrdSfsFile;
00131 class  XrdSfsDirectory;
00132 class  XrdOucTList;
00133 class  XrdSecEntity;
00134 
00135 /******************************************************************************/
00136 /*                      X r d S f s F i l e S y s t e m                       */
00137 /******************************************************************************/
00138   
00139 class XrdSfsFileSystem
00140 {
00141 public:
00142 
00143 // The following two methods allocate a directory or file object
00144 //
00145 virtual XrdSfsDirectory *newDir(char *user=0)  = 0;
00146 
00147 virtual XrdSfsFile      *newFile(char *user=0) = 0;
00148 
00149 // The following are filesystem related methods
00150 //
00151 
00152 enum    csFunc {csCalc = 0, csGet, csSize};
00153 
00154 virtual int            chksum(      csFunc            Func,
00155                               const char             *csName,
00156                               const char             *Path,
00157                                     XrdOucErrInfo    &out_error,
00158                               const XrdSecEntity     *client = 0,
00159                               const char             *opaque = 0)
00160                               {out_error.setErrInfo(ENOTSUP, "Not supported.");
00161                                return SFS_ERROR;
00162                               }
00163 
00164 virtual int            chmod(const char             *Name,
00165                                    XrdSfsMode        Mode,
00166                                    XrdOucErrInfo    &out_error,
00167                              const XrdSecEntity     *client = 0,
00168                              const char             *opaque = 0) = 0;
00169 
00170 virtual int            FSctl(const int               cmd,
00171                                    XrdSfsFSctl      &args,
00172                                    XrdOucErrInfo    &out_error,
00173                              const XrdSecEntity     *client = 0) {return SFS_OK;}
00174 
00175 virtual int            fsctl(const int               cmd,
00176                              const char             *args,
00177                                    XrdOucErrInfo    &out_error,
00178                              const XrdSecEntity     *client = 0) = 0;
00179 
00180 virtual int            getStats(char *buff, int blen) = 0;
00181 
00182 virtual const char    *getVersion() = 0;
00183 
00184 virtual int            exists(const char                *fileName,
00185                                     XrdSfsFileExistence &exists_flag,
00186                                     XrdOucErrInfo       &out_error,
00187                               const XrdSecEntity        *client = 0,
00188                               const char                *opaque = 0) = 0;
00189 
00190 virtual int            mkdir(const char             *dirName,
00191                                    XrdSfsMode         Mode,
00192                                    XrdOucErrInfo     &out_error,
00193                              const XrdSecEntity      *client = 0,
00194                              const char              *opaque = 0) = 0;
00195 
00196 virtual int            prepare(      XrdSfsPrep      &pargs,
00197                                      XrdOucErrInfo   &out_error,
00198                                const XrdSecEntity    *client = 0) = 0;
00199 
00200 virtual int            rem(const char                *path,
00201                                  XrdOucErrInfo       &out_error,
00202                            const XrdSecEntity        *client = 0,
00203                            const char                *opaque = 0) = 0;
00204 
00205 virtual int            remdir(const char             *dirName,
00206                                     XrdOucErrInfo    &out_error,
00207                               const XrdSecEntity     *client = 0,
00208                               const char             *opaque = 0) = 0;
00209 
00210 virtual int            rename(const char             *oldFileName,
00211                               const char             *newFileName,
00212                                     XrdOucErrInfo    &out_error,
00213                               const XrdSecEntity     *client = 0,
00214                               const char             *opaqueO = 0,
00215                               const char             *opaqueN = 0) = 0;
00216 
00217 virtual int            stat(const char               *Name,
00218                                   struct stat        *buf,
00219                                   XrdOucErrInfo      &out_error,
00220                             const XrdSecEntity       *client = 0,
00221                             const char               *opaque = 0) = 0;
00222 
00223 virtual int            stat(const char               *Name,
00224                                   mode_t             &mode,
00225                                   XrdOucErrInfo      &out_error,
00226                             const XrdSecEntity       *client = 0,
00227                             const char               *opaque = 0) = 0;
00228 
00229 virtual int            truncate(const char             *Name,
00230                                       XrdSfsFileOffset fileOffset,
00231                                       XrdOucErrInfo    &out_error,
00232                                 const XrdSecEntity     *client = 0,
00233                                 const char             *opaque = 0) = 0;
00234 
00235                        XrdSfsFileSystem() {}
00236 virtual               ~XrdSfsFileSystem() {}
00237 
00238 protected:
00239 };
00240 
00241 /******************************************************************************/
00242 /*              F i l e   S y s t e m   I n s t a n t i a t o r               */
00243 /******************************************************************************/
00244 
00245 /* When building a shared library plugin, the following "C" entry point must
00246    exist in the library:
00247 
00248    extern "C"
00249          {XrdSfsFileSystem *XrdSfsGetFileSystem(XrdSfsFileSystem *nativeFS,
00250                                                 XrdSysLogger     *Logger,
00251                                                 const char       *configFn);
00252          }
00253 
00254    This entry is called to get an instance of the file system. Return 0 if upon
00255    failure to properly create such an object. For statically linked file systems
00256    the non-extern C XrdSfsGetDefaultFileSystem() is used instead. It has a
00257    slightly different calling convention which adds an environment parameter
00258    as follows:
00259 
00260    XrdSfsFileSystem *XrdSfsGetDefaultFileSystem(XrdSfsFileSystem *nativeFS,
00261                                                 XrdSysLogger     *Logger,
00262                                                 const char       *configFn,
00263                                                 XrdOucEnv        *EnvInfo);
00264 */
00265 
00266 /******************************************************************************/
00267 /*                            X r d S f s F i l e                             */
00268 /******************************************************************************/
00269 
00270 class XrdSfsAio;
00271   
00272 class XrdSfsFile
00273 {
00274 public:
00275         XrdOucErrInfo  error;
00276 
00277 virtual int            open(const char                *fileName,
00278                                   XrdSfsFileOpenMode   openMode,
00279                                   mode_t               createMode,
00280                             const XrdSecEntity        *client = 0,
00281                             const char                *opaque = 0) = 0;
00282 
00283 virtual int            close() = 0;
00284 
00285 virtual int            fctl(const int               cmd,
00286                             const char             *args,
00287                                   XrdOucErrInfo    &out_error) = 0;
00288 
00289 virtual const char    *FName() = 0;
00290 
00291 virtual int            getMmap(void **Addr, off_t &Size) = 0;
00292 
00293 virtual int            read(XrdSfsFileOffset   fileOffset,
00294                             XrdSfsXferSize     preread_sz) = 0;
00295 
00296 virtual XrdSfsXferSize read(XrdSfsFileOffset   fileOffset,
00297                             char              *buffer,
00298                             XrdSfsXferSize     buffer_size) = 0;
00299 
00300 virtual int            read(XrdSfsAio *aioparm) = 0;
00301 
00302 virtual XrdSfsXferSize write(XrdSfsFileOffset  fileOffset,
00303                              const char       *buffer,
00304                              XrdSfsXferSize    buffer_size) = 0;
00305 
00306 virtual int            write(XrdSfsAio *aioparm) = 0;
00307 
00308 virtual int            stat(struct stat *buf) = 0;
00309 
00310 virtual int            sync() = 0;
00311 
00312 virtual int            sync(XrdSfsAio *aiop) = 0;
00313 
00314 virtual int            truncate(XrdSfsFileOffset fileOffset) = 0;
00315 
00316 virtual int            getCXinfo(char cxtype[4], int &cxrsz) = 0;
00317 
00318                        XrdSfsFile(const char *user=0) {error.setErrUser(user);}
00319 virtual               ~XrdSfsFile() {}
00320 
00321 }; // class XrdSfsFile
00322 
00323 /******************************************************************************/
00324 /*                       X r d S f s D i r e c t o r y                        */
00325 /******************************************************************************/
00326   
00327 class XrdSfsDirectory
00328 {
00329 public:
00330         XrdOucErrInfo error;
00331 
00332 virtual int         open(const char              *dirName,
00333                          const XrdSecEntity      *client = 0,
00334                          const char              *opaque = 0) = 0;
00335 
00336 virtual const char *nextEntry() = 0;
00337 
00338 virtual int         close() = 0;
00339 
00340 virtual const char *FName() = 0;
00341 
00342                     XrdSfsDirectory(const char *user=0) {error.setErrUser(user);}
00343 virtual            ~XrdSfsDirectory() {}
00344 
00345 }; // class XrdSfsDirectory
00346 #endif