tdb/common/dump.c

説明を見る。
00001  /* 
00002    Unix SMB/CIFS implementation.
00003 
00004    trivial database library
00005 
00006    Copyright (C) Andrew Tridgell              1999-2005
00007    Copyright (C) Paul `Rusty' Russell              2000
00008    Copyright (C) Jeremy Allison                    2000-2003
00009    
00010      ** NOTE! The following LGPL license applies to the tdb
00011      ** library. This does NOT imply that all of Samba is released
00012      ** under the LGPL
00013    
00014    This library is free software; you can redistribute it and/or
00015    modify it under the terms of the GNU Lesser General Public
00016    License as published by the Free Software Foundation; either
00017    version 2 of the License, or (at your option) any later version.
00018 
00019    This library is distributed in the hope that it will be useful,
00020    but WITHOUT ANY WARRANTY; without even the implied warranty of
00021    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022    Lesser General Public License for more details.
00023 
00024    You should have received a copy of the GNU Lesser General Public
00025    License along with this library; if not, write to the Free Software
00026    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 */
00028 
00029 #include "tdb_private.h"
00030 
00031 static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash,
00032                                  tdb_off_t offset)
00033 {
00034         struct list_struct rec;
00035         tdb_off_t tailer_ofs, tailer;
00036 
00037         if (tdb->methods->tdb_read(tdb, offset, (char *)&rec, 
00038                                    sizeof(rec), DOCONV()) == -1) {
00039                 printf("ERROR: failed to read record at %u\n", offset);
00040                 return 0;
00041         }
00042 
00043         printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%d "
00044                "key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n",
00045                hash, offset, rec.next, rec.rec_len, rec.key_len, rec.data_len,
00046                rec.full_hash, rec.magic);
00047 
00048         tailer_ofs = offset + sizeof(rec) + rec.rec_len - sizeof(tdb_off_t);
00049 
00050         if (tdb_ofs_read(tdb, tailer_ofs, &tailer) == -1) {
00051                 printf("ERROR: failed to read tailer at %u\n", tailer_ofs);
00052                 return rec.next;
00053         }
00054 
00055         if (tailer != rec.rec_len + sizeof(rec)) {
00056                 printf("ERROR: tailer does not match record! tailer=%u totalsize=%u\n",
00057                                 (unsigned int)tailer, (unsigned int)(rec.rec_len + sizeof(rec)));
00058         }
00059         return rec.next;
00060 }
00061 
00062 static int tdb_dump_chain(struct tdb_context *tdb, int i)
00063 {
00064         tdb_off_t rec_ptr, top;
00065 
00066         top = TDB_HASH_TOP(i);
00067 
00068         if (tdb_lock(tdb, i, F_WRLCK) != 0)
00069                 return -1;
00070 
00071         if (tdb_ofs_read(tdb, top, &rec_ptr) == -1)
00072                 return tdb_unlock(tdb, i, F_WRLCK);
00073 
00074         if (rec_ptr)
00075                 printf("hash=%d\n", i);
00076 
00077         while (rec_ptr) {
00078                 rec_ptr = tdb_dump_record(tdb, i, rec_ptr);
00079         }
00080 
00081         return tdb_unlock(tdb, i, F_WRLCK);
00082 }
00083 
00084 void tdb_dump_all(struct tdb_context *tdb)
00085 {
00086         int i;
00087         for (i=0;i<tdb->header.hash_size;i++) {
00088                 tdb_dump_chain(tdb, i);
00089         }
00090         printf("freelist:\n");
00091         tdb_dump_chain(tdb, -1);
00092 }
00093 
00094 int tdb_printfreelist(struct tdb_context *tdb)
00095 {
00096         int ret;
00097         long total_free = 0;
00098         tdb_off_t offset, rec_ptr;
00099         struct list_struct rec;
00100 
00101         if ((ret = tdb_lock(tdb, -1, F_WRLCK)) != 0)
00102                 return ret;
00103 
00104         offset = FREELIST_TOP;
00105 
00106         /* read in the freelist top */
00107         if (tdb_ofs_read(tdb, offset, &rec_ptr) == -1) {
00108                 tdb_unlock(tdb, -1, F_WRLCK);
00109                 return 0;
00110         }
00111 
00112         printf("freelist top=[0x%08x]\n", rec_ptr );
00113         while (rec_ptr) {
00114                 if (tdb->methods->tdb_read(tdb, rec_ptr, (char *)&rec, 
00115                                            sizeof(rec), DOCONV()) == -1) {
00116                         tdb_unlock(tdb, -1, F_WRLCK);
00117                         return -1;
00118                 }
00119 
00120                 if (rec.magic != TDB_FREE_MAGIC) {
00121                         printf("bad magic 0x%08x in free list\n", rec.magic);
00122                         tdb_unlock(tdb, -1, F_WRLCK);
00123                         return -1;
00124                 }
00125 
00126                 printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)] (end = 0x%08x)\n", 
00127                        rec_ptr, rec.rec_len, rec.rec_len, rec_ptr + rec.rec_len);
00128                 total_free += rec.rec_len;
00129 
00130                 /* move to the next record */
00131                 rec_ptr = rec.next;
00132         }
00133         printf("total rec_len = [0x%08x (%d)]\n", (int)total_free, 
00134                (int)total_free);
00135 
00136         return tdb_unlock(tdb, -1, F_WRLCK);
00137 }
00138 

Sambaに対してSat Aug 29 21:23:26 2009に生成されました。  doxygen 1.4.7