ssize_t buffer::list::pread_file(const char *fn, uint64_t off, uint64_t len, std::string *error)
{
- int fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC));
+ int fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC|O_BINARY));
if (fd < 0) {
int err = errno;
std::ostringstream oss;
int buffer::list::read_file(const char *fn, std::string *error)
{
- int fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC));
+ int fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC|O_BINARY));
if (fd < 0) {
int err = errno;
std::ostringstream oss;
int buffer::list::write_file(const char *fn, int mode)
{
- int fd = TEMP_FAILURE_RETRY(::open(fn, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, mode));
+ int fd = TEMP_FAILURE_RETRY(::open(fn, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC|O_BINARY, mode));
if (fd < 0) {
int err = errno;
cerr << "bufferlist::write_file(" << fn << "): failed to open file: "
snprintf(fn, sizeof(fn), "%s/%s", base, file);
snprintf(tmp, sizeof(tmp), "%s/%s.tmp", base, file);
- fd = open(tmp, O_WRONLY|O_CREAT|O_TRUNC, mode);
+ fd = open(tmp, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, mode);
if (fd < 0) {
ret = errno;
return -ret;
return ret;
}
- fd = open(base, O_RDONLY);
+ fd = open(base, O_RDONLY|O_BINARY);
if (fd < 0) {
ret = -errno;
return ret;
int fd, len;
snprintf(fn, sizeof(fn), "%s/%s", base, file);
- fd = open(fn, O_RDONLY);
+ fd = open(fn, O_RDONLY|O_BINARY);
if (fd < 0) {
return -errno;
}
#endif
}
+// Needed on Windows when handling binary files. Without it, line
+// endings will be replaced and certain characters can be treated as
+// EOF.
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
#endif /* !CEPH_COMPAT_H */
::snprintf(fn, sizeof(fn),
ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", name,
getpid(), i++);
- int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT|O_CLOEXEC, 0644);
+ int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT|O_CLOEXEC|O_BINARY, 0644);
if (fd < 0) {
return;
}
break; \
char fn[PATH_MAX]; \
snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", #cl, getpid(), i++); \
- int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT|O_CLOEXEC, 0644); \
+ int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT|O_CLOEXEC|O_BINARY, 0644); \
if (fd >= 0) { \
::ceph::bufferlist sub; \
sub.substr_of(bl, pre_off, bl.length() - pre_off); \
snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP) "/%s__%d.%x",
abi::__cxa_demangle(typeid(*this).name(), 0, 0, &status),
getpid(), i++);
- int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT|O_CLOEXEC, 0644);
+ int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT|O_CLOEXEC|O_BINARY, 0644);
if (fd >= 0) {
bl.write_fd(fd);
::close(fd);
m_rbd = new librbd::RBD();
map<thread_id_t, Worker*> workers;
- int fd = open(replay_file.c_str(), O_RDONLY);
+ int fd = open(replay_file.c_str(), O_RDONLY|O_BINARY);
if (fd < 0) {
std::cerr << "Failed to open " << replay_file << ": "
<< cpp_strerror(errno) << std::endl;
// This code assumes that IO IDs and timestamps are related monotonically.
// In other words, (a.id < b.id) == (a.timestamp < b.timestamp) for all IOs a and b.
+#include "include/compat.h"
#include "common/errno.h"
#include "rbd_replay/ActionTypes.h"
#include <babeltrace/babeltrace.h>
struct bt_iter *bt_itr = bt_ctf_get_iter(itr);
- int fd = open(output_file_name.c_str(), O_WRONLY | O_CREAT | O_EXCL, 0644);
+ int fd = open(output_file_name.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0644);
ASSERT_EXIT(fd >= 0, "Error opening output file " << output_file_name <<
": " << cpp_strerror(errno));
BOOST_SCOPE_EXIT( (fd) ) {
cerr << "expecting filename" << std::endl;
exit(1);
}
- int fd = ::open(*i, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ int fd = ::open(*i, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
if (fd < 0) {
cerr << "error opening " << *i << " for write: " << cpp_strerror(errno) << std::endl;
exit(1);
MonitorDBStore::TransactionRef t;
public:
explicit TraceIter(string fname) : fd(-1), idx(-1) {
- fd = ::open(fname.c_str(), O_RDONLY);
+ fd = ::open(fname.c_str(), O_RDONLY|O_BINARY);
t.reset(new MonitorDBStore::Transaction);
}
bool valid() {
int fd = STDOUT_FILENO;
if (!outpath.empty()){
- fd = ::open(outpath.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ fd = ::open(outpath.c_str(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
if (fd < 0) {
std::cerr << "error opening output file: "
<< cpp_strerror(errno) << std::endl;
cout << "journal is " << start << "~" << len << std::endl;
- int fd = ::open(dump_file, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ int fd = ::open(dump_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
if (fd >= 0) {
// include an informative header
uuid_d fsid = monc->get_fsid();
derr << "recover_journal failed, try to get header from dump file " << dendl;
}
- int fd = ::open(dump_file, O_RDONLY);
+ int fd = ::open(dump_file, O_RDONLY|O_BINARY);
if (fd < 0) {
r = errno;
derr << "couldn't open " << dump_file << ": " << cpp_strerror(r) << dendl;
if (filename == "-") {
fd = STDOUT_FILENO;
} else {
- fd = TEMP_FAILURE_RETRY(::open(filename.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0644));
+ fd = TEMP_FAILURE_RETRY(::open(filename.c_str(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644));
if (fd < 0) {
int err = errno;
cerr << "failed to open file: " << cpp_strerror(err) << std::endl;
if (strcmp(outfile, "-") == 0) {
fd = STDOUT_FILENO;
} else {
- fd = TEMP_FAILURE_RETRY(::open(outfile, O_WRONLY|O_CREAT|O_TRUNC, 0644));
+ fd = TEMP_FAILURE_RETRY(::open(outfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644));
if (fd < 0) {
int err = errno;
cerr << "failed to open file: " << cpp_strerror(err) << std::endl;
int ret = 0;
int fd = STDIN_FILENO;
if (!stdio)
- fd = open(infile, O_RDONLY);
+ fd = open(infile, O_RDONLY|O_BINARY);
if (fd < 0) {
cerr << "error reading input file " << infile << ": " << cpp_strerror(errno) << std::endl;
return 1;
int ret = 0;
int fd = STDIN_FILENO;
if (!stdio)
- fd = open(infile, O_RDONLY);
+ fd = open(infile, O_RDONLY|O_BINARY);
if (fd < 0) {
cerr << "error reading input file " << infile << ": " << cpp_strerror(errno) << std::endl;
return 1;
if (nargs.size() < 2 || std::string(nargs[1]) == "-") {
file_fd = STDOUT_FILENO;
} else {
- file_fd = open(nargs[1], O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ file_fd = open(nargs[1], O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
if (file_fd < 0) {
cerr << "Error opening '" << nargs[1] << "': "
<< cpp_strerror(file_fd) << std::endl;
if (filename == "-") {
file_fd = STDIN_FILENO;
} else {
- file_fd = open(filename.c_str(), O_RDONLY);
+ file_fd = open(filename.c_str(), O_RDONLY|O_BINARY);
if (file_fd < 0) {
cerr << "Error opening '" << filename << "': "
<< cpp_strerror(file_fd) << std::endl;
if (strcmp(path, "-") == 0)
fd = STDOUT_FILENO;
else
- fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
+ fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0644);
if (fd < 0)
return -errno;
if (to_stdout) {
fd = STDOUT_FILENO;
} else {
- fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
+ fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0644);
if (fd < 0) {
return -errno;
}
if (strcmp(path, "-") == 0) {
fd = STDIN_FILENO;
} else {
- fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY|O_BINARY);
if (fd < 0) {
r = -errno;
std::cerr << "rbd: error opening " << path << std::endl;
fd = STDIN_FILENO;
size = 1ULL << order;
} else {
- if ((fd = open(path, O_RDONLY)) < 0) {
+ if ((fd = open(path, O_RDONLY|O_BINARY)) < 0) {
r = -errno;
std::cerr << "rbd: error opening " << path << std::endl;
goto done2;
if (to_stdout) {
fd = STDOUT_FILENO;
} else {
- fd = open(path.c_str(), O_WRONLY | O_CREAT | O_EXCL, 0644);
+ fd = open(path.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0644);
if (fd < 0) {
r = -errno;
std::cerr << "rbd: error creating " << path << std::endl;
if (from_stdin) {
fd = STDIN_FILENO;
} else {
- if ((fd = open(path.c_str(), O_RDONLY)) < 0) {
+ if ((fd = open(path.c_str(), O_RDONLY|O_BINARY)) < 0) {
r = -errno;
std::cerr << "rbd: error opening " << path << std::endl;
return r;
if (first_stdin) {
fd = STDIN_FILENO;
} else {
- fd = open(first, O_RDONLY);
+ fd = open(first, O_RDONLY|O_BINARY);
if (fd < 0) {
r = -errno;
std::cerr << "rbd: error opening " << first << std::endl;
}
}
- sd = open(second, O_RDONLY);
+ sd = open(second, O_RDONLY|O_BINARY);
if (sd < 0) {
r = -errno;
std::cerr << "rbd: error opening " << second << std::endl;
if (strcmp(path, "-") == 0) {
pd = 1;
} else {
- pd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
+ pd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0644);
if (pd < 0) {
r = -errno;
std::cerr << "rbd: error create " << path << std::endl;
int fd = STDIN_FILENO;
if (token_path != "-") {
- fd = open(token_path.c_str(), O_RDONLY);
+ fd = open(token_path.c_str(), O_RDONLY|O_BINARY);
if (fd < 0) {
r = -errno;
std::cerr << "rbd: error opening " << token_path << std::endl;