]> git.wh0rd.org - dump.git/blame - common/indexer_test.c
SQLlite and QFA overhaul.
[dump.git] / common / indexer_test.c
CommitLineData
70deb804
SP
1#include <config.h>
2#include <stdio.h>
3#include <stdarg.h>
4#include <dirent.h>
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <sys/param.h>
8#include <limits.h>
9
10#include <bsdcompat.h>
11#include <protocols/dumprestore.h>
12
13#ifdef __linux__
14#include <linux/types.h>
15#ifdef HAVE_EXT2FS_EXT2_FS_H
16#include <ext2fs/ext2_fs.h>
17#else
18#include <linux/ext2_fs.h>
19#endif
20#include <ext2fs/ext2fs.h>
21#elif defined sunos
22#include <sys/vnode.h>
23#include <ufs/inode.h>
24#include <ufs/fs.h>
25#else
26#include <ufs/ufs/dinode.h>
27#include <ufs/ffs/fs.h>
28#endif
29#include <uuid/uuid.h>
30
31#include "indexer.h"
32#include "slave.h"
33
34int notify;
35dump_ino_t volinfo[TP_NINOS];
36
37int nddates;
38struct dumpdates **ddatev;
39char *host = NULL;
40int tapefd;
41int tapeno;
42
43struct slave slaves[SLAVES+1];
44struct slave *slp;
45
46union u_spcl u_spcl;
47
48#ifdef __linux__
49struct struct_ext2_filsys test_fs;
50struct ext2_super_block test_super;
51ext2_filsys fs = &test_fs;
52#else
53struct fs *sblock; /* the file system super block */
54char sblock_buf[MAXBSIZE];
55#endif
56
57/* for dumprmt.c */
58int dokerberos = 0;
59int ntrec;
60int abortifconnerr = 0;
61
62/*
63 *
64 */
65void
66msg(const char *fmt, ...)
67{
68 va_list ap;
69 va_start(ap, fmt);
70 vprintf(fmt, ap);
71 va_end(ap);
72}
73
74/*
75 * print error message and quit.
76 */
77int
78quit(const char *msg)
79{
80 printf("%s\n", msg);
81 exit(1);
82}
83
84/*
85 * Compute and fill in checksum information. (from dump/traverse.c)
86 */
87void
88mkchecksum(union u_spcl *tmpspcl)
89{
90 int32_t sum, cnt, *lp;
91
92 tmpspcl->s_spcl.c_checksum = 0;
93 lp = (int32_t *)&tmpspcl->s_spcl;
94 sum = 0;
95 cnt = sizeof(union u_spcl) / (4 * sizeof(int32_t));
96 while (--cnt >= 0) {
97 sum += *lp++;
98 sum += *lp++;
99 sum += *lp++;
100 sum += *lp++;
101 }
102 tmpspcl->s_spcl.c_checksum = CHECKSUM - sum;
103}
104
105/*
106 *
107 */
108int
109dump_inode(Indexer *indexer, struct stat *buf)
110{
111 struct dinode dinode;
112
113 memset(&dinode, 0, sizeof dinode);
114 dinode.di_mode = buf->st_mode;
115 dinode.di_nlink = buf->st_nlink;
116 dinode.di_uid = buf->st_uid;
117 dinode.di_gid = buf->st_gid;
118 dinode.di_rdev = buf->st_rdev;
119 dinode.di_size = buf->st_size;
120 dinode.di_atime = buf->st_atime;
121 dinode.di_mtime = buf->st_mtime;
122 dinode.di_ctime = buf->st_ctime;
123 dinode.di_blocks = buf->st_blocks;
124
125 spcl.c_tapea++;
126
127 indexer->addInode(&dinode, buf->st_ino, 0);
128}
129
130/*
131 *
132 */
133int
134dump_walk(Indexer *indexer, const char *root, int first)
135{
136 DIR *dirp;
137 struct dirent *dp;
138 char pathname[MAXPATHLEN];
139 struct stat bufroot, bufentry;
140 struct direct direct;
141
142 dirp = opendir(root);
143 if (dirp == NULL) {
144 printf("%s:%d: trying to open '%s'\n", __FILE__, __LINE__, root);
145 perror(root);
146 return -1;
147 }
148
149 stat(root, &bufroot);
150
151 //if (first) {
152 // spcl.c_volume = 1;
153 // spcl.c_tapea = 1;
154 // indexer->addDirEntry(&direct, direct.d_ino);
155 // dump_inode(indexer, &bufroot);
156 //}
157
158 while ((dp = readdir(dirp)) != NULL) {
159 direct.d_ino = dp->d_ino;
160 direct.d_reclen = dp->d_reclen;
161 direct.d_type = dp->d_type;
162 direct.d_namlen = strlen(dp->d_name);
163 memcpy(direct.d_name, dp->d_name, MAXNAMLEN + 1);
164 direct.d_name[MAXNAMLEN] = '\0';
165
166 snprintf(pathname, sizeof pathname, "%s/%s", root, dp->d_name);
167 stat(pathname, &bufentry);
168 if (strcmp(dp->d_name, "..")) {
169 indexer->addDirEntry(&direct, bufentry.st_ino);
170 dump_inode(indexer, &bufentry);
171 if (S_ISDIR(bufentry.st_mode)) {
172 if (strcmp(dp->d_name, ".")) {
173 dump_walk(indexer, pathname, 0);
174 }
175 }
176 }
177 }
178 closedir(dirp);
179}
180
181/*
182 *
183 */
184int
185test_indexer(Indexer *indexer, const char *filename, const char *path)
186{
187 struct direct dp;
188 struct stat buf;
189
190#ifdef __linux__
191 test_fs.super = &test_super;
192 uuid_generate_time((unsigned char *)&test_fs.super->s_uuid);
193#endif
194
195 indexer->open(filename, 1);
196
197 dump_walk(indexer, path, 1);
198 indexer->close();
199
200 indexer->open(filename, 0);
201 indexer->close();
202}
203
204/*
205 *
206 */
207int
208main(int argc, char **argv)
209{
210 if (argc == 1) {
211// printf("usage: %s partition\n", argv[0]);
212// exit(1);
213 argv[1] = "/usr/include";
214 }
215
216// test_indexer(&indexer_legacy, "/tmp/archive.data", argv[1]);
217
218#ifdef HAVE_SQLITE3
219 test_indexer(&indexer_sqlite, "/tmp/t.sqlite3", argv[1]);
220#endif /* HAVE_SQLITE3 */
221}