xrootd
XrdSutPFile.hh
Go to the documentation of this file.
1 // $Id$
2 #ifndef __SUT_PFILE_H
3 #define __SUT_PFILE_H
4 
5 /******************************************************************************/
6 /* */
7 /* X r d S u t P F i l e . h h */
8 /* */
9 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
10 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
11 /* Produced by Andrew Hanushevsky for Stanford University under contract */
12 /* DE-AC03-76-SFO0515 with the Department of Energy */
13 /******************************************************************************/
14 
15 #ifndef __XPROTOCOL_H
16 #include <XProtocol/XProtocol.hh>
17 #endif
18 #ifndef __OOUC_HASH__
19 #include <XrdOuc/XrdOucHash.hh>
20 #endif
21 #ifndef __OUC_STRING_H__
22 #include <XrdOuc/XrdOucString.hh>
23 #endif
24 /******************************************************************************/
25 /* */
26 /* Interface class to file to store login-related information */
27 /* */
28 /******************************************************************************/
29 
30 #define kFileIDSize 8
31 #define kDefFileID "XrdIF"
32 #define kXrdIFVersion 1
33 
34 #define kOfsFileID 0
35 #define kOfsVersion 8 // == kFileIDSize (if this changes remember to scale
36 #define kOfsCtime 12 // accordingly the other offsets ...)
37 #define kOfsItime 16
38 #define kOfsEntries 20
39 #define kOfsIndOfs 24
40 #define kOfsJnkSiz 28
41 
42 #define kPFEcreate 0x1
43 #define kPFEopen 0x2
44 
45 #define kMaxLockTries 3
46 
63 };
64 
65 class XrdSutPFEntry;
66 
68 public:
69  char *name;
73  XrdSutPFEntInd(const char *n = 0,
74  kXR_int32 no = 0, kXR_int32 eo = 0, kXR_int32 es = 0);
75  XrdSutPFEntInd(const XrdSutPFEntInd &ei);
76  virtual ~XrdSutPFEntInd() { if (name) delete[] name; }
77 
78  kXR_int32 Length() const { return (strlen(name) + 4*sizeof(kXR_int32)); }
79  void SetName(const char *n = 0);
80 
81  // Assignement operator
83 };
84 
86 public:
89  kXR_int32 ctime; // time of file change
90  kXR_int32 itime; // time of index change
93  kXR_int32 jnksiz; // number of unreachable bytes
94  XrdSutPFHeader(const char *id = " ", kXR_int32 v = 0, kXR_int32 ct = 0,
95  kXR_int32 it = 0, kXR_int32 ent = 0, kXR_int32 ofs = 0);
96  XrdSutPFHeader(const XrdSutPFHeader &fh);
97  virtual ~XrdSutPFHeader() { }
98  void Print() const;
99 
100  static kXR_int32 Length() { return (kFileIDSize + 6*sizeof(kXR_int32)); }
101 };
102 
103 
104 class XrdSutPFile {
105 
106  friend class XrdSutCache; // for open/close operation;
107 
108 private:
109  char *name;
110  bool valid; // If the file is usable ...
112  XrdOucHash<kXR_int32> *fHashTable; // Reflects the file index structure
113  kXR_int32 fHTutime; // time at which fHashTable was updated
114  kXR_int32 fError; // last error
115  XrdOucString fErrStr; // description of last error
116 
117  // Entry low level access
124 
125  // Reset (set inactive)
126  kXR_int32 Reset(kXR_int32 ofs, kXR_int32 size);
127 
128  // Hash table operations
129  kXR_int32 UpdateHashTable(bool force = 0);
130 
131  // For errors
132  kXR_int32 Err(kXR_int32 code, const char *loc,
133  const char *em1 = 0, const char *em2 = 0);
134 
135 public:
136  XrdSutPFile(const char *n, kXR_int32 openmode = kPFEcreate,
137  kXR_int32 createmode = 0600, bool hashtab = 1);
138  XrdSutPFile(const XrdSutPFile &f);
139  virtual ~XrdSutPFile();
140 
141  // Initialization method
142  bool Init(const char *n, kXR_int32 openmode = kPFEcreate,
143  kXR_int32 createmode = 0600, bool hashtab = 1);
144 
145  // Open/Close operations
146  kXR_int32 Open(kXR_int32 opt, bool *wasopen = 0,
147  const char *nam = 0, kXR_int32 createmode = 0600);
148  kXR_int32 Close(kXR_int32 d = -1);
149 
150  // File name
151  const char *Name() const { return (const char *)name; }
152  // (Un)Successful attachement
153  bool IsValid() const { return valid; }
154  // Last error
155  kXR_int32 LastError() const { return fError; }
156  const char *LastErrStr() const { return (const char *)fErrStr.c_str(); }
157 
158  // Update Methods
159  kXR_int32 RemoveEntry(const char *name);
161  kXR_int32 RemoveEntries(const char *name, char opt);
162  kXR_int32 Trim(const char *fbak = 0);
165  kXR_int32 UpdateCount(const char *nm, int *cnt = 0, int step = 1, bool reset = 0);
166  kXR_int32 ResetCount(const char *nm) { return UpdateCount(nm,0,0,1); }
167  kXR_int32 ReadCount(const char *nm, int &cnt) { return UpdateCount(nm,&cnt,0); }
168 
169  // Access methods
171  kXR_int32 ReadEntry(const char *name, XrdSutPFEntry &ent, int opt = 0);
173  kXR_int32 SearchEntries(const char *name, char opt,
174  kXR_int32 *ofs = 0, kXR_int32 nofs = 1);
176 
177  // Browser
178  kXR_int32 Browse(void *out = 0);
179 };
180 
181 #endif