26 {
open (name, flags, perms); }
39 <<
"Destructor called on dCache file '" <<
m_name
40 <<
"' but the file is still open";
78 if ((name == 0) || (*name == 0)) {
80 ex <<
"Cannot open a file without a name";
87 ex <<
"Must open file '" << name <<
"' at least for read or write";
101 else if (flags & IOFlags::OpenRead)
102 openflags |= O_RDONLY;
103 else if (flags & IOFlags::OpenWrite)
104 openflags |= O_WRONLY;
110 openflags |= O_APPEND;
113 openflags |= O_CREAT;
119 openflags |= O_TRUNC;
123 if ((newfd = dc_open (name, openflags, perms)) == -1) {
125 ex <<
"dc_open(name='" << name
126 <<
"', flags=0x" << std::hex << openflags
127 <<
", permissions=0" << std::oct << perms << std::dec
128 <<
") => error '" << dc_strerror(dc_errno)
129 <<
"' (dc_errno=" << dc_errno <<
")";
144 dc_noBuffering(
m_fd);
146 dc_setBufferSize(
m_fd, 64000);
159 <<
"DCacheFile::close(name='" <<
m_name
160 <<
"') called but the file is not open";
166 if (dc_close (
m_fd) == -1)
168 <<
"dc_close(name='" <<
m_name
169 <<
"') failed with error '" << dc_strerror (dc_errno)
170 <<
"' (dc_errno=" << dc_errno <<
")";
212 ssize_t
s = dc_read (
m_fd, (
char *) into + done, n - done);
215 ex <<
"dc_read(name='" <<
m_name <<
"', n=" << (n-
done)
216 <<
") failed with error '" << dc_strerror(dc_errno)
217 <<
"' (dc_errno=" << dc_errno <<
")";
224 else if (s < ssize_t (n-done))
226 <<
"dc_read(name='" <<
m_name <<
"', n=" << (n-
done)
227 <<
") returned a short read of " << s <<
" bytes; "
228 <<
"please report a bug in dCache referencing the "
229 <<
"comment on line " <<
BUGLINE <<
" of " << __FILE__;
243 ssize_t
s = dc_write (
m_fd, (
const char *) from + done, n - done);
246 ex <<
"dc_write(name='" <<
m_name <<
"', n=" << (n-
done)
247 <<
") failed with error '" << dc_strerror(dc_errno)
248 <<
"' (dc_errno=" << dc_errno <<
")";
252 else if (s < ssize_t (n-done))
254 <<
"dc_write(name='" <<
m_name <<
"', n=" << (n-
done)
255 <<
") returned a short write of " << s <<
" bytes; "
256 <<
"please report a bug in dCache referencing the "
257 <<
"comment on line " <<
BUGLINE <<
" of " << __FILE__;
267 assert (! buffers || into);
274 std::vector<iovec> bufs (buffers);
277 bufs [
i].iov_len = into [
i].
size ();
278 bufs [
i].iov_base = (caddr_t) into [
i].
data ();
283 ssize_t
n = dc_readv (
m_fd, &bufs [0], buffers);
288 ex <<
"dc_readv(name='" <<
m_name <<
"', iov[" << buffers
289 <<
"]) failed with error '" << dc_strerror(dc_errno)
290 <<
"' (dc_errno=" << dc_errno <<
")";
302 assert (! buffers || into);
309 std::vector<iovec2> bufs (buffers);
313 bufs [
i].offset = into [
i].
offset ();
314 bufs [
i].len = into [
i].
size ();
315 bufs [
i].buf = (
char *) into [
i].
data ();
316 total += into [
i].
size ();
321 ssize_t
n = dc_readv2 (
m_fd, &bufs [0], buffers);
326 ex <<
"dc_readv2(name='" <<
m_name <<
"', iov2[" << buffers
327 <<
"]) failed with error '" << dc_strerror(dc_errno)
328 <<
"' (dc_errno=" << dc_errno <<
")";
333 return (n == 0) ? total : 0;
344 ex <<
"DCacheFile::position() called on a closed file";
349 ex <<
"DCacheFile::position() called with incorrect 'whence' parameter";
353 int mywhence = (whence ==
SET ? SEEK_SET
358 if ((result = dc_lseek64 (
m_fd, offset, mywhence)) == -1) {
360 ex <<
"dc_lseek64(name='" <<
m_name <<
"', offset=" << offset
361 <<
", whence=" << mywhence <<
") failed with error '"
362 << dc_strerror (dc_errno) <<
"' (dc_errno=" << dc_errno <<
")";
363 ex.
addContext(
"Calling DCacheFile::position()");
368 if (whence == SEEK_END && (result = dc_lseek64 (
m_fd, result, SEEK_SET)) == -1) {
370 ex <<
"dc_lseek64(name='" <<
m_name <<
"', offset=" << offset
371 <<
", whence=" << SEEK_SET <<
") failed with error '"
372 << dc_strerror (dc_errno) <<
"' (dc_errno=" << dc_errno <<
")";
373 ex.
addContext(
"Calling DCacheFile::position()");
383 ex <<
"DCacheFile::resize(name='" <<
m_name <<
"') not implemented";
std::vector< Variable::Flags > flags
virtual void resize(IOOffset size)
virtual IOSize write(const void *from, IOSize n)
virtual void create(const char *name, bool exclusive=false, int perms=0666)
virtual IOOffset position(void) const
virtual IOSize readv(IOBuffer *into, IOSize buffers)
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
unsigned int offset(bool)
IOOffset offset(void) const
void addContext(std::string const &context)
char data[epos_bytes_allocation]
volatile std::atomic< bool > shutdown_flag false