mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 23:39:19 +08:00
mdbx: more check/debug around mdbx_pread() and mdbx_read_header().
This commit is contained in:
parent
f8903ca7c7
commit
678e4f5738
@ -3286,19 +3286,20 @@ static int __cold mdbx_read_header(MDB_env *env, MDB_meta *meta) {
|
|||||||
/* We don't know the page size on first time, so use a minimum value. */
|
/* We don't know the page size on first time, so use a minimum value. */
|
||||||
int rc = mdbx_pread(env->me_fd, &buf, sizeof(buf), offset);
|
int rc = mdbx_pread(env->me_fd, &buf, sizeof(buf), offset);
|
||||||
if (rc != MDB_SUCCESS) {
|
if (rc != MDB_SUCCESS) {
|
||||||
mdbx_debug("read: %s", mdbx_strerror(rc));
|
mdbx_debug("read meta[%u,%u]: %i, %s", offset, (unsigned)sizeof(buf), rc,
|
||||||
|
mdbx_strerror(rc));
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
MDB_page *p = (MDB_page *)&buf;
|
MDB_page *p = (MDB_page *)&buf;
|
||||||
if (!F_ISSET(p->mp_flags, P_META)) {
|
if (!F_ISSET(p->mp_flags, P_META)) {
|
||||||
mdbx_debug("page %zu not a meta page", p->mp_pgno);
|
mdbx_debug("page %zu not a meta-page", p->mp_pgno);
|
||||||
return MDB_INVALID;
|
return MDB_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
MDB_meta *m = PAGEDATA(p);
|
MDB_meta *m = PAGEDATA(p);
|
||||||
if (m->mm_magic != MDB_MAGIC) {
|
if (m->mm_magic != MDB_MAGIC) {
|
||||||
mdbx_debug("meta has invalid magic");
|
mdbx_debug("meta[%u] has invalid magic", offset);
|
||||||
return MDB_INVALID;
|
return MDB_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3310,7 +3311,7 @@ static int __cold mdbx_read_header(MDB_env *env, MDB_meta *meta) {
|
|||||||
|
|
||||||
/* LY: check signature as a checksum */
|
/* LY: check signature as a checksum */
|
||||||
if (META_IS_STEADY(m) && m->mm_datasync_sign != mdbx_meta_sign(m)) {
|
if (META_IS_STEADY(m) && m->mm_datasync_sign != mdbx_meta_sign(m)) {
|
||||||
mdbx_debug("steady-meta has invalid checksum");
|
mdbx_debug("steady-meta[%u] has invalid checksum", offset);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,9 +325,9 @@ int mdbx_closefile(mdbx_filehandle_t fd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, off_t offset) {
|
int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, off_t offset) {
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
|
||||||
if (bytes > MAX_WRITE)
|
if (bytes > MAX_WRITE)
|
||||||
return ERROR_INVALID_PARAMETER;
|
return MDBX_EINVAL;
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
|
||||||
OVERLAPPED ov;
|
OVERLAPPED ov;
|
||||||
ov.hEvent = 0;
|
ov.hEvent = 0;
|
||||||
|
@ -308,7 +308,7 @@ static __inline void mdbx_invalidate_cache(void *addr, size_t nbytes) {
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* max bytes to write in one call */
|
/* max bytes to write in one call */
|
||||||
#define MAX_WRITE (0x80000000U >> (sizeof(ssize_t) == 4))
|
#define MAX_WRITE UINT32_C(0x3fff0000)
|
||||||
|
|
||||||
/* Get the size of a memory page for the system.
|
/* Get the size of a memory page for the system.
|
||||||
* This is the basic size that the platform's memory manager uses, and is
|
* This is the basic size that the platform's memory manager uses, and is
|
||||||
|
Loading…
Reference in New Issue
Block a user