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" {
#define UU(x) x __attribute__((__unused__))
// Deprecated functions.
#if !defined(TOKU_ALLOW_DEPRECATED_FSTAT)
int fstat() __attribute__((__deprecated__));
#endif
#if defined __cplusplus
};
#endif
......
......@@ -11,6 +11,8 @@ SRCS = $(wildcard *.c)
OBJS = $(patsubst %.c,%.$(OEXT),$(SRCS))
TARGET = libtokuportability.$(AEXT)
$(OBJS): CFLAGS += -DTOKU_ALLOW_DEPRECATED_FSTAT
install: $(TARGET)
$(MAYBEATSIGN)cp $(TARGET) $(LIBPORTABILITY)
......
......@@ -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) {
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(sbuf.st_size >= 0);
if ((size_t)sbuf.st_size < size) {
assert(file_size >= 0);
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.
char *MALLOC_N(N, wbuf);
memset(wbuf, 0, N);
toku_off_t start_write = alignup(sbuf.st_size, 4096);
assert(start_write >= sbuf.st_size);
toku_off_t start_write = alignup(file_size, 4096);
assert(start_write >= file_size);
ssize_t r = pwrite(fd, wbuf, N, start_write);
assert(r==N);
toku_free(wbuf);
......
......@@ -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 r;
struct stat statbuf;
r=fstat(fd, &statbuf);
struct fileid fileid;
r=toku_os_get_unique_file_id(fd, &fileid);
if (r != 0) {
r=errno; close(fd); return r;
}
......@@ -259,10 +259,6 @@ int toku_cachefile_set_fd (CACHEFILE cf, int fd, const char *fname) {
toku_free(cf->fname);
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);
return 0;
}
......
......@@ -10,13 +10,14 @@
#include <sys/stat.h>
#include <unistd.h>
#include <zlib.h>
#include "toku_portability.h"
off_t fd_size (int fd) {
struct stat buf;
int r = fstat(fd, &buf);
int64_t file_size;
int r = toku_os_get_file_size(fd, &file_size);
assert(r==0);
return buf.st_size;
return file_size;
}
#define NSIZE (1<<20)
......
......@@ -2,6 +2,8 @@
#include <string.h>
#include <stdlib.h>
#include "toku_portability.h"
int verbose=0;
static inline void
......
......@@ -18,15 +18,15 @@ grep_for_in_logs (const char *str) {
#endif
int fd = open(lname, O_RDONLY);
assert(fd>=0);
struct stat statbuf;
int r = fstat(fd, &statbuf);
int64_t file_size;
int r = toku_os_get_file_size(fd, &file_size);
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);
char *fstr = addr_v;
int searchlen=strlen(str);
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) {
return i;
}
......
......@@ -90,6 +90,7 @@ toku_os_get_unique_file_id(int fildes, struct fileid *id) {
id->st_creat |= info.ftCreationTime.dwLowDateTime;
r = 0;
cleanup:
if (r!=0) errno = 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