提交 2394e0e0 编写于 作者: H Hongze Cheng

more

上级 e078dd69
......@@ -104,6 +104,7 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) {
}
mpf->fd = -1;
mpf->mp = mp;
if ((mpf->fname = strdup(fname)) == NULL) {
goto _err;
......@@ -113,6 +114,10 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) {
goto _err;
}
if (tdbGnrtFileID(fname, mpf->fileid) < 0) {
goto _err;
}
*mpfp = mpf;
return 0;
......@@ -123,11 +128,28 @@ _err:
}
int tdbMPoolFileClose(TDB_MPFILE *mpf) {
// TODO
if (mpf) {
if (mpf->fd > 0) {
close(mpf->fd);
}
tfree(mpf->fname);
free(mpf);
}
return 0;
}
static int tdbGnrtFileID(const char *fname, uint8_t *fileid) {
// TODO
struct stat statbuf;
if (stat(fname, &statbuf) < 0) {
return -1;
}
memset(fileid, 0, TDB_FILE_ID_LEN);
((uint64_t *)fileid)[0] = (uint64_t)statbuf.st_ino;
((uint64_t *)fileid)[1] = (uint64_t)statbuf.st_dev;
((uint64_t *)fileid)[2] = rand();
return 0;
}
\ No newline at end of file
......@@ -56,10 +56,10 @@ struct TDB_MPOOL {
#define MP_PAGE_AT(mp, idx) (mp)->pages[idx]
struct TDB_MPFILE {
uint8_t fileid[TDB_FILE_ID_LEN]; // file ID
TDB_MPOOL *mp; // underlying memory pool
char * fname; // file name
int fd; // fd
uint8_t fileid[TDB_FILE_ID_LEN]; // file ID
TDB_MPOOL *mp; // underlying memory pool
};
/*=================================================== Exposed apis ==================================================*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册