xrootd
XrdSfsInterface.hh
Go to the documentation of this file.
1 #ifndef __SFS_INTERFACE_H__
2 #define __SFS_INTERFACE_H__
3 /******************************************************************************/
4 /* */
5 /* X r d S f s I n t e r f a c e . h h */
6 /* */
7 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <string.h> // For strlcpy()
14 #include <sys/errno.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <sys/socket.h> // for sockaddr
18 
19 #include "XrdOuc/XrdOucErrInfo.hh"
20 
21 /******************************************************************************/
22 /* O p e n M o d e s */
23 /******************************************************************************/
24 
25 #define SFS_O_RDONLY 0 // open read/only
26 #define SFS_O_WRONLY 1 // open write/only
27 #define SFS_O_RDWR 2 // open read/write
28 #define SFS_O_CREAT 0x100 // used for file creation
29 #define SFS_O_TRUNC 0x200 // used for file truncation
30 #define SFS_O_POSC 0x0100000 // persist on successful close
31 #define SFS_O_NOWAIT 0x01000000 // do not impose operational delays
32 #define SFS_O_RAWIO 0x02000000 // allow client-side decompression
33 #define SFS_O_RESET 0x04000000 // Reset any cached information
34 #define SFS_O_REPLICA 0x08000000 // Open for replication
35 
36 // The following flag may be set in the access mode arg for open() & mkdir()
37 // Note that on some systems mode_t is 16-bits so we use a careful value!
38 //
39 #define SFS_O_MKPTH 0x00004000 // Make directory path if missing
40 
41 // The following options are here to provide a uniform clustering interface.
42 // They may be passed through open/locate/stat, as applicable.
43 //
44 #define SFS_O_LOCATE 0x10000000 // This request generated by locate()
45 #define SFS_O_STAT 0x20000000 // This request generated by stat()
46 #define SFS_O_META 0x40000000 // This request generated by metaop
47 
48 /******************************************************************************/
49 /* D e f i n e s */
50 /******************************************************************************/
51 
52 // Common fctl command values (0 to 255)
53 //
54 #define SFS_FCTL_GETFD 1 // Return file descriptor if possible
55 #define SFS_FCTL_STATV 2 // Return visa information
56 
57 // Common fsctl command values (0 to 255)
58 //
59 #define SFS_FSCTL_CMD 255
60 
61 #define SFS_FSCTL_LOCATE 1 // Locate a file
62 #define SFS_FSCTL_STATFS 2 // Return FS data
63 #define SFS_FSCTL_STATLS 3 // Return LS data
64 #define SFS_FSCTL_STATXA 4 // Return XA data
65 #define SFS_FSCTL_PLUGIN 8 // Return Implementation Dependent Data
66 #define SFS_FSCTL_PLUGIO 16 // Return Implementation Dependent Data
67 
68 // Return Values for Integer Returning XrdSfs Interface
69 //
70 #define SFS_STALL 1 // ErrInfo code -> Seconds to stall client
71 #define SFS_OK 0 // ErrInfo code -> All is well
72 #define SFS_ERROR -1 // ErrInfo code -> Error occurred
73 #define SFS_REDIRECT -256 // ErrInfo code -> Port number to redirect to
74 #define SFS_STARTED -512 // ErrInfo code -> Estimated seconds to completion
75 #define SFS_DATA -1024 // ErrInfo code -> Length of data
76 
77 /******************************************************************************/
78 /* S t r u c t u r e s & T y p e d e f s */
79 /******************************************************************************/
80 
81 typedef long long XrdSfsFileOffset;
82 typedef int XrdSfsFileOpenMode;
83 typedef int XrdSfsMode;
84 typedef int XrdSfsXferSize;
85 
87 {
91 };
92 //------------------------------------------------
93 
94 #define Prep_PRTY0 0
95 #define Prep_PRTY1 1
96 #define Prep_PRTY2 2
97 #define Prep_PRTY3 3
98 #define Prep_PMASK 3
99 #define Prep_SENDAOK 4
100 #define Prep_SENDERR 8
101 #define Prep_SENDACK 12
102 #define Prep_WMODE 16
103 #define Prep_STAGE 32
104 #define Prep_COLOC 64
105 #define Prep_FRESH 128
106 
107 class XrdOucTList;
108 
109 struct XrdSfsFSctl // SFS_FSCTL_PLUGIN/PLUGIO parameters
110 {
111  const char *Arg1; // PLUGIO & PLUGIN
112  int Arg1Len;
113  int Arg2Len;
114  const char *Arg2; // PLUGIN opaque string
115 };
116 
117 struct XrdSfsPrep // Prepare parameters
118 {
119  char *reqid; // Request ID
120  char *notify; // Notification path or 0
121  int opts; // Prep_xxx
122  XrdOucTList *paths; // List of paths
123  XrdOucTList *oinfo; // 1-to-1 correspondence of opaque info
124 };
125 
126 /******************************************************************************/
127 /* A b s t r a c t C l a s s e s */
128 /******************************************************************************/
129 
130 class XrdSfsFile;
131 class XrdSfsDirectory;
132 class XrdOucTList;
133 class XrdSecEntity;
134 
135 /******************************************************************************/
136 /* X r d S f s F i l e S y s t e m */
137 /******************************************************************************/
138 
140 {
141 public:
142 
143 // The following two methods allocate a directory or file object
144 //
145 virtual XrdSfsDirectory *newDir(char *user=0, int MonID=0) = 0;
146 
147 virtual XrdSfsFile *newFile(char *user=0, int MonID=0) = 0;
148 
149 // The following are filesystem related methods
150 //
151 
152 enum csFunc {csCalc = 0, csGet, csSize};
153 
154 virtual int chksum( csFunc Func,
155  const char *csName,
156  const char *Path,
157  XrdOucErrInfo &out_error,
158  const XrdSecEntity *client = 0,
159  const char *opaque = 0)
160  {out_error.setErrInfo(ENOTSUP, "Not supported.");
161  return SFS_ERROR;
162  }
163 
164 virtual int chmod(const char *Name,
166  XrdOucErrInfo &out_error,
167  const XrdSecEntity *client = 0,
168  const char *opaque = 0) = 0;
169 
170 virtual int FSctl(const int cmd,
171  XrdSfsFSctl &args,
172  XrdOucErrInfo &out_error,
173  const XrdSecEntity *client = 0) {return SFS_OK;}
174 
175 virtual int fsctl(const int cmd,
176  const char *args,
177  XrdOucErrInfo &out_error,
178  const XrdSecEntity *client = 0) = 0;
179 
180 virtual int getStats(char *buff, int blen) = 0;
181 
182 virtual const char *getVersion() = 0;
183 
184 virtual int exists(const char *fileName,
185  XrdSfsFileExistence &exists_flag,
186  XrdOucErrInfo &out_error,
187  const XrdSecEntity *client = 0,
188  const char *opaque = 0) = 0;
189 
190 virtual int mkdir(const char *dirName,
192  XrdOucErrInfo &out_error,
193  const XrdSecEntity *client = 0,
194  const char *opaque = 0) = 0;
195 
196 virtual int prepare( XrdSfsPrep &pargs,
197  XrdOucErrInfo &out_error,
198  const XrdSecEntity *client = 0) = 0;
199 
200 virtual int rem(const char *path,
201  XrdOucErrInfo &out_error,
202  const XrdSecEntity *client = 0,
203  const char *opaque = 0) = 0;
204 
205 virtual int remdir(const char *dirName,
206  XrdOucErrInfo &out_error,
207  const XrdSecEntity *client = 0,
208  const char *opaque = 0) = 0;
209 
210 virtual int rename(const char *oldFileName,
211  const char *newFileName,
212  XrdOucErrInfo &out_error,
213  const XrdSecEntity *client = 0,
214  const char *opaqueO = 0,
215  const char *opaqueN = 0) = 0;
216 
217 virtual int stat(const char *Name,
218  struct stat *buf,
219  XrdOucErrInfo &out_error,
220  const XrdSecEntity *client = 0,
221  const char *opaque = 0) = 0;
222 
223 virtual int stat(const char *Name,
224  mode_t &mode,
225  XrdOucErrInfo &out_error,
226  const XrdSecEntity *client = 0,
227  const char *opaque = 0) = 0;
228 
229 virtual int truncate(const char *Name,
230  XrdSfsFileOffset fileOffset,
231  XrdOucErrInfo &out_error,
232  const XrdSecEntity *client = 0,
233  const char *opaque = 0) = 0;
234 
236 virtual ~XrdSfsFileSystem() {}
237 
238 protected:
239 };
240 
241 /******************************************************************************/
242 /* F i l e S y s t e m I n s t a n t i a t o r */
243 /******************************************************************************/
244 
245 /* When building a shared library plugin, the following "C" entry point must
246  exist in the library:
247 
248  extern "C"
249  {XrdSfsFileSystem *XrdSfsGetFileSystem(XrdSfsFileSystem *nativeFS,
250  XrdSysLogger *Logger,
251  const char *configFn);
252  }
253 
254  This entry is called to get an instance of the file system. Return 0 if upon
255  failure to properly create such an object. For statically linked file systems
256  the non-extern C XrdSfsGetDefaultFileSystem() is used instead. It has a
257  slightly different calling convention which adds an environment parameter
258  as follows:
259 
260  XrdSfsFileSystem *XrdSfsGetDefaultFileSystem(XrdSfsFileSystem *nativeFS,
261  XrdSysLogger *Logger,
262  const char *configFn,
263  XrdOucEnv *EnvInfo);
264 */
265 
266 /******************************************************************************/
267 /* X r d S f s F i l e */
268 /******************************************************************************/
269 
270 class XrdSfsAio;
271 
273 {
274 public:
276 
277 virtual int open(const char *fileName,
278  XrdSfsFileOpenMode openMode,
279  mode_t createMode,
280  const XrdSecEntity *client = 0,
281  const char *opaque = 0) = 0;
282 
283 virtual int close() = 0;
284 
285 virtual int fctl(const int cmd,
286  const char *args,
287  XrdOucErrInfo &out_error) = 0;
288 
289 virtual const char *FName() = 0;
290 
291 virtual int getMmap(void **Addr, off_t &Size) = 0;
292 
293 virtual int read(XrdSfsFileOffset fileOffset,
294  XrdSfsXferSize preread_sz) = 0;
295 
296 virtual XrdSfsXferSize read(XrdSfsFileOffset fileOffset,
297  char *buffer,
298  XrdSfsXferSize buffer_size) = 0;
299 
300 virtual int read(XrdSfsAio *aioparm) = 0;
301 
302 virtual XrdSfsXferSize write(XrdSfsFileOffset fileOffset,
303  const char *buffer,
304  XrdSfsXferSize buffer_size) = 0;
305 
306 virtual int write(XrdSfsAio *aioparm) = 0;
307 
308 virtual int stat(struct stat *buf) = 0;
309 
310 virtual int sync() = 0;
311 
312 virtual int sync(XrdSfsAio *aiop) = 0;
313 
314 virtual int truncate(XrdSfsFileOffset fileOffset) = 0;
315 
316 virtual int getCXinfo(char cxtype[4], int &cxrsz) = 0;
317 
318  XrdSfsFile(const char *user=0, int MonID=0)
319  : error(user, MonID) {}
320 virtual ~XrdSfsFile() {}
321 
322 }; // class XrdSfsFile
323 
324 /******************************************************************************/
325 /* X r d S f s D i r e c t o r y */
326 /******************************************************************************/
327 
329 {
330 public:
332 
333 virtual int open(const char *dirName,
334  const XrdSecEntity *client = 0,
335  const char *opaque = 0) = 0;
336 
337 virtual const char *nextEntry() = 0;
338 
339 virtual int close() = 0;
340 
341 virtual const char *FName() = 0;
342 
343  XrdSfsDirectory(const char *user=0, int MonID=0)
344  : error(user, MonID) {}
345 virtual ~XrdSfsDirectory() {}
346 
347 }; // class XrdSfsDirectory
348 #endif