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/XrdOucCache2.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 XrdOucCacheIO2,
00059 public XrdCl::ResponseHandler
00060 {
00061 public:
00062
00063 XrdOucCacheIO2 *XCio;
00064 XrdPosixPrepIO *PrepIO;
00065 XrdCl::File clFile;
00066
00067 long long addOffset(long long offs, int updtSz=0)
00068 {updMutex.Lock();
00069 currOffset += offs;
00070 if (updtSz && currOffset > (long long)mySize)
00071 mySize = currOffset;
00072 long long retOffset = currOffset;
00073 updMutex.UnLock();
00074 return retOffset;
00075 }
00076
00077
00078
00079 static void* DelayedDestroy(void*);
00080
00081 static void DelayedDestroy(XrdPosixFile *fp);
00082
00083 bool Close(XrdCl::XRootDStatus &Status);
00084
00085 bool Finalize(XrdCl::XRootDStatus *Status);
00086
00087 long long FSize() {AtomicBeg(updMutex);
00088 long long retSize = AtomicGet(mySize);
00089 AtomicEnd(updMutex);
00090 return retSize;
00091 }
00092
00093 int Fstat(struct stat &buf);
00094
00095 const char *Location();
00096
00097 void HandleResponse(XrdCl::XRootDStatus *status,
00098 XrdCl::AnyObject *response);
00099
00100 void isOpen();
00101
00102 void updLock() {updMutex.Lock();}
00103
00104 void updUnLock() {updMutex.UnLock();}
00105
00106 long long Offset() {AtomicRet(updMutex, currOffset);}
00107
00108 const char *Origin() {return fOpen;}
00109
00110 const char *Path() {return fPath;}
00111
00112 int Read (char *Buff, long long Offs, int Len);
00113
00114 void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs,
00115 int rlen);
00116
00117 int ReadV (const XrdOucIOVec *readV, int n);
00118
00119 void ReadV (XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV,
00120 int n);
00121
00122 long long setOffset(long long offs)
00123 {updMutex.Lock();
00124 currOffset = offs;
00125 updMutex.UnLock();
00126 return offs;
00127 }
00128
00129 bool Stat(XrdCl::XRootDStatus &Status, bool force=false);
00130
00131 int Sync();
00132
00133 void Sync(XrdOucCacheIOCB &iocb);
00134
00135 int Trunc(long long Offset);
00136
00137 void UpdtSize(size_t newsz)
00138 {updMutex.Lock();
00139 if (newsz > mySize) mySize = newsz;
00140 updMutex.UnLock();
00141 }
00142
00143 using XrdPosixObject::Who;
00144
00145 bool Who(XrdPosixFile **fileP)
00146 {*fileP = this; return true;}
00147
00148 int Write(char *Buff, long long Offs, int Len);
00149
00150 void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs,
00151 int wlen);
00152
00153 size_t mySize;
00154 time_t myMtime;
00155 dev_t myRdev;
00156 ino_t myInode;
00157 mode_t myMode;
00158
00159 static
00160 XrdSysSemaphore ddSem;
00161 static XrdSysMutex ddMutex;
00162 static XrdPosixFile *ddList;
00163 static XrdPosixFile *ddLost;
00164 static char *sfSFX;
00165 static short sfSLN;
00166 static bool ddPosted;
00167 static int ddNum;
00168
00169 static const int realFD = 1;
00170 static const int isStrm = 2;
00171 static const int isUpdt = 4;
00172
00173 XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0,
00174 int Opts=0);
00175 ~XrdPosixFile();
00176
00177 private:
00178
00179 union {long long currOffset;
00180 XrdPosixCallBack *theCB;
00181 XrdPosixFile *nextFile;
00182 };
00183
00184 char *fPath;
00185 char *fOpen;
00186 char *fLoc;
00187 union {int cOpt; int numTries;};
00188 char isStream;
00189 };
00190 #endif