diff options
Diffstat (limited to 'lib/ntdb')
-rw-r--r-- | lib/ntdb/check.c | 7 | ||||
-rw-r--r-- | lib/ntdb/free.c | 2 | ||||
-rw-r--r-- | lib/ntdb/io.c | 13 | ||||
-rw-r--r-- | lib/ntdb/open.c | 2 | ||||
-rw-r--r-- | lib/ntdb/private.h | 12 | ||||
-rw-r--r-- | lib/ntdb/transaction.c | 2 |
6 files changed, 24 insertions, 14 deletions
diff --git a/lib/ntdb/check.c b/lib/ntdb/check.c index 723e7b11bf..be27003a51 100644 --- a/lib/ntdb/check.c +++ b/lib/ntdb/check.c @@ -505,10 +505,9 @@ static enum NTDB_ERROR check_free(struct ntdb_context *ntdb, } - ecode = ntdb->io->oob(ntdb, off, - frec_len(frec) - + sizeof(struct ntdb_used_record), - false); + ecode = ntdb_oob(ntdb, off, + frec_len(frec) + sizeof(struct ntdb_used_record), + false); if (ecode != NTDB_SUCCESS) { return ecode; } diff --git a/lib/ntdb/free.c b/lib/ntdb/free.c index f51aa5bc33..3e31937382 100644 --- a/lib/ntdb/free.c +++ b/lib/ntdb/free.c @@ -932,7 +932,7 @@ static enum NTDB_ERROR ntdb_expand(struct ntdb_context *ntdb, ntdb_len_t size) /* Someone else may have expanded the file, so retry. */ old_size = ntdb->file->map_size; - ntdb->io->oob(ntdb, ntdb->file->map_size, 1, true); + ntdb_oob(ntdb, ntdb->file->map_size, 1, true); if (ntdb->file->map_size != old_size) { ntdb_unlock_expand(ntdb, F_WRLCK); return NTDB_SUCCESS; diff --git a/lib/ntdb/io.c b/lib/ntdb/io.c index b20141cc8f..138a405dda 100644 --- a/lib/ntdb/io.c +++ b/lib/ntdb/io.c @@ -92,8 +92,9 @@ enum NTDB_ERROR ntdb_mmap(struct ntdb_context *ntdb) If probe is true, len being too large isn't a failure. */ -static enum NTDB_ERROR ntdb_oob(struct ntdb_context *ntdb, - ntdb_off_t off, ntdb_len_t len, bool probe) +static enum NTDB_ERROR ntdb_normal_oob(struct ntdb_context *ntdb, + ntdb_off_t off, ntdb_len_t len, + bool probe) { struct stat st; enum NTDB_ERROR ecode; @@ -112,8 +113,6 @@ static enum NTDB_ERROR ntdb_oob(struct ntdb_context *ntdb, (long long)off, (long long)len); } - if (len + off <= ntdb->file->map_size) - return NTDB_SUCCESS; if (ntdb->flags & NTDB_INTERNAL) { if (probe) return NTDB_SUCCESS; @@ -271,7 +270,7 @@ static enum NTDB_ERROR ntdb_write(struct ntdb_context *ntdb, ntdb_off_t off, "Write to read-only database"); } - ecode = ntdb->io->oob(ntdb, off, len, false); + ecode = ntdb_oob(ntdb, off, len, false); if (ecode != NTDB_SUCCESS) { return ecode; } @@ -305,7 +304,7 @@ static enum NTDB_ERROR ntdb_read(struct ntdb_context *ntdb, ntdb_off_t off, { enum NTDB_ERROR ecode; - ecode = ntdb->io->oob(ntdb, off, len, false); + ecode = ntdb_oob(ntdb, off, len, false); if (ecode != NTDB_SUCCESS) { return ecode; } @@ -639,7 +638,7 @@ void ntdb_inc_seqnum(struct ntdb_context *ntdb) static const struct ntdb_methods io_methods = { ntdb_read, ntdb_write, - ntdb_oob, + ntdb_normal_oob, ntdb_expand_file, ntdb_direct, }; diff --git a/lib/ntdb/open.c b/lib/ntdb/open.c index dc473d2680..6aac46ab2f 100644 --- a/lib/ntdb/open.c +++ b/lib/ntdb/open.c @@ -718,7 +718,7 @@ _PUBLIC_ struct ntdb_context *ntdb_open(const char *name, int ntdb_flags, ntdb_unlock_open(ntdb, openlock); /* This makes sure we have current map_size and mmap. */ - ecode = ntdb->io->oob(ntdb, ntdb->file->map_size, 1, true); + ecode = ntdb_oob(ntdb, ntdb->file->map_size, 1, true); if (unlikely(ecode != NTDB_SUCCESS)) goto fail; diff --git a/lib/ntdb/private.h b/lib/ntdb/private.h index ee8eeb76af..f46b5ef906 100644 --- a/lib/ntdb/private.h +++ b/lib/ntdb/private.h @@ -630,6 +630,18 @@ enum NTDB_ERROR COLD PRINTF_FMT(4, 5) enum ntdb_log_level level, const char *fmt, ...); +static inline enum NTDB_ERROR ntdb_oob(struct ntdb_context *ntdb, + ntdb_off_t off, ntdb_len_t len, + bool probe) +{ + if (likely(off + len >= off) + && likely(off + len <= ntdb->file->map_size) + && likely(!probe)) { + return NTDB_SUCCESS; + } + return ntdb->io->oob(ntdb, off, len, probe); +} + #ifdef NTDB_TRACE void ntdb_trace(struct ntdb_context *ntdb, const char *op); void ntdb_trace_seqnum(struct ntdb_context *ntdb, uint32_t seqnum, const char *op); diff --git a/lib/ntdb/transaction.c b/lib/ntdb/transaction.c index 11dd7b4af5..a265252174 100644 --- a/lib/ntdb/transaction.c +++ b/lib/ntdb/transaction.c @@ -568,7 +568,7 @@ _PUBLIC_ enum NTDB_ERROR ntdb_transaction_start(struct ntdb_context *ntdb) /* make sure we know about any file expansions already done by anyone else */ - ntdb->io->oob(ntdb, ntdb->file->map_size, 1, true); + ntdb_oob(ntdb, ntdb->file->map_size, 1, true); ntdb->transaction->old_map_size = ntdb->file->map_size; /* finally hook the io methods, replacing them with |