35 #include <sys/types.h>
48 #define ENODATA ENOATTR
62 cUp() :
ossP(0), buff(0), fd(-1) {}
65 if (fd >= 0)
close(fd);
88 if (cpFile.
isActive())
return -EEXIST;
92 if ((rc = ossFile.
Fstat(&
Stat)))
return rc;
128 int XrdOfsChkPnt::Failed(
const char *opn,
int eRC,
bool *readok)
130 static const mode_t mRO = S_IRUSR | S_IRGRP;
131 const char *eWhat =
"still accessible!";
140 else eWhat =
"made inaccessible";
141 if (readok) *readok =
false;
145 else eWhat =
"made read/only";
146 if (readok) *readok =
true;
157 if (opn)
OfsEroute.
Emsg(
"ChkPnt", eRC, opn, (lFN ? lFN :
"\'???\'"));
158 if (lFN)
OfsEroute.
Emsg(
"ChkPnt", lFN,
"restore failed;", eWhat);
184 const char *eWhy = 0;
189 if (!cpFile.
isActive())
return -ENOENT;
196 eMsg =
"process chkpnt (";
197 if (eWhy)
eMsg.append(eWhy);
201 return Failed(0, rc, readok);
210 rc = ossFile.
Open(lFN, O_RDWR, 0, ckpEnv);
211 if (rc)
return Failed(
"open", rc, readok);
218 if (rc)
return Failed(
"truncate", rc, readok);
225 return Failed(
"write", (rc < 0 ? rc : -EIO), readok);
234 struct timeval utArg[2];
235 utArg[0].tv_sec = utArg[1].tv_sec = rinfo.
mTime;
236 utArg[0].tv_usec = utArg[1].tv_usec = 0;
238 if (rc && rc != -ENOTSUP)
OfsEroute.
Emsg(
"ChkPnt", rc,
"set mtime for", lFN);
244 return Failed(0, rc, readok);
264 if (!cpFile.
isActive())
return -ENOENT;
268 if (range[0].offset < 0)
return -EINVAL;
272 if (range[0].offset >= fSize)
return 0;
276 dlen = fSize - range[0].
offset;
281 if (!cpFile.
Reserve(dlen, 1))
return -ENOSPC;
286 if (!(cup.buff = (
char *)malloc(dlen)))
return -ENOMEM;
290 rc = ossFile.
Read(cup.buff, range[0].
offset, dlen);
291 if (rc < 0 || (rc && (rc = cpFile.
Append(cup.buff, range[0].
offset, rc))))
299 if (!(rc = cpFile.
Sync())) fSize = range[0].
offset;
310 int rc, dlen = 0, buffSZ = 0, numVS = 0, totSZ = 0;
314 if (!cpFile.
isActive())
return -ENOENT;
318 for (
int i = 0; i < rnum; i++)
319 {
if (range[i].offset < 0)
return -EINVAL;
320 if (range[i].offset < fSize && range[i].size)
321 {
if (range[i].size + range[i].offset < fSize) dlen = range[i].
size;
322 else dlen = fSize - range[i].
offset;
324 if (dlen > buffSZ) buffSZ = dlen;
325 range[i].
info = dlen; totSZ += dlen; numVS++;
326 }
else range[i].
info = 0;
331 if (!buffSZ)
return 0;
339 if (!(cup.buff = (
char *)malloc(buffSZ)))
return -ENOMEM;
343 if (!cpFile.
Reserve(dlen, numVS))
return -ENOSPC;
348 for (
int i = 0; i < rnum; i++)
352 || (rc && (rc = cpFile.
Append(cup.buff, range[i].
offset, rc))))
359 return cpFile.
Sync();
int stat(const char *path, struct stat *buf)
int64_t fSize
Original size of the source file.
const char * srcLFN
Pointer to the source filename.
XrdOucIOVec * DataVec
A vector of data that must be written back.
int DataLen
Number of bytes to write back (may be 0)
int DataNum
Number of elements in DataVec (may be 0)
time_t mTime
Original modification time of the source.
bool Reserve(int dlen, int nseg)
int Append(const char *data, off_t offset, int dlen)
int RestoreInfo(rInfo &rinfo, const char *&ewhy)
int Create(const char *lfn, struct stat &Stat)
const char * FName(bool trim=false)
int Truncate(struct iov *&range)
int Query(struct iov &range)
int Write(struct iov *&range, int rnum)
int Restore(bool *readok=0)
virtual ssize_t WriteV(XrdOucIOVec *writeV, int wrvcnt)
virtual int Ftruncate(unsigned long long flen)
static const int Fctl_utimes
virtual int Fstat(struct stat *buf)
virtual int Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env)
virtual ssize_t Read(off_t offset, size_t size)
virtual int Fctl(int cmd, int alen, const char *args, char **resp=0)
virtual int Chmod(const char *path, mode_t mode, XrdOucEnv *envP=0)=0
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)