10 #include <bsdcompat.h>
11 #include <protocols/dumprestore.h>
14 #include <linux/types.h>
15 #ifdef HAVE_EXT2FS_EXT2_FS_H
16 #include <ext2fs/ext2_fs.h>
18 #include <linux/ext2_fs.h>
20 #include <ext2fs/ext2fs.h>
22 #include <sys/vnode.h>
23 #include <ufs/inode.h>
26 #include <ufs/ufs/dinode.h>
27 #include <ufs/ffs/fs.h>
29 #include <uuid/uuid.h>
35 dump_ino_t volinfo[TP_NINOS];
38 struct dumpdates **ddatev;
43 struct slave slaves[SLAVES+1];
49 struct struct_ext2_filsys test_fs;
50 struct ext2_super_block test_super;
51 ext2_filsys fs = &test_fs;
53 struct fs *sblock; /* the file system super block */
54 char sblock_buf[MAXBSIZE];
60 int abortifconnerr = 0;
66 msg(const char *fmt, ...)
75 * print error message and quit.
85 * Compute and fill in checksum information. (from dump/traverse.c)
88 mkchecksum(union u_spcl *tmpspcl)
90 int32_t sum, cnt, *lp;
92 tmpspcl->s_spcl.c_checksum = 0;
93 lp = (int32_t *)&tmpspcl->s_spcl;
95 cnt = sizeof(union u_spcl) / (4 * sizeof(int32_t));
102 tmpspcl->s_spcl.c_checksum = CHECKSUM - sum;
109 dump_inode(Indexer *indexer, struct stat *buf)
111 struct dinode dinode;
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;
127 indexer->addInode(&dinode, buf->st_ino, 0);
134 dump_walk(Indexer *indexer, const char *root, int first)
138 char pathname[MAXPATHLEN];
139 struct stat bufroot, bufentry;
140 struct direct direct;
142 dirp = opendir(root);
144 printf("%s:%d: trying to open '%s'\n", __FILE__, __LINE__, root);
149 stat(root, &bufroot);
152 // spcl.c_volume = 1;
154 // indexer->addDirEntry(&direct, direct.d_ino);
155 // dump_inode(indexer, &bufroot);
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';
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);
185 test_indexer(Indexer *indexer, const char *filename, const char *path)
191 test_fs.super = &test_super;
192 uuid_generate_time((unsigned char *)&test_fs.super->s_uuid);
195 indexer->open(filename, 1);
197 dump_walk(indexer, path, 1);
200 indexer->open(filename, 0);
208 main(int argc, char **argv)
211 // printf("usage: %s partition\n", argv[0]);
213 argv[1] = "/usr/include";
216 // test_indexer(&indexer_legacy, "/tmp/archive.data", argv[1]);
219 test_indexer(&indexer_sqlite, "/tmp/t.sqlite3", argv[1]);
220 #endif /* HAVE_SQLITE3 */