xrootd
XrdSfsNative.hh
Go to the documentation of this file.
00001 #ifndef __SFS_NATIVE_H__
00002 #define __SFS_NATIVE_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                       X r d S f s N a t i v e . h h                        */
00006 /*                                                                            */
00007 /* (c) 2004 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 <sys/types.h>
00033 #include <string.h>
00034 #include <dirent.h>
00035   
00036 #include "XrdSfs/XrdSfsInterface.hh"
00037 
00038 class XrdSysError;
00039 class XrdSysLogger;
00040 
00041 /******************************************************************************/
00042 /*                 X r d S f s N a t i v e D i r e c t o r y                  */
00043 /******************************************************************************/
00044   
00045 class XrdSfsNativeDirectory : public XrdSfsDirectory
00046 {
00047 public:
00048 
00049         int         open(const char              *dirName,
00050                          const XrdSecClientName  *client = 0,
00051                          const char              *opaque = 0);
00052 
00053         const char *nextEntry();
00054 
00055         int         close();
00056 
00057 const   char       *FName() {return (const char *)fname;}
00058 
00059                     XrdSfsNativeDirectory(char *user=0, int monid=0)
00060                                 : XrdSfsDirectory(user, monid)
00061                                 {ateof = 0; fname = 0;
00062                                  dh    = (DIR *)0;
00063                                  d_pnt = &dirent_full.d_entry;
00064                                 }
00065 
00066                    ~XrdSfsNativeDirectory() {if (dh) close();}
00067 private:
00068 
00069 DIR           *dh;  // Directory stream handle
00070 char           ateof;
00071 char          *fname;
00072 
00073 struct {struct dirent d_entry;
00074                char   pad[MAXNAMLEN];   // This is only required for Solaris!
00075        } dirent_full;
00076 
00077 struct dirent *d_pnt;
00078 
00079 };
00080 
00081 /******************************************************************************/
00082 /*                      X r d S f s N a t i v e F i l e                       */
00083 /******************************************************************************/
00084   
00085 class XrdSfsAio;
00086 
00087 class XrdSfsNativeFile : public XrdSfsFile
00088 {
00089 public:
00090 
00091         int            open(const char                *fileName,
00092                                   XrdSfsFileOpenMode   openMode,
00093                                   mode_t               createMode,
00094                             const XrdSecClientName    *client = 0,
00095                             const char                *opaque = 0);
00096 
00097         int            close();
00098 
00099         int            fctl(const int               cmd,
00100                             const char             *args,
00101                                   XrdOucErrInfo    &out_error);
00102 
00103         const char    *FName() {return fname;}
00104 
00105         int            getMmap(void **Addr, off_t &Size)
00106                               {if (Addr) Addr = 0; Size = 0; return SFS_OK;}
00107 
00108         int            read(XrdSfsFileOffset   fileOffset,
00109                             XrdSfsXferSize     preread_sz) {return SFS_OK;}
00110 
00111         XrdSfsXferSize read(XrdSfsFileOffset   fileOffset,
00112                             char              *buffer,
00113                             XrdSfsXferSize     buffer_size);
00114 
00115         int            read(XrdSfsAio *aioparm);
00116 
00117         XrdSfsXferSize write(XrdSfsFileOffset   fileOffset,
00118                              const char        *buffer,
00119                              XrdSfsXferSize     buffer_size);
00120 
00121         int            write(XrdSfsAio *aioparm);
00122 
00123         int            sync();
00124 
00125         int            sync(XrdSfsAio *aiop);
00126 
00127         int            stat(struct stat *buf);
00128 
00129         int            truncate(XrdSfsFileOffset   fileOffset);
00130 
00131         int            getCXinfo(char cxtype[4], int &cxrsz) {return cxrsz = 0;}
00132 
00133                        XrdSfsNativeFile(char *user=0, int monid=0)
00134                                        : XrdSfsFile(user, monid)
00135                                           {oh = -1; fname = 0;}
00136                       ~XrdSfsNativeFile() {if (oh) close();}
00137 private:
00138 
00139 int   oh;
00140 char *fname;
00141 
00142 };
00143 
00144 /******************************************************************************/
00145 /*                          X r d S f s N a t i v e                           */
00146 /******************************************************************************/
00147   
00148 class XrdSfsNative : public XrdSfsFileSystem
00149 {
00150 public:
00151 
00152 // Object Allocation Functions
00153 //
00154         XrdSfsDirectory *newDir(char *user=0, int monid=0)
00155                         {return (XrdSfsDirectory *)new XrdSfsNativeDirectory(user,monid);}
00156 
00157         XrdSfsFile      *newFile(char *user=0,int monid=0)
00158                         {return      (XrdSfsFile *)new XrdSfsNativeFile(user,monid);}
00159 
00160 // Other Functions
00161 //
00162         int            chmod(const char             *Name,
00163                                    XrdSfsMode        Mode,
00164                                    XrdOucErrInfo    &out_error,
00165                              const XrdSecClientName *client = 0,
00166                              const char             *opaque = 0);
00167 
00168         int            exists(const char                *fileName,
00169                                     XrdSfsFileExistence &exists_flag,
00170                                     XrdOucErrInfo       &out_error,
00171                               const XrdSecClientName    *client = 0,
00172                               const char                *opaque = 0);
00173 
00174         int            fsctl(const int               cmd,
00175                              const char             *args,
00176                                    XrdOucErrInfo    &out_error,
00177                              const XrdSecClientName *client = 0);
00178 
00179         int            getStats(char *buff, int blen) {return 0;}
00180 
00181 const   char          *getVersion();
00182 
00183         int            mkdir(const char             *dirName,
00184                                    XrdSfsMode        Mode,
00185                                    XrdOucErrInfo    &out_error,
00186                              const XrdSecClientName *client = 0,
00187                              const char             *opaque = 0);
00188 
00189         int            prepare(      XrdSfsPrep       &pargs,
00190                                      XrdOucErrInfo    &out_error,
00191                                const XrdSecClientName *client = 0) {return 0;}
00192 
00193         int            rem(const char             *path,
00194                                  XrdOucErrInfo    &out_error,
00195                            const XrdSecClientName *client = 0,
00196                            const char             *opaque = 0);
00197 
00198         int            remdir(const char             *dirName,
00199                                     XrdOucErrInfo    &out_error,
00200                               const XrdSecClientName *client = 0,
00201                               const char             *opaque = 0);
00202 
00203         int            rename(const char             *oldFileName,
00204                               const char             *newFileName,
00205                                     XrdOucErrInfo    &out_error,
00206                               const XrdSecClientName *client = 0,
00207                               const char             *opaqueO = 0,
00208                               const char             *opaqueN = 0);
00209 
00210         int            stat(const char             *Name,
00211                                   struct stat      *buf,
00212                                   XrdOucErrInfo    &out_error,
00213                             const XrdSecClientName *client = 0,
00214                             const char             *opaque = 0);
00215 
00216         int            stat(const char             *Name,
00217                                   mode_t           &mode,
00218                                   XrdOucErrInfo    &out_error,
00219                             const XrdSecClientName *client = 0,
00220                             const char             *opaque = 0)
00221                        {struct stat bfr;
00222                         int rc = stat(Name, &bfr, out_error, client);
00223                         if (!rc) mode = bfr.st_mode;
00224                         return rc;
00225                        }
00226 
00227         int            truncate(const char             *Name,
00228                                       XrdSfsFileOffset fileOffset,
00229                                       XrdOucErrInfo    &out_error,
00230                                 const XrdSecEntity     *client = 0,
00231                                 const char             *opaque = 0);
00232 
00233 // Common functions
00234 //
00235 static  int            Mkpath(const char *path, mode_t mode, 
00236                               const char *info=0);
00237 
00238 static  int            Emsg(const char *, XrdOucErrInfo&, int, const char *x,
00239                             const char *y="");
00240 
00241                        XrdSfsNative(XrdSysError *lp);
00242 virtual               ~XrdSfsNative() {}
00243 
00244 private:
00245 
00246 static XrdSysError *eDest;
00247 };
00248 #endif