From 3c4e6bbf90f76f0b6ebaa74e030116989aea83e5 Mon Sep 17 00:00:00 2001 From: leitner Date: Wed, 4 Feb 2004 23:27:01 +0000 Subject: [PATCH] now we need to init the mstorage objects --- .cvsignore | 1 + addindex.c | 2 ++ mstorage_add.c | 6 +++--- mstorage_init.c | 7 +++++++ parse.c | 17 ++++++++++++----- 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 mstorage_init.c diff --git a/.cvsignore b/.cvsignore index b928490..ebfe0d0 100644 --- a/.cvsignore +++ b/.cvsignore @@ -18,3 +18,4 @@ idx2ldif ldap-capture server md5password +t6 diff --git a/addindex.c b/addindex.c index 1ab909b..23af38f 100644 --- a/addindex.c +++ b/addindex.c @@ -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"); diff --git a/mstorage_add.c b/mstorage_add.c index 5e7130a..97e341a 100644 --- a/mstorage_add.c +++ b/mstorage_add.c @@ -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; } diff --git a/mstorage_init.c b/mstorage_init.c new file mode 100644 index 0000000..c342368 --- /dev/null +++ b/mstorage_init.c @@ -0,0 +1,7 @@ +#include + +void mstorage_init(mstorage_t* p) { + p->root=0; + p->mapped=p->used=0; + p->fd=-1; +} diff --git a/parse.c b/parse.c index b9d5970..39864fa 100644 --- a/parse.c +++ b/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 */