XRootD
XrdSutPFile.hh
Go to the documentation of this file.
1 #ifndef __SUT_PFILE_H
2 #define __SUT_PFILE_H
3 /******************************************************************************/
4 /* */
5 /* X r d S u t P F i l e . h h */
6 /* */
7 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Gerri Ganis for CERN */
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 #ifndef __XPROTOCOL_H
32 #include "XProtocol/XPtypes.hh"
33 #endif
34 #ifndef __OOUC_HASH__
35 #include "XrdOuc/XrdOucHash.hh"
36 #endif
37 #ifndef __OUC_STRING_H__
38 #include "XrdOuc/XrdOucString.hh"
39 #endif
40 
41 /******************************************************************************/
42 /* */
43 /* Interface class to file to store login-related information */
44 /* */
45 /******************************************************************************/
46 
47 #define kFileIDSize 8
48 #define kDefFileID "XrdIF"
49 #define kXrdIFVersion 1
50 
51 #define kOfsFileID 0
52 #define kOfsVersion 8 // == kFileIDSize (if this changes remember to scale
53 #define kOfsCtime 12 // accordingly the other offsets ...)
54 #define kOfsItime 16
55 #define kOfsEntries 20
56 #define kOfsIndOfs 24
57 #define kOfsJnkSiz 28
58 
59 #define kPFEcreate 0x1
60 #define kPFEopen 0x2
61 
62 #define kMaxLockTries 3
63 
80 };
81 
82 class XrdSutPFEntry;
83 
85 public:
86  char *name;
90  XrdSutPFEntInd(const char *n = 0,
91  kXR_int32 no = 0, kXR_int32 eo = 0, kXR_int32 es = 0);
92  XrdSutPFEntInd(const XrdSutPFEntInd &ei);
93  virtual ~XrdSutPFEntInd() { if (name) delete[] name; }
94 
95  kXR_int32 Length() const { return (strlen(name) + 4*sizeof(kXR_int32)); }
96  void SetName(const char *n = 0);
97 
98  // Assignement operator
100 };
101 
103 public:
106  kXR_int32 ctime; // time of file change
107  kXR_int32 itime; // time of index change
110  kXR_int32 jnksiz; // number of unreachable bytes
111  XrdSutPFHeader(const char *id = " ", kXR_int32 v = 0, kXR_int32 ct = 0,
112  kXR_int32 it = 0, kXR_int32 ent = 0, kXR_int32 ofs = 0);
113  XrdSutPFHeader(const XrdSutPFHeader &fh);
114  virtual ~XrdSutPFHeader() { }
115  void Print() const;
116 
117  static kXR_int32 Length() { return (kFileIDSize + 6*sizeof(kXR_int32)); }
118 };
119 
120 
121 class XrdSutPFile {
122 
123  friend class XrdSutPFCache; // for open/close operation;
124 
125 private:
126  char *name;
127  bool valid; // If the file is usable ...
128  kXR_int32 fFd;
129  XrdOucHash<kXR_int32> *fHashTable; // Reflects the file index structure
130  kXR_int32 fHTutime; // time at which fHashTable was updated
131  kXR_int32 fError; // last error
132  XrdOucString fErrStr; // description of last error
133 
134  // Entry low level access
135  kXR_int32 WriteHeader(XrdSutPFHeader hd);
136  kXR_int32 ReadHeader(XrdSutPFHeader &hd);
137  kXR_int32 WriteInd(kXR_int32 ofs, XrdSutPFEntInd ind);
138  kXR_int32 ReadInd(kXR_int32 ofs, XrdSutPFEntInd &ind);
139  kXR_int32 WriteEnt(kXR_int32 ofs, XrdSutPFEntry ent);
140  kXR_int32 ReadEnt(kXR_int32 ofs, XrdSutPFEntry &ent);
141 
142  // Reset (set inactive)
143  kXR_int32 Reset(kXR_int32 ofs, kXR_int32 size);
144 
145  // Hash table operations
146  kXR_int32 UpdateHashTable(bool force = 0);
147 
148  // For errors
149  kXR_int32 Err(kXR_int32 code, const char *loc,
150  const char *em1 = 0, const char *em2 = 0);
151 
152 public:
153  XrdSutPFile(const char *n, kXR_int32 openmode = kPFEcreate,
154  kXR_int32 createmode = 0600, bool hashtab = 1);
155  XrdSutPFile(const XrdSutPFile &f);
156  virtual ~XrdSutPFile();
157 
158  // Initialization method
159  bool Init(const char *n, kXR_int32 openmode = kPFEcreate,
160  kXR_int32 createmode = 0600, bool hashtab = 1);
161 
162  // Open/Close operations
163  kXR_int32 Open(kXR_int32 opt, bool *wasopen = 0,
164  const char *nam = 0, kXR_int32 createmode = 0600);
165  kXR_int32 Close(kXR_int32 d = -1);
166 
167  // File name
168  const char *Name() const { return (const char *)name; }
169  // (Un)Successful attachement
170  bool IsValid() const { return valid; }
171  // Last error
172  kXR_int32 LastError() const { return fError; }
173  const char *LastErrStr() const { return (const char *)fErrStr.c_str(); }
174 
175  // Update Methods
176  kXR_int32 RemoveEntry(const char *name);
178  kXR_int32 RemoveEntries(const char *name, char opt);
179  kXR_int32 Trim(const char *fbak = 0);
182  kXR_int32 UpdateCount(const char *nm, int *cnt = 0, int step = 1, bool reset = 0);
183  kXR_int32 ResetCount(const char *nm) { return UpdateCount(nm,0,0,1); }
184  kXR_int32 ReadCount(const char *nm, int &cnt) { return UpdateCount(nm,&cnt,0); }
185 
186  // Access methods
188  kXR_int32 ReadEntry(const char *name, XrdSutPFEntry &ent, int opt = 0);
190  kXR_int32 SearchEntries(const char *name, char opt,
191  kXR_int32 *ofs = 0, kXR_int32 nofs = 1);
193 
194  // Browser
195  kXR_int32 Browse(void *out = 0);
196 };
197 
198 #endif
int kXR_int32
Definition: XPtypes.hh:89
#define Err(p, a, b, c)
Definition: XrdNetSocket.cc:81
EPFileErrors
Definition: XrdSutPFile.hh:64
@ kPFErrUnlocking
Definition: XrdSutPFile.hh:73
@ kPFErrFileLocked
Definition: XrdSutPFile.hh:74
@ kPFErrBadInputs
Definition: XrdSutPFile.hh:65
@ kPFErrStat
Definition: XrdSutPFile.hh:69
@ kPFErrOutOfMemory
Definition: XrdSutPFile.hh:77
@ kPFErrBadOp
Definition: XrdSutPFile.hh:79
@ kPFErrFileNotOpen
Definition: XrdSutPFile.hh:71
@ kPFErrSeek
Definition: XrdSutPFile.hh:75
@ kPFErrFileOpen
Definition: XrdSutPFile.hh:70
@ kPFErrLocking
Definition: XrdSutPFile.hh:72
@ kPFErrFileRename
Definition: XrdSutPFile.hh:68
@ kPFErrFileAlreadyOpen
Definition: XrdSutPFile.hh:66
@ kPFErrRead
Definition: XrdSutPFile.hh:76
@ kPFErrNoFile
Definition: XrdSutPFile.hh:67
@ kPFErrLenMismatch
Definition: XrdSutPFile.hh:78
#define kFileIDSize
Definition: XrdSutPFile.hh:47
#define kPFEcreate
Definition: XrdSutPFile.hh:59
const char * c_str() const
int Reset(int newsz=-1, bool lock=1)
virtual ~XrdSutPFEntInd()
Definition: XrdSutPFile.hh:93
kXR_int32 entsiz
Definition: XrdSutPFile.hh:89
void SetName(const char *n=0)
Definition: XrdSutPFile.cc:78
kXR_int32 Length() const
Definition: XrdSutPFile.hh:95
kXR_int32 entofs
Definition: XrdSutPFile.hh:88
XrdSutPFEntInd & operator=(const XrdSutPFEntInd ei)
Definition: XrdSutPFile.cc:94
XrdSutPFEntInd(const char *n=0, kXR_int32 no=0, kXR_int32 eo=0, kXR_int32 es=0)
Definition: XrdSutPFile.cc:45
kXR_int32 nxtofs
Definition: XrdSutPFile.hh:87
kXR_int32 itime
Definition: XrdSutPFile.hh:107
kXR_int32 entries
Definition: XrdSutPFile.hh:108
kXR_int32 version
Definition: XrdSutPFile.hh:105
static kXR_int32 Length()
Definition: XrdSutPFile.hh:117
virtual ~XrdSutPFHeader()
Definition: XrdSutPFile.hh:114
kXR_int32 ctime
Definition: XrdSutPFile.hh:106
kXR_int32 jnksiz
Definition: XrdSutPFile.hh:110
kXR_int32 indofs
Definition: XrdSutPFile.hh:109
char fileID[kFileIDSize]
Definition: XrdSutPFile.hh:104
XrdSutPFHeader(const char *id=" ", kXR_int32 v=0, kXR_int32 ct=0, kXR_int32 it=0, kXR_int32 ent=0, kXR_int32 ofs=0)
Definition: XrdSutPFile.cc:112
void Print() const
Definition: XrdSutPFile.cc:147
kXR_int32 UpdateCount(const char *nm, int *cnt=0, int step=1, bool reset=0)
Definition: XrdSutPFile.cc:795
kXR_int32 SearchSpecialEntries(kXR_int32 *ofs=0, kXR_int32 nofs=1)
kXR_int32 Browse(void *out=0)
kXR_int32 Trim(const char *fbak=0)
kXR_int32 WriteEntry(XrdSutPFEntry ent)
Definition: XrdSutPFile.cc:585
bool IsValid() const
Definition: XrdSutPFile.hh:170
virtual ~XrdSutPFile()
Definition: XrdSutPFile.cc:221
kXR_int32 RemoveEntries(const char *name, char opt)
const char * LastErrStr() const
Definition: XrdSutPFile.hh:173
const char * Name() const
Definition: XrdSutPFile.hh:168
kXR_int32 RetrieveHeader(XrdSutPFHeader &hd)
Definition: XrdSutPFile.cc:503
kXR_int32 SearchEntries(const char *name, char opt, kXR_int32 *ofs=0, kXR_int32 nofs=1)
kXR_int32 Close(kXR_int32 d=-1)
Definition: XrdSutPFile.cc:450
kXR_int32 ReadEntry(const char *name, XrdSutPFEntry &ent, int opt=0)
Definition: XrdSutPFile.cc:909
XrdSutPFile(const char *n, kXR_int32 openmode=kPFEcreate, kXR_int32 createmode=0600, bool hashtab=1)
Definition: XrdSutPFile.cc:187
bool Init(const char *n, kXR_int32 openmode=kPFEcreate, kXR_int32 createmode=0600, bool hashtab=1)
Definition: XrdSutPFile.cc:236
kXR_int32 UpdateHeader(XrdSutPFHeader hd)
Definition: XrdSutPFile.cc:484
kXR_int32 RemoveEntry(const char *name)
kXR_int32 Open(kXR_int32 opt, bool *wasopen=0, const char *nam=0, kXR_int32 createmode=0600)
Definition: XrdSutPFile.cc:300
kXR_int32 ReadCount(const char *nm, int &cnt)
Definition: XrdSutPFile.hh:184
kXR_int32 ResetCount(const char *nm)
Definition: XrdSutPFile.hh:183
kXR_int32 LastError() const
Definition: XrdSutPFile.hh:172