CMS 3D CMS Logo

UnixFile.cc
Go to the documentation of this file.
5 #include <cassert>
6 
7 using namespace IOFlags;
8 
10  IOFD copyfd;
11  if ((copyfd = ::dup(fd)) == EDM_IOFD_INVALID)
12  throwStorageError("FileDuplicateError", "Calling File::sysduplicate()", "dup()", errno);
13 
14  return copyfd;
15 }
16 
17 void File::sysopen(const char *name, int flags, int perms, IOFD &newfd, unsigned int & /*newflags*/) {
18  // Translate our flags to system flags.
19  int openflags = 0;
20 
21  if ((flags & OpenRead) && (flags & OpenWrite))
22  openflags |= O_RDWR;
23  else if (flags & OpenRead)
24  openflags |= O_RDONLY;
25  else if (flags & OpenWrite)
26  openflags |= O_WRONLY;
27 
28  if (flags & OpenNonBlock)
29  openflags |= O_NONBLOCK;
30 
31  if (flags & OpenAppend)
32  openflags |= O_APPEND;
33 
34 #ifdef O_SYNC
35  if (flags & OpenUnbuffered)
36  openflags |= O_SYNC;
37 #else
38  if (flags & OpenUnbuffered)
39  newflags |= OpenUnbuffered;
40 #endif
41 
42  if (flags & OpenCreate)
43  openflags |= O_CREAT;
44 
45  if (flags & OpenExclusive)
46  openflags |= O_EXCL;
47 
48  if (flags & OpenTruncate)
49  openflags |= O_TRUNC;
50 
51  if (flags & OpenNotCTTY)
52  openflags |= O_NOCTTY;
53 
54  if ((newfd = ::open(name, openflags, perms)) == -1)
55  throwStorageError(edm::errors::FileOpenError, "Calling File::sysopen()", "open()", errno);
56 }
57 
59  assert(pos >= 0);
60 
61  ssize_t s;
62  do
63  s = ::pread(fd(), into, n, pos);
64  while (s == -1 && errno == EINTR);
65 
66  if (s == -1)
67  throwStorageError(edm::errors::FileReadError, "Calling File::read()", "pread()", errno);
68 
69  return s;
70 }
71 
72 IOSize File::write(const void *from, IOSize n, IOOffset pos) {
73  assert(pos >= 0);
74 
75  ssize_t s;
76  do
77  s = ::pwrite(fd(), from, n, pos);
78  while (s == -1 && errno == EINTR);
79 
80  if (s == -1)
81  throwStorageError(edm::errors::FileWriteError, "Calling File::write()", "pwrite()", errno);
82 
83  if (m_flags & OpenUnbuffered)
84  // FIXME: Exception handling?
85  flush();
86 
87  return s;
88 }
89 
90 IOOffset File::size(void) const {
91  IOFD fd = this->fd();
92  assert(fd != EDM_IOFD_INVALID);
93 
94  struct stat info;
95  if (fstat(fd, &info) == -1)
96  throwStorageError("FileSizeError", "Calling File::size()", "fstat()", errno);
97 
98  return info.st_size;
99 }
100 
102  IOFD fd = this->fd();
103  assert(fd != EDM_IOFD_INVALID);
104  assert(whence == CURRENT || whence == SET || whence == END);
105 
107  int mywhence = (whence == SET ? SEEK_SET : whence == CURRENT ? SEEK_CUR : SEEK_END);
108  if ((result = ::lseek(fd, offset, mywhence)) == -1)
109  throwStorageError("FilePositionError", "Calling File::position()", "lseek()", errno);
110 
111  return result;
112 }
113 
115  IOFD fd = this->fd();
116  assert(fd != EDM_IOFD_INVALID);
117 
118  if (ftruncate(fd, size) == -1)
119  throwStorageError("FileResizeError", "Calling File::resize()", "ftruncate()", errno);
120 }
121 
122 void File::flush(void) {
123  IOFD fd = this->fd();
124  assert(fd != EDM_IOFD_INVALID);
125 
126 #if _POSIX_SYNCHRONIZED_IO > 0
127  if (fdatasync(fd) == -1)
128  throwStorageError("FileFlushError", "Calling File::flush()", "fdatasync()", errno);
129 #elif _POSIX_FSYNC > 0
130  if (fsync(fd) == -1)
131  throwStorageError("FileFlushError", "Calling File::flush()", "fsync()", errno);
132 #endif
133 }
134 
135 bool File::sysclose(IOFD fd, int *error /* = 0 */) {
136  int ret = ::close(fd);
137  if (error)
138  *error = errno;
139  return ret != -1;
140 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
L1DTConfigBti_cff.SET
SET
Definition: L1DTConfigBti_cff.py:21
IOFlags::OpenNonBlock
Definition: IOFlags.h:9
File::flush
void flush(void) override
Definition: UnixFile.cc:122
pos
Definition: PixelAliasList.h:18
edm::errors::FileWriteError
Definition: EDMException.h:66
Storage::Relative
Relative
Definition: Storage.h:22
cms::cuda::assert
assert(be >=bs)
File::resize
void resize(IOOffset size) override
Definition: UnixFile.cc:114
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
IOFlags::OpenTruncate
Definition: IOFlags.h:28
IOFlags::OpenWrite
Definition: IOFlags.h:8
relativeConstraints.error
error
Definition: relativeConstraints.py:53
edm::errors::FileOpenError
Definition: EDMException.h:49
EDMException.h
ztee.fd
fd
Definition: ztee.py:136
alignCSCRings.s
s
Definition: alignCSCRings.py:92
hgcalPlots.stat
stat
Definition: hgcalPlots.py:1111
IOFlags::OpenRead
Definition: IOFlags.h:7
SysFile.h
trackingPlots.dup
dup
Definition: trackingPlots.py:183
IOFlags
Definition: IOFlags.h:4
IOOffset
int64_t IOOffset
Definition: IOTypes.h:19
IOFlags::OpenNotCTTY
Definition: IOFlags.h:30
throwStorageError
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
IOFlags::OpenExclusive
Definition: IOFlags.h:25
IOFlags::OpenCreate
Definition: IOFlags.h:24
File::sysopen
static void sysopen(const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags)
Definition: UnixFile.cc:17
File::write
IOSize write(const void *from, IOSize n) override
Definition: File.cc:209
IOFD
int IOFD
Definition: IOTypes.h:22
IOFlags::OpenAppend
Definition: IOFlags.h:18
EDM_IOFD_INVALID
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
File::size
IOOffset size(void) const override
Definition: UnixFile.cc:90
Storage::position
virtual IOOffset position(void) const
Definition: Storage.cc:72
IOInput::read
int read(void)
Definition: IOInput.cc:52
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
O_NONBLOCK
#define O_NONBLOCK
Definition: SysFile.h:21
IOFlags::OpenUnbuffered
Definition: IOFlags.h:20
mps_fire.result
result
Definition: mps_fire.py:303
Throw.h
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:78
IOSize
size_t IOSize
Definition: IOTypes.h:14
File::sysduplicate
static IOFD sysduplicate(IOFD fd)
Definition: UnixFile.cc:9
edm::errors::FileReadError
Definition: EDMException.h:50
File.h
HLT_2018_cff.flags
flags
Definition: HLT_2018_cff.py:11758
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
File::sysclose
static bool sysclose(IOFD fd, int *error=nullptr)
Definition: UnixFile.cc:135