関数 | |
static int | seen_insert (struct tdb_context *mem_tdb, tdb_off_t rec_ptr) |
int | tdb_validate_freelist (struct tdb_context *tdb, int *pnum_entries) |
static int seen_insert | ( | struct tdb_context * | mem_tdb, | |
tdb_off_t | rec_ptr | |||
) | [static] |
freelistcheck.c の 37 行で定義されています。
参照先 TDB_DATA::dptr・TDB_DATA::dsize・tdb_store().
00038 { 00039 TDB_DATA key, data; 00040 00041 memset(&data, '\0', sizeof(data)); 00042 key.dptr = (char *)&rec_ptr; 00043 key.dsize = sizeof(rec_ptr); 00044 return tdb_store(mem_tdb, key, data, TDB_INSERT); 00045 }
int tdb_validate_freelist | ( | struct tdb_context * | tdb, | |
int * | pnum_entries | |||
) |
freelistcheck.c の 47 行で定義されています。
参照先 tdb_header::hash_size・tdb_context::header・last_ptr・list_struct::next・rec_free_read()・seen_insert()・tdb・tdb_close()・TDB_ERR_CORRUPT・tdb_lock()・tdb_ofs_read()・tdb_open()・tdb_unlock().
参照元 main().
00048 { 00049 struct tdb_context *mem_tdb = NULL; 00050 struct list_struct rec; 00051 tdb_off_t rec_ptr, last_ptr; 00052 int ret = -1; 00053 00054 *pnum_entries = 0; 00055 00056 mem_tdb = tdb_open("flval", tdb->header.hash_size, 00057 TDB_INTERNAL, O_RDWR, 0600); 00058 if (!mem_tdb) { 00059 return -1; 00060 } 00061 00062 if (tdb_lock(tdb, -1, F_WRLCK) == -1) { 00063 tdb_close(mem_tdb); 00064 return 0; 00065 } 00066 00067 last_ptr = FREELIST_TOP; 00068 00069 /* Store the FREELIST_TOP record. */ 00070 if (seen_insert(mem_tdb, last_ptr) == -1) { 00071 ret = TDB_ERRCODE(TDB_ERR_CORRUPT, -1); 00072 goto fail; 00073 } 00074 00075 /* read in the freelist top */ 00076 if (tdb_ofs_read(tdb, FREELIST_TOP, &rec_ptr) == -1) { 00077 goto fail; 00078 } 00079 00080 while (rec_ptr) { 00081 00082 /* If we can't store this record (we've seen it 00083 before) then the free list has a loop and must 00084 be corrupt. */ 00085 00086 if (seen_insert(mem_tdb, rec_ptr)) { 00087 ret = TDB_ERRCODE(TDB_ERR_CORRUPT, -1); 00088 goto fail; 00089 } 00090 00091 if (rec_free_read(tdb, rec_ptr, &rec) == -1) { 00092 goto fail; 00093 } 00094 00095 /* move to the next record */ 00096 last_ptr = rec_ptr; 00097 rec_ptr = rec.next; 00098 *pnum_entries += 1; 00099 } 00100 00101 ret = 0; 00102 00103 fail: 00104 00105 tdb_close(mem_tdb); 00106 tdb_unlock(tdb, -1, F_WRLCK); 00107 return ret; 00108 }