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/XProtocol.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 XrdSutCache; // for open/close operation;
124 
125 private:
126  char *name;
127  bool valid; // If the file is usable ...
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
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