now we need to init the mstorage objects
This commit is contained in:
@@ -18,3 +18,4 @@ idx2ldif
|
||||
ldap-capture
|
||||
server
|
||||
md5password
|
||||
t6
|
||||
|
||||
@@ -34,6 +34,8 @@ int main(int argc,char* argv[]) {
|
||||
uint32 magic,attribute_count,record_count,indices_offset,size_of_string_table;
|
||||
uint32 wanted,casesensitive,dn,objectClass;
|
||||
|
||||
mstorage_init(&idx);
|
||||
|
||||
if (argc<3) {
|
||||
buffer_putsflush(buffer_2,"usage: ./addindex filename attribute [i]\n"
|
||||
"if i is present, make index case insensitive.\n");
|
||||
|
||||
@@ -67,9 +67,9 @@ long mstorage_add(mstorage_t* p,const char* s,unsigned long n) {
|
||||
#endif
|
||||
if (p->fd!=-1) {
|
||||
/* slight complication if the storage is file based: we need to
|
||||
* make sure the file size is extended. */
|
||||
if (lseek(p->fd,need-1,SEEK_SET)==-1) return -1;
|
||||
if (write(p->fd,"x",1)!=1) return -1;
|
||||
* make sure the file size is extended, or the byte_copy will
|
||||
* yield a bus error. */
|
||||
if (ftruncate(p->fd,need)==-1) return -1;
|
||||
}
|
||||
p->mapped=need; p->root=tmp;
|
||||
}
|
||||
|
||||
7
mstorage_init.c
Normal file
7
mstorage_init.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <mstorage.h>
|
||||
|
||||
void mstorage_init(mstorage_t* p) {
|
||||
p->root=0;
|
||||
p->mapped=p->used=0;
|
||||
p->fd=-1;
|
||||
}
|
||||
17
parse.c
17
parse.c
@@ -41,15 +41,21 @@ void dumprec(struct ldaprec* l) {
|
||||
buffer_putsflush(buffer_1,"\n");
|
||||
}
|
||||
|
||||
extern mstorage_t stringtable;
|
||||
|
||||
int main(int argc,char* argv[]) {
|
||||
int fd;
|
||||
long len;
|
||||
char* destname=argc<3?"data":argv[2];
|
||||
unsigned long size_of_string_table,indices_offset,record_count;
|
||||
long offset_stringtable,offset_classes,offset_attributes;
|
||||
char* map,* dest;
|
||||
|
||||
mstorage_init(&stringtable);
|
||||
|
||||
ldif_parse(argc<2?"exp.ldif":argv[1]);
|
||||
if (!first) {
|
||||
buffer_putsflush(buffer_2,"no data?!");
|
||||
buffer_putsflush(buffer_2,"usage: parse [src-ldif-filename] [dest-bin-filename]\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -97,14 +103,15 @@ int main(int argc,char* argv[]) {
|
||||
indices_offset=len;
|
||||
len+=record_count*4;
|
||||
/* done! we don't create any indices for now. */
|
||||
if ((fd=open("data",O_RDWR|O_CREAT|O_TRUNC,0600))<0) {
|
||||
buffer_putsflush(buffer_2,"could not create data");
|
||||
|
||||
if ((fd=open(destname,O_RDWR|O_CREAT|O_TRUNC,0600))<0) {
|
||||
buffer_putsflush(buffer_2,"could not create destination data file");
|
||||
return 1;
|
||||
}
|
||||
ftruncate(fd,len);
|
||||
if ((map=mmap(0,len,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0))==MAP_FAILED) {
|
||||
buffer_putsflush(buffer_2,"could not mmap data!\n");
|
||||
unlink("data");
|
||||
buffer_putsflush(buffer_2,"could not mmap destination data file!\n");
|
||||
unlink(destname);
|
||||
return 1;
|
||||
}
|
||||
uint32_pack(map ,0xfefe1da9); /* magic */
|
||||
|
||||
Reference in New Issue
Block a user