endif()
if(WIN32)
- list(APPEND ceph_common_deps ws2_32 mswsock)
+ list(APPEND ceph_common_deps ws2_32 mswsock bcrypt)
list(APPEND ceph_common_deps dlfcn_win32)
endif()
}
}
-#else // !HAVE_GETENTROPY
+#elif defined(_WIN32) // !HAVE_GETENTROPY
+#include <bcrypt.h>
+
+CryptoRandom::CryptoRandom() : fd(0) {}
+CryptoRandom::~CryptoRandom() = default;
+
+void CryptoRandom::get_bytes(char *buf, int len)
+{
+ auto ret = BCryptGenRandom (
+ NULL,
+ (unsigned char*)buf,
+ len,
+ BCRYPT_USE_SYSTEM_PREFERRED_RNG);
+ if (ret != 0) {
+ throw std::system_error(ret, std::system_category());
+ }
+}
+
+#else // !HAVE_GETENTROPY && !_WIN32
// open /dev/urandom once on construction and reuse the fd for all reads
CryptoRandom::CryptoRandom()
: fd{open_urandom()}
*
*/
+#include <utime.h>
#include <signal.h>
#include "HeartbeatMap.h"
if (path.length() && is_healthy()) {
int fd = ::open(path.c_str(), O_WRONLY|O_CREAT|O_CLOEXEC, 0644);
if (fd >= 0) {
- ::utimes(path.c_str(), NULL);
+ ::utime(path.c_str(), NULL);
::close(fd);
} else {
ldout(m_cct, 0) << "unable to touch " << path << ": "
char *ceph_strerror_r(int errnum, char *buf, size_t buflen)
{
-#ifdef STRERROR_R_CHAR_P
+#ifdef _WIN32
+ strerror_s(buf, buflen, errnum);
+ return buf;
+#elif defined(STRERROR_R_CHAR_P)
return strerror_r(errnum, buf, buflen);
#else
if (strerror_r(errnum, buf, buflen)) {
#include <unistd.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
namespace ceph {
// page size crap, see page.h
return n;
}
+ #ifdef _WIN32
+ unsigned _get_page_size() {
+ SYSTEM_INFO system_info;
+ GetSystemInfo(&system_info);
+ return system_info.dwPageSize;
+ }
+
+ unsigned _page_size = _get_page_size();
+ #else
unsigned _page_size = sysconf(_SC_PAGESIZE);
+ #endif
unsigned long _page_mask = ~(unsigned long)(_page_size - 1);
unsigned _page_shift = _get_bits_of(_page_size - 1);
#ifdef __cplusplus
}
+
+// Windows' mkdir doesn't accept a mode argument.
+#define compat_mkdir(pathname, mode) mkdir(pathname)
+
#endif
// O_CLOEXEC is not defined on Windows. Since handles aren't inherited
// flag as a no-op.
#define O_CLOEXEC 0
+#define compat_mkdir(pathname, mode) mkdir(pathname, mode)
+
#endif /* WIN32 */
#endif /* !CEPH_COMPAT_H */
if (out_date) {
char buf[32];
- strftime(buf, sizeof(buf), "%F", &tm);
+ strftime(buf, sizeof(buf), "%Y-%m-%d", &tm);
*out_date = buf;
}
if (out_time) {
char buf[32];
- strftime(buf, sizeof(buf), "%T", &tm);
+ strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
*out_time = buf;
}
int r;
dout(1) << __func__ << dendl;
if (create) {
- r = ::mkdir(m_db_path.c_str(), 0700);
+ r = compat_mkdir(m_db_path.c_str(), 0700);
if (r < 0) {
r = -errno;
if (r != -EEXIST) {
unique_ptr<rocksdb::Directory> dir;
env->NewDirectory(path, &dir);
} else {
- int r = ::mkdir(path.c_str(), 0755);
+ int r = compat_mkdir(path.c_str(), 0755);
if (r < 0)
r = -errno;
if (r < 0 && r != -EEXIST) {
// return the sent length
// < 0 means error occurred
+ #ifndef _WIN32
static ssize_t do_sendmsg(int fd, struct msghdr &msg, unsigned len, bool more)
{
size_t sent = 0;
return static_cast<ssize_t>(sent_bytes);
}
+ #else
+ ssize_t send(bufferlist &bl, bool more) override
+ {
+ size_t total_sent_bytes = 0;
+ auto pb = std::cbegin(bl.buffers());
+ uint64_t left_pbrs = bl.get_num_buffers();
+ while (left_pbrs) {
+ WSABUF msgvec[IOV_MAX];
+ uint64_t size = std::min<uint64_t>(left_pbrs, IOV_MAX);
+ left_pbrs -= size;
+ unsigned msglen = 0;
+ for (auto iov = msgvec; iov != msgvec + size; iov++) {
+ iov->buf = const_cast<char*>(pb->c_str());
+ iov->len = pb->length();
+ msglen += pb->length();
+ ++pb;
+ }
+ DWORD sent_bytes = 0;
+ DWORD flags = 0;
+ if (more)
+ flags |= MSG_PARTIAL;
+
+ int ret_val = WSASend(_fd, msgvec, size, &sent_bytes, flags, NULL, NULL);
+ if (ret_val)
+ return -ret_val;
+
+ total_sent_bytes += sent_bytes;
+ if (static_cast<unsigned>(sent_bytes) < msglen)
+ break;
+ }
+
+ if (total_sent_bytes) {
+ bufferlist swapped;
+ if (total_sent_bytes < bl.length()) {
+ bl.splice(total_sent_bytes, bl.length()-total_sent_bytes, &swapped);
+ bl.swap(swapped);
+ } else {
+ bl.clear();
+ }
+ }
+
+ return static_cast<ssize_t>(total_sent_bytes);
+ }
+ #endif
void shutdown() override {
::shutdown(_fd, SHUT_RDWR);
}
int flags;
int r = 0;
+ #ifdef _WIN32
+ ULONG mode = 1;
+ r = ioctlsocket(sd, FIONBIO, &mode);
+ if (r) {
+ lderr(cct) << __func__ << " ioctlsocket(FIONBIO) failed: " << r << dendl;
+ return -r;
+ }
+ #else
/* Set the socket nonblocking.
* Note that fcntl(2) for F_GETFL and F_SETFL can't be
* interrupted by a signal. */
lderr(cct) << __func__ << " fcntl(F_SETFL,O_NONBLOCK): " << cpp_strerror(r) << dendl;
return -r;
}
+ #endif
return 0;
}