From 67772bbf1b5bb90848d82ac3415738345088086e Mon Sep 17 00:00:00 2001 From: Michiel Van Der Kolk Date: Wed, 27 Apr 2005 11:49:51 +0000 Subject: More database maintenance functions.. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6364 a1c6a512-1295-4272-9138-f99709370657 --- apps/database.c | 119 +++++++++++++++++++++++++++++++++++++++++++------------- apps/database.h | 2 +- 2 files changed, 93 insertions(+), 28 deletions(-) diff --git a/apps/database.c b/apps/database.c index 0d562d5..7f605ba 100644 --- a/apps/database.c +++ b/apps/database.c @@ -48,7 +48,7 @@ #ifdef NEW_DB_CODE static char sbuf[1024]; static struct file_entry fe; -static int currentferecord; +static int currentfeoffset, currentferecord; #endif int tagdb_fd = -1; @@ -111,6 +111,9 @@ void tagdb_shutdown(void) /* NOTE: All these functions below are yet untested. */ #ifdef NEW_DB_CODE + +/*** TagDatabase code ***/ + void writetagdbheader() { lseek(tagdb_fd,0,SEEK_SET); write(tagdb_fd, &tagdbheader, 68); @@ -121,12 +124,11 @@ void getfentrybyoffset(int offset) { fread(tagdb_fd,sbuf,tagdbheader.filelen); fread(tagdb_fd,&fe+sizeof(char *),12); fe.name=sbuf; + currentfeoffset=offset; currentferecord=(offset-tagdbheader.filestart)/FILEENTRY_SIZE; } -void getfentrybyrecord(int record) { - getfentrybyoffset(FILERECORD2OFFSET(record)); -} +#define getfentrybyrecord(_x_) getfentrybyoffset(FILERECORD2OFFSET(_x_)) int getfentrybyfilename(char *fname) { int min=0; @@ -146,10 +148,56 @@ int getfentrybyfilename(char *fname) { return 0; } -int shiftdown(int targetoffset, int startingoffset) { +int getfentrybyhash(int hash) { + int min=0; + for(min=0;min=startingoffset) { - splash(HZ*2,"Woah. no beeping way. (shiftdown)"); + splash(HZ*2,"Woah. no beeping way. (tagdb_shiftdown)"); return 0; } lseek(tagdb_fd,startingoffset,SEEK_SET); @@ -160,7 +208,7 @@ int shiftdown(int targetoffset, int startingoffset) { written=write(tagdb_fd,sbuf,amount); targetoffset+=written; if(amount!=written) { - splash(HZ*2,"Something went very wrong. expect database corruption."); + splash(HZ*2,"Something went very wrong. expect database corruption. (tagdb_shiftdown)"); return 0; } lseek(tagdb_fd,startingoffset,SEEK_SET); @@ -169,27 +217,44 @@ int shiftdown(int targetoffset, int startingoffset) { return 1; } -int deletefentry(char *fname) { - if(!getfentrybyfilename(fname)) - return 0; - int restrecord = currentferecord+1; - if(currentferecord==tagdbheader.filecount) /* file is last entry */ - ftruncate(tagdb_fd,lseek(tagdb_fd,0,SEEK_END)-FILEENTRY_SIZE); - else - shiftdown(FILERECORD2OFFSET(currentferecord),FILERECORD2OFFSET(restrecord)); - tagdbheader.filecount--; - writetagdbheader(); - return 1; -} - -int getfentrybyhash(int hash) { - int min=0; - for(min=0;min1024 ? 1024 : readpos-startingoffset; + readpos-=amount; + writepos=readpos+(targetoffset-startingoffset); + lseek(tagdb_fd,readpos,SEEK_SET); + amount2=read(tagdb_fd,sbuf,amount); + if(amount2!=amount) { + splash(HZ*2,"Something went very wrong. expect database corruption. (tagdb_shiftup)"); + } + lseek(tagdb_fd,writepos,SEEK_SET); + amount=write(tagdb_fd,sbuf,amount2); + if(amount2!=amount) { + splash(HZ*2,"Something went very wrong. expect database corruption. (tagdb_shiftup)"); + } + } while (amount>0); + if(amount==0) + return 1; + else { + splash(HZ*2,"Something went wrong, >.>;; (tagdb_shiftup)"); + return 0; } - return 0; } +/*** end TagDatabase code ***/ + +/*** RuntimeDatabase code ***/ + + + +/*** end RuntimeDatabase code ***/ + #endif diff --git a/apps/database.h b/apps/database.h index cdbd4d4..3828257 100644 --- a/apps/database.h +++ b/apps/database.h @@ -65,7 +65,7 @@ struct tagdb_header { struct file_entry { char *name; int hash; - int tagentry; + int songentry; int rundbentry; }; -- cgit v1.1