xrootd
XrdOss.hh
Go to the documentation of this file.
1 #ifndef _XRDOSS_H
2 #define _XRDOSS_H
3 /******************************************************************************/
4 /* */
5 /* X r d O s s & X r d O s s D F */
6 /* */
7 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <dirent.h>
14 #include <errno.h>
15 #include <strings.h>
16 #include <sys/stat.h>
17 #include <sys/types.h>
18 #include <string.h>
19 
20 class XrdOucEnv;
21 class XrdSysLogger;
22 class XrdSfsAio;
23 
24 #ifndef XrdOssOK
25 #define XrdOssOK 0
26 #endif
27 
28 /******************************************************************************/
29 /* X r d O s s D F */
30 /******************************************************************************/
31 
32 // This class defines the object that handles directory as well as file
33 // oriented requests. It is instantiated for each file/dir to be opened.
34 // The object is obtained by calling newDir() or newFile() in class XrdOss.
35 // This allows flexibility on how to structure an oss plugin.
36 
37 class XrdOssDF
38 {
39 public:
40  // Directory oriented methods
41 virtual int Opendir(const char *, XrdOucEnv &) {return -ENOTDIR;}
42 virtual int Readdir(char *buff, int blen) {return -ENOTDIR;}
43 
44  // File oriented methods
45 virtual int Fchmod(mode_t mode) {return -EISDIR;}
46 virtual int Fstat(struct stat *) {return -EISDIR;}
47 virtual int Fsync() {return -EISDIR;}
48 virtual int Fsync(XrdSfsAio *aiop) {return -EISDIR;}
49 virtual int Ftruncate(unsigned long long) {return -EISDIR;}
50 virtual int getFD() {return -1;}
51 virtual off_t getMmap(void **addr) {return 0;}
52 virtual int isCompressed(char *cxidp=0) {return -EISDIR;}
53 virtual int Open(const char *, int, mode_t, XrdOucEnv &) {return -EISDIR;}
54 virtual ssize_t Read(off_t, size_t) {return (ssize_t)-EISDIR;}
55 virtual ssize_t Read(void *, off_t, size_t) {return (ssize_t)-EISDIR;}
56 virtual int Read(XrdSfsAio *aoip) {return (ssize_t)-EISDIR;}
57 virtual ssize_t ReadRaw( void *, off_t, size_t) {return (ssize_t)-EISDIR;}
58 virtual ssize_t Write(const void *, off_t, size_t) {return (ssize_t)-EISDIR;}
59 virtual int Write(XrdSfsAio *aiop) {return (ssize_t)-EISDIR;}
60 
61  // Methods common to both
62 virtual int Close(long long *retsz=0)=0;
63 inline int Handle() {return fd;}
64 
65  XrdOssDF() {fd = -1;}
66 virtual ~XrdOssDF() {}
67 
68 protected:
69 
70 int fd; // The associated file descriptor.
71 };
72 
73 /******************************************************************************/
74 /* X r d O s s */
75 /******************************************************************************/
76 
77 // Options that can be passed to Create()
78 //
79 #define XRDOSS_mkpath 0x01
80 #define XRDOSS_new 0x02
81 #define XRDOSS_Online 0x04
82 #define XRDOSS_isPFN 0x10
83 #define XRDOSS_isMIG 0x20
84 #define XRDOSS_setnoxa 0x40
85 
86 // Options that can be passed to Stat()
87 //
88 #define XRDOSS_resonly 0x01
89 #define XRDOSS_updtatm 0x02
90 
91 // Class passed to StatVS()
92 //
94 {
95 public:
96 long long Total; // Total bytes
97 long long Free; // Total bytes free
98 long long Large; // Total bytes in largest partition
99 long long LFree; // Max bytes free in contiguous chunk
100 long long Usage; // Used bytes (if usage enabled)
101 long long Quota; // Quota bytes (if quota enabled)
102 int Extents; // Number of partitions/extents
104 
105  XrdOssVSInfo() : Total(0),Free(0),Large(0),LFree(0),Usage(-1),
106  Quota(-1),Extents(0),Reserved(0) {}
108 };
109 
110 class XrdOss
111 {
112 public:
113 virtual XrdOssDF *newDir(const char *tident)=0;
114 virtual XrdOssDF *newFile(const char *tident)=0;
115 
116 virtual int Chmod(const char *, mode_t mode, XrdOucEnv *eP=0)=0;
117 virtual int Create(const char *, const char *, mode_t, XrdOucEnv &,
118  int opts=0)=0;
119 virtual int Init(XrdSysLogger *, const char *)=0;
120 virtual int Mkdir(const char *, mode_t mode, int mkpath=0,
121  XrdOucEnv *eP=0)=0;
122 virtual int Reloc(const char *, const char *, const char *, const char *x=0)
123  {return -ENOTSUP;}
124 virtual int Remdir(const char *, int Opts=0, XrdOucEnv *eP=0)=0;
125 virtual int Rename(const char *, const char *,
126  XrdOucEnv *eP1=0, XrdOucEnv *eP2=0)=0;
127 virtual int Stat(const char *, struct stat *, int opts=0, XrdOucEnv *eP=0)=0;
128 virtual int StatFS(const char *path, char *buff, int &blen, XrdOucEnv *eP=0)
129  {return -ENOTSUP;}
130 virtual int StatLS(XrdOucEnv &env, const char *cgrp, char *buff, int &blen)
131  {return -ENOTSUP;}
132 virtual int StatXA(const char *path, char *buff, int &blen, XrdOucEnv *eP=0)
133  {return -ENOTSUP;}
134 virtual int StatXP(const char *path, unsigned long long &attr,
135  XrdOucEnv *eP=0) {return -ENOTSUP;}
136 virtual int Truncate(const char *, unsigned long long, XrdOucEnv *eP=0)=0;
137 virtual int Unlink(const char *, int Opts=0, XrdOucEnv *eP=0)=0;
138 
139 virtual int Stats(char *bp, int bl) {return 0;}
140 
141 virtual int StatVS(XrdOssVSInfo *sP, const char *sname=0, int updt=0)
142  {return -ENOTSUP;}
143 
144 virtual int Lfn2Pfn(const char *Path, char *buff, int blen)
145  {if ((int)strlen(Path) >= blen) return -ENAMETOOLONG;
146  strcpy(buff, Path); return 0;
147  }
148 virtual
149 const char *Lfn2Pfn(const char *Path, char *buff, int blen, int &rc)
150  {rc = 0; return Path;}
151 
152  XrdOss() {}
153 virtual ~XrdOss() {}
154 };
155 
156 /******************************************************************************/
157 /* S t o r a g e S y s t e m I n s t a n t i a t o r */
158 /******************************************************************************/
159 
160 // This function is called to obtain an instance of a configured XrdOss object.
161 // It is passed the object that would have been used as the storage system.
162 // The object is not initialized (i.e., Init() has not yet been called).
163 // This allows one to easily wrap the native implementation or to completely
164 // replace it, as needed. The name of the config file and any parameters
165 // specified after the path on the ofs.osslib directive are also passed (note
166 // that if no parameters exist, parms may be null).
167 
168 extern "C"
169 {
172  const char *config_fn,
173  const char *parms);
174 }
175 #endif