Commit cfb07b7d authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1307

fstat calls replaced with toku_os calls.
fstat deprecated everywhere except the 'linux' portability directory

git-svn-id: file:///svn/toku/tokudb.1032b@8264 c7de825b-a66e-492c-adef-691d508d4ae1
parent 3e2b8392
...@@ -69,6 +69,11 @@ extern "C" { ...@@ -69,6 +69,11 @@ extern "C" {
#define UU(x) x __attribute__((__unused__)) #define UU(x) x __attribute__((__unused__))
// Deprecated functions.
#if !defined(TOKU_ALLOW_DEPRECATED_FSTAT)
int fstat() __attribute__((__deprecated__));
#endif
#if defined __cplusplus #if defined __cplusplus
}; };
#endif #endif
......
...@@ -11,6 +11,8 @@ SRCS = $(wildcard *.c) ...@@ -11,6 +11,8 @@ SRCS = $(wildcard *.c)
OBJS = $(patsubst %.c,%.$(OEXT),$(SRCS)) OBJS = $(patsubst %.c,%.$(OEXT),$(SRCS))
TARGET = libtokuportability.$(AEXT) TARGET = libtokuportability.$(AEXT)
$(OBJS): CFLAGS += -DTOKU_ALLOW_DEPRECATED_FSTAT
install: $(TARGET) install: $(TARGET)
$(MAYBEATSIGN)cp $(TARGET) $(LIBPORTABILITY) $(MAYBEATSIGN)cp $(TARGET) $(LIBPORTABILITY)
......
...@@ -24,18 +24,18 @@ static inline u_int64_t alignup (u_int64_t a, u_int64_t b) { ...@@ -24,18 +24,18 @@ static inline u_int64_t alignup (u_int64_t a, u_int64_t b) {
} }
static void maybe_preallocate_in_file (int fd, u_int64_t size) { static void maybe_preallocate_in_file (int fd, u_int64_t size) {
struct stat sbuf; int64_t file_size;
{ {
int r = fstat(fd, &sbuf); int r = toku_os_get_file_size(fd, &file_size);
assert(r==0); assert(r==0);
} }
assert(sbuf.st_size >= 0); assert(file_size >= 0);
if ((size_t)sbuf.st_size < size) { if ((size_t)file_size < size) {
const int N = umin64(size, 16<<20); // Double the size of the file, or add 16MB, whichever is less. const int N = umin64(size, 16<<20); // Double the size of the file, or add 16MB, whichever is less.
char *MALLOC_N(N, wbuf); char *MALLOC_N(N, wbuf);
memset(wbuf, 0, N); memset(wbuf, 0, N);
toku_off_t start_write = alignup(sbuf.st_size, 4096); toku_off_t start_write = alignup(file_size, 4096);
assert(start_write >= sbuf.st_size); assert(start_write >= file_size);
ssize_t r = pwrite(fd, wbuf, N, start_write); ssize_t r = pwrite(fd, wbuf, N, start_write);
assert(r==N); assert(r==N);
toku_free(wbuf); toku_free(wbuf);
......
...@@ -241,8 +241,8 @@ int toku_cachetable_openf (CACHEFILE *cf, CACHETABLE t, const char *fname, int f ...@@ -241,8 +241,8 @@ int toku_cachetable_openf (CACHEFILE *cf, CACHETABLE t, const char *fname, int f
int toku_cachefile_set_fd (CACHEFILE cf, int fd, const char *fname) { int toku_cachefile_set_fd (CACHEFILE cf, int fd, const char *fname) {
int r; int r;
struct stat statbuf; struct fileid fileid;
r=fstat(fd, &statbuf); r=toku_os_get_unique_file_id(fd, &fileid);
if (r != 0) { if (r != 0) {
r=errno; close(fd); return r; r=errno; close(fd); return r;
} }
...@@ -259,10 +259,6 @@ int toku_cachefile_set_fd (CACHEFILE cf, int fd, const char *fname) { ...@@ -259,10 +259,6 @@ int toku_cachefile_set_fd (CACHEFILE cf, int fd, const char *fname) {
toku_free(cf->fname); toku_free(cf->fname);
cf->fname = 0; cf->fname = 0;
} }
struct fileid fileid;
memset(&fileid, 0, sizeof fileid);
fileid.st_dev = statbuf.st_dev;
fileid.st_ino = statbuf.st_ino;
cachefile_init_filenum(cf, fd, fname, fileid); cachefile_init_filenum(cf, fd, fname, fileid);
return 0; return 0;
} }
......
...@@ -10,13 +10,14 @@ ...@@ -10,13 +10,14 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <zlib.h> #include <zlib.h>
#include "toku_portability.h"
off_t fd_size (int fd) { off_t fd_size (int fd) {
struct stat buf; int64_t file_size;
int r = fstat(fd, &buf); int r = toku_os_get_file_size(fd, &file_size);
assert(r==0); assert(r==0);
return buf.st_size; return file_size;
} }
#define NSIZE (1<<20) #define NSIZE (1<<20)
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "toku_portability.h"
int verbose=0; int verbose=0;
static inline void static inline void
......
...@@ -18,15 +18,15 @@ grep_for_in_logs (const char *str) { ...@@ -18,15 +18,15 @@ grep_for_in_logs (const char *str) {
#endif #endif
int fd = open(lname, O_RDONLY); int fd = open(lname, O_RDONLY);
assert(fd>=0); assert(fd>=0);
struct stat statbuf; int64_t file_size;
int r = fstat(fd, &statbuf); int r = toku_os_get_file_size(fd, &file_size);
assert(r==0); assert(r==0);
void *addr_v = mmap(0, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); void *addr_v = mmap(0, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
assert(addr_v!=MAP_FAILED); assert(addr_v!=MAP_FAILED);
char *fstr = addr_v; char *fstr = addr_v;
int searchlen=strlen(str); int searchlen=strlen(str);
int i; int i;
for (i=0; i+searchlen<statbuf.st_size; i++) { for (i=0; i+searchlen<file_size; i++) {
if (memcmp(str, fstr+i, searchlen)==0) { if (memcmp(str, fstr+i, searchlen)==0) {
return i; return i;
} }
......
...@@ -90,6 +90,7 @@ toku_os_get_unique_file_id(int fildes, struct fileid *id) { ...@@ -90,6 +90,7 @@ toku_os_get_unique_file_id(int fildes, struct fileid *id) {
id->st_creat |= info.ftCreationTime.dwLowDateTime; id->st_creat |= info.ftCreationTime.dwLowDateTime;
r = 0; r = 0;
cleanup: cleanup:
if (r!=0) errno = r;
return r; 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