|
xrootd
|
00001 #ifndef __SUT_PFILE_H 00002 #define __SUT_PFILE_H 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S u t P F i l e . h h */ 00006 /* */ 00007 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Gerri Ganis for CERN */ 00009 /* */ 00010 /* This file is part of the XRootD software suite. */ 00011 /* */ 00012 /* XRootD is free software: you can redistribute it and/or modify it under */ 00013 /* the terms of the GNU Lesser General Public License as published by the */ 00014 /* Free Software Foundation, either version 3 of the License, or (at your */ 00015 /* option) any later version. */ 00016 /* */ 00017 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00018 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00019 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00020 /* License for more details. */ 00021 /* */ 00022 /* You should have received a copy of the GNU Lesser General Public License */ 00023 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00024 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00025 /* */ 00026 /* The copyright holder's institutional names and contributor's names may not */ 00027 /* be used to endorse or promote products derived from this software without */ 00028 /* specific prior written permission of the institution or contributor. */ 00029 /******************************************************************************/ 00030 00031 #ifndef __XPROTOCOL_H 00032 #include "XProtocol/XProtocol.hh" 00033 #endif 00034 #ifndef __OOUC_HASH__ 00035 #include "XrdOuc/XrdOucHash.hh" 00036 #endif 00037 #ifndef __OUC_STRING_H__ 00038 #include "XrdOuc/XrdOucString.hh" 00039 #endif 00040 00041 /******************************************************************************/ 00042 /* */ 00043 /* Interface class to file to store login-related information */ 00044 /* */ 00045 /******************************************************************************/ 00046 00047 #define kFileIDSize 8 00048 #define kDefFileID "XrdIF" 00049 #define kXrdIFVersion 1 00050 00051 #define kOfsFileID 0 00052 #define kOfsVersion 8 // == kFileIDSize (if this changes remember to scale 00053 #define kOfsCtime 12 // accordingly the other offsets ...) 00054 #define kOfsItime 16 00055 #define kOfsEntries 20 00056 #define kOfsIndOfs 24 00057 #define kOfsJnkSiz 28 00058 00059 #define kPFEcreate 0x1 00060 #define kPFEopen 0x2 00061 00062 #define kMaxLockTries 3 00063 00064 enum EPFileErrors { 00065 kPFErrBadInputs, 00066 kPFErrFileAlreadyOpen, 00067 kPFErrNoFile, 00068 kPFErrFileRename, 00069 kPFErrStat, 00070 kPFErrFileOpen, 00071 kPFErrFileNotOpen, 00072 kPFErrLocking, 00073 kPFErrUnlocking, 00074 kPFErrFileLocked, 00075 kPFErrSeek, 00076 kPFErrRead, 00077 kPFErrOutOfMemory, 00078 kPFErrLenMismatch, 00079 kPFErrBadOp 00080 }; 00081 00082 class XrdSutPFEntry; 00083 00084 class XrdSutPFEntInd { 00085 public: 00086 char *name; 00087 kXR_int32 nxtofs; 00088 kXR_int32 entofs; 00089 kXR_int32 entsiz; 00090 XrdSutPFEntInd(const char *n = 0, 00091 kXR_int32 no = 0, kXR_int32 eo = 0, kXR_int32 es = 0); 00092 XrdSutPFEntInd(const XrdSutPFEntInd &ei); 00093 virtual ~XrdSutPFEntInd() { if (name) delete[] name; } 00094 00095 kXR_int32 Length() const { return (strlen(name) + 4*sizeof(kXR_int32)); } 00096 void SetName(const char *n = 0); 00097 00098 // Assignement operator 00099 XrdSutPFEntInd &operator=(const XrdSutPFEntInd ei); 00100 }; 00101 00102 class XrdSutPFHeader { 00103 public: 00104 char fileID[kFileIDSize]; 00105 kXR_int32 version; 00106 kXR_int32 ctime; // time of file change 00107 kXR_int32 itime; // time of index change 00108 kXR_int32 entries; 00109 kXR_int32 indofs; 00110 kXR_int32 jnksiz; // number of unreachable bytes 00111 XrdSutPFHeader(const char *id = " ", kXR_int32 v = 0, kXR_int32 ct = 0, 00112 kXR_int32 it = 0, kXR_int32 ent = 0, kXR_int32 ofs = 0); 00113 XrdSutPFHeader(const XrdSutPFHeader &fh); 00114 virtual ~XrdSutPFHeader() { } 00115 void Print() const; 00116 00117 static kXR_int32 Length() { return (kFileIDSize + 6*sizeof(kXR_int32)); } 00118 }; 00119 00120 00121 class XrdSutPFile { 00122 00123 friend class XrdSutCache; // for open/close operation; 00124 00125 private: 00126 char *name; 00127 bool valid; // If the file is usable ... 00128 kXR_int32 fFd; 00129 XrdOucHash<kXR_int32> *fHashTable; // Reflects the file index structure 00130 kXR_int32 fHTutime; // time at which fHashTable was updated 00131 kXR_int32 fError; // last error 00132 XrdOucString fErrStr; // description of last error 00133 00134 // Entry low level access 00135 kXR_int32 WriteHeader(XrdSutPFHeader hd); 00136 kXR_int32 ReadHeader(XrdSutPFHeader &hd); 00137 kXR_int32 WriteInd(kXR_int32 ofs, XrdSutPFEntInd ind); 00138 kXR_int32 ReadInd(kXR_int32 ofs, XrdSutPFEntInd &ind); 00139 kXR_int32 WriteEnt(kXR_int32 ofs, XrdSutPFEntry ent); 00140 kXR_int32 ReadEnt(kXR_int32 ofs, XrdSutPFEntry &ent); 00141 00142 // Reset (set inactive) 00143 kXR_int32 Reset(kXR_int32 ofs, kXR_int32 size); 00144 00145 // Hash table operations 00146 kXR_int32 UpdateHashTable(bool force = 0); 00147 00148 // For errors 00149 kXR_int32 Err(kXR_int32 code, const char *loc, 00150 const char *em1 = 0, const char *em2 = 0); 00151 00152 public: 00153 XrdSutPFile(const char *n, kXR_int32 openmode = kPFEcreate, 00154 kXR_int32 createmode = 0600, bool hashtab = 1); 00155 XrdSutPFile(const XrdSutPFile &f); 00156 virtual ~XrdSutPFile(); 00157 00158 // Initialization method 00159 bool Init(const char *n, kXR_int32 openmode = kPFEcreate, 00160 kXR_int32 createmode = 0600, bool hashtab = 1); 00161 00162 // Open/Close operations 00163 kXR_int32 Open(kXR_int32 opt, bool *wasopen = 0, 00164 const char *nam = 0, kXR_int32 createmode = 0600); 00165 kXR_int32 Close(kXR_int32 d = -1); 00166 00167 // File name 00168 const char *Name() const { return (const char *)name; } 00169 // (Un)Successful attachement 00170 bool IsValid() const { return valid; } 00171 // Last error 00172 kXR_int32 LastError() const { return fError; } 00173 const char *LastErrStr() const { return (const char *)fErrStr.c_str(); } 00174 00175 // Update Methods 00176 kXR_int32 RemoveEntry(const char *name); 00177 kXR_int32 RemoveEntry(kXR_int32 ofs); 00178 kXR_int32 RemoveEntries(const char *name, char opt); 00179 kXR_int32 Trim(const char *fbak = 0); 00180 kXR_int32 UpdateHeader(XrdSutPFHeader hd); 00181 kXR_int32 WriteEntry(XrdSutPFEntry ent); 00182 kXR_int32 UpdateCount(const char *nm, int *cnt = 0, int step = 1, bool reset = 0); 00183 kXR_int32 ResetCount(const char *nm) { return UpdateCount(nm,0,0,1); } 00184 kXR_int32 ReadCount(const char *nm, int &cnt) { return UpdateCount(nm,&cnt,0); } 00185 00186 // Access methods 00187 kXR_int32 RetrieveHeader(XrdSutPFHeader &hd); 00188 kXR_int32 ReadEntry(const char *name, XrdSutPFEntry &ent, int opt = 0); 00189 kXR_int32 ReadEntry(kXR_int32 ofs, XrdSutPFEntry &ent); 00190 kXR_int32 SearchEntries(const char *name, char opt, 00191 kXR_int32 *ofs = 0, kXR_int32 nofs = 1); 00192 kXR_int32 SearchSpecialEntries(kXR_int32 *ofs = 0, kXR_int32 nofs = 1); 00193 00194 // Browser 00195 kXR_int32 Browse(void *out = 0); 00196 }; 00197 00198 #endif
1.7.6.1