00001 #ifndef __XRDPOSIXFILE_HH__
00002 #define __XRDPOSIXFILE_HH__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <errno.h>
00034 #include <fcntl.h>
00035 #include <sys/time.h>
00036 #include <sys/param.h>
00037 #include <sys/resource.h>
00038 #include <sys/uio.h>
00039
00040 #include "XrdCl/XrdClFileSystem.hh"
00041 #include "XrdCl/XrdClFile.hh"
00042 #include "XrdCl/XrdClURL.hh"
00043 #include "XrdCl/XrdClXRootDResponses.hh"
00044
00045 #include "XrdOuc/XrdOucCache.hh"
00046
00047 #include "XrdPosix/XrdPosixMap.hh"
00048 #include "XrdPosix/XrdPosixObject.hh"
00049
00050
00051
00052
00053
00054 class XrdPosixCallBack;
00055 class XrdPosixPrepIO;
00056
00057 class XrdPosixFile : public XrdPosixObject,
00058 public XrdOucCacheIO,
00059 public XrdOucCacheIOCD,
00060 public XrdCl::ResponseHandler
00061 {
00062 public:
00063
00064 XrdOucCacheIO *XCio;
00065 XrdPosixPrepIO *PrepIO;
00066 XrdCl::File clFile;
00067
00068 long long addOffset(long long offs, int updtSz=0)
00069 {updMutex.Lock();
00070 currOffset += offs;
00071 if (updtSz && currOffset > (long long)mySize)
00072 mySize = currOffset;
00073 long long retOffset = currOffset;
00074 updMutex.UnLock();
00075 return retOffset;
00076 }
00077
00078
00079
00080 static void* DelayedDestroy(void*);
00081
00082 static void DelayedDestroy(XrdPosixFile *fp);
00083
00084 bool Close(XrdCl::XRootDStatus &Status);
00085
00086 bool Detach(XrdOucCacheIOCD &cdP) {(void)cdP; return true;}
00087
00088 void DetachDone() {unRef();}
00089
00090 bool Finalize(XrdCl::XRootDStatus *Status);
00091
00092 long long FSize() {AtomicBeg(updMutex);
00093 long long retSize = AtomicGet(mySize);
00094 AtomicEnd(updMutex);
00095 return retSize;
00096 }
00097
00098 int Fstat(struct stat &buf);
00099
00100 const char *Location();
00101
00102 void HandleResponse(XrdCl::XRootDStatus *status,
00103 XrdCl::AnyObject *response);
00104
00105 void updLock() {updMutex.Lock();}
00106
00107 void updUnLock() {updMutex.UnLock();}
00108
00109 long long Offset() {AtomicRet(updMutex, currOffset);}
00110
00111 const char *Origin() {return fOpen;}
00112
00113 const char *Path() {return fPath;}
00114
00115 int Read (char *Buff, long long Offs, int Len);
00116
00117 void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs,
00118 int rlen);
00119
00120 int ReadV (const XrdOucIOVec *readV, int n);
00121
00122 void ReadV (XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV,
00123 int n);
00124
00125 long long setOffset(long long offs)
00126 {updMutex.Lock();
00127 currOffset = offs;
00128 updMutex.UnLock();
00129 return offs;
00130 }
00131
00132 bool Stat(XrdCl::XRootDStatus &Status, bool force=false);
00133
00134 int Sync();
00135
00136 void Sync(XrdOucCacheIOCB &iocb);
00137
00138 int Trunc(long long Offset);
00139
00140 void UpdtSize(size_t newsz)
00141 {updMutex.Lock();
00142 if (newsz > mySize) mySize = newsz;
00143 updMutex.UnLock();
00144 }
00145
00146 using XrdPosixObject::Who;
00147
00148 bool Who(XrdPosixFile **fileP)
00149 {*fileP = this; return true;}
00150
00151 int Write(char *Buff, long long Offs, int Len);
00152
00153 void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs,
00154 int wlen);
00155
00156 size_t mySize;
00157 time_t myMtime;
00158 dev_t myRdev;
00159 ino_t myInode;
00160 mode_t myMode;
00161
00162 static
00163 XrdSysSemaphore ddSem;
00164 static XrdSysMutex ddMutex;
00165 static XrdPosixFile *ddList;
00166 static XrdPosixFile *ddLost;
00167 static char *sfSFX;
00168 static short sfSLN;
00169 static bool ddPosted;
00170 static int ddNum;
00171
00172 static const int realFD = 1;
00173 static const int isStrm = 2;
00174 static const int isUpdt = 4;
00175
00176 XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0,
00177 int Opts=0);
00178 ~XrdPosixFile();
00179
00180 private:
00181
00182 union {long long currOffset;
00183 XrdPosixCallBack *theCB;
00184 XrdPosixFile *nextFile;
00185 };
00186
00187 char *fPath;
00188 char *fOpen;
00189 char *fLoc;
00190 union {int cOpt; int numTries;};
00191 char isStream;
00192 };
00193 #endif