35 #include <sys/types.h>
43 EPNAME(
"TagstoreFile::Open");
45 const int ret = fd_->Open(path, Oflag, 0666, Env);
54 guard_s(
XrdOssDF *fd,
bool &isopen) : fd_(fd), isopen_(isopen) { }
55 ~guard_s() {
if (fd_) { fd_->Close(); isopen_ =
false; } }
56 void disarm() { fd_ = NULL; }
60 } fdguard(fd_.get(),isOpen);
62 const static int little = 1;
63 if (*(
char const *)&little)
65 machineIsBige_ =
false;
69 machineIsBige_ =
true;
78 memcpy(&magic, header_, 4);
81 fileIsBige_ = machineIsBige_;
84 else if (magic == bswap_32(cmagic_))
86 fileIsBige_ = !machineIsBige_;
93 fileIsBige_ = machineIsBige_;
96 const int stret = MarshallAndWriteHeader();
97 if (stret<0)
return stret;
101 memcpy(&trackinglen_, &header_[4], 8);
102 if (fileIsBige_ != machineIsBige_)
104 trackinglen_ = bswap_64(trackinglen_);
106 memcpy(&hflags_,&header_[12], 4);
107 if (fileIsBige_ != machineIsBige_)
109 hflags_ = bswap_32(hflags_);
113 memcpy(&rv, &header_[16], 4);
114 if (fileIsBige_ != machineIsBige_) rv = bswap_32(rv);
121 if (trackinglen_ != dsize)
123 TRACE(Warn,
"Tagfile disagrees with actual filelength for " << fn_ <<
" expected " << trackinglen_ <<
" actual " << dsize);
127 if (rsret<0)
return rsret;
136 if (!isOpen)
return -EBADF;
139 const int ssret = fd_->Fstat(&sb);
140 if (ssret<0)
return ssret;
143 if (expected_tagfile_size < sb.st_size)
145 TRACE(Warn,
"Truncating tagfile to " << expected_tagfile_size <<
146 ", from current size " << sb.st_size <<
" for " << fn_);
147 const int tret = fd_->Ftruncate(expected_tagfile_size);
148 if (tret<0)
return tret;
150 else if (expected_tagfile_size > sb.st_size)
153 if (sb.st_size>20) nb = (sb.st_size - 20)/4;
155 " instead of " << trackinglen_ <<
", because of short tagfile for " << fn_);
157 if (stret<0)
return stret;
158 const int tret = fd_->Ftruncate(20LL + 4*nb);
159 if (tret<0)
return tret;
166 if (!isOpen)
return -EBADF;
178 if (!isOpen)
return -EBADF;
185 if (!isOpen)
return -EBADF;
186 if (machineIsBige_ != fileIsBige_)
return WriteTags_swap(buf, off, n);
189 if (nwritten<0)
return nwritten;
195 if (!isOpen)
return -EBADF;
196 if (machineIsBige_ != fileIsBige_)
return ReadTags_swap(buf, off, n);
199 if (nread<0)
return nread;
212 const int tret = fd_->Ftruncate(expected_tagfile_size);
220 int wtt = WriteTrackedTagSize(size);
221 if (wtt<0)
return wtt;
223 if (datatoo) actualsize_ = size;
227 ssize_t XrdOssCsiTagstoreFile::WriteTags_swap(
const uint32_t *
const buf,
const off_t off,
const size_t n)
230 const size_t bsz =
sizeof(b)/
sizeof(uint32_t);
235 const size_t bs = std::min(towrite, bsz);
236 for(
size_t i=0;i<bs;i++)
238 b[i] = bswap_32(buf[i+nwritten]);
241 if (wret<0)
return wret;
248 ssize_t XrdOssCsiTagstoreFile::ReadTags_swap(uint32_t *
const buf,
const off_t off,
const size_t n)
251 const size_t bsz =
sizeof(b)/
sizeof(uint32_t);
256 const size_t bs = std::min(toread, bsz);
258 if (rret<0)
return rret;
259 for(
size_t i=0;i<bs;i++)
261 buf[i+nread] = bswap_32(b[i]);
int stat(const char *path, struct stat *buf)
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
static const int PageSize