Commit a03e6093 authored by Yoni Fogel's avatar Yoni Fogel

[t:2493] Port filesystem redzone to windows

git-svn-id: file:///svn/toku/tokudb@19294 c7de825b-a66e-492c-adef-691d508d4ae1
parent 387d65c1
#define _CRT_SECURE_NO_DEPRECATE
#include <test.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <toku_stdint.h>
#include <unistd.h>
#include <toku_assert.h>
#include "toku_os.h"
int test_main(int argc, char *const argv[]) {
int verbose = 0;
int limit = 1;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
verbose = 1;
continue;
}
if (strcmp(argv[i], "--timeit") == 0) {
limit = 100000;
continue;
}
}
int r;
#if 0
r = toku_get_filesystem_sizes(NULL, NULL, NULL, NULL);
assert(r == EFAULT);
#endif
r = toku_get_filesystem_sizes(".", NULL, NULL, NULL);
assert(r == 0);
uint64_t free_size = 0, avail_size = 0, total_size = 0;
for (int i = 0; i < limit; i++) {
r = toku_get_filesystem_sizes(".", &avail_size, &free_size, &total_size);
assert(r == 0);
assert(avail_size <= free_size && free_size <= total_size);
}
if (verbose) {
printf("avail=%"PRIu64"\n", avail_size);
printf("free=%"PRIu64"\n", free_size);
printf("total=%"PRIu64"\n", total_size);
}
return 0;
}
......@@ -347,13 +347,24 @@ toku_dup2(int fd, int fd2) {
// for now, just return zeros
int
toku_get_filesystem_sizes(const char *path, uint64_t *avail_size, uint64_t *free_size, uint64_t *total_size) {
uint64_t a = 0, f = 0, t = 0;
path = path;
if (avail_size)
*avail_size = a;
if (free_size)
*free_size = f;
if (total_size)
*total_size = t;
return 0;
int r;
ULARGE_INTEGER free_bytes_for_user;
ULARGE_INTEGER free_bytes_total;
ULARGE_INTEGER total_bytes;
BOOL success = GetDiskFreeSpaceEx(path,
&free_bytes_for_user,
&total_bytes,
&free_bytes_total);
if (success) {
r = 0;
if (avail_size) *avail_size = free_bytes_for_user.QuadPart;
if (free_size) *free_size = free_bytes_total.QuadPart;
if (total_size) *total_size = total_bytes.QuadPart;
}
else {
r = GetLastError();
}
return r;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment