From 73e32ddf7757016f2d3530b6e28d8b652b431d12 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 7 Feb 2022 10:12:09 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/pgfile.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/db/pgfile.c b/source/libs/tdb/src/db/pgfile.c index 9e4795dc08..670fc3a667 100644 --- a/source/libs/tdb/src/db/pgfile.c +++ b/source/libs/tdb/src/db/pgfile.c @@ -106,6 +106,29 @@ int pgFileWrite(SPage *pPage) { } static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData) { - // TODO + pgsize_t pgSize; + ssize_t rsize; + uint8_t *pTData; + size_t szToRead; + + // pgSize = ; (TODO) + pTData = pData; + szToRead = pgSize; + for (; szToRead > 0;) { + rsize = pread(pPgFile->fd, pTData, szToRead, pgno * pgSize); + if (rsize < 0) { + if (errno == EINTR) { + continue; + } else { + return -1; + } + } else if (rsize == 0) { + return -1; + } + + szToRead -= rsize; + pTData += rsize; + } + return 0; } \ No newline at end of file