Commit 5b79a48a authored by Samarth Joshi's avatar Samarth Joshi
parents d39129da 811d30c1
...@@ -37,6 +37,9 @@ void file_del( char *key) ...@@ -37,6 +37,9 @@ void file_del( char *key)
int length=0; int length=0;
sem_wait(&mutex[index]); sem_wait(&mutex[index]);
char blankspace[512]; char blankspace[512];
char ch;
int k=-1;
lseek(fds[index], 0, SEEK_SET);
memset(blankspace,0,512); memset(blankspace,0,512);
char *line; char *line;
char temp[514]; char temp[514];
...@@ -52,12 +55,13 @@ void file_del( char *key) ...@@ -52,12 +55,13 @@ void file_del( char *key)
if(strcmp(key,fkey)==0){ if(strcmp(key,fkey)==0){
lseek(fds[index],position,SEEK_SET); lseek(fds[index],position,SEEK_SET);
write(fds[index],blankspace,strlen(temp)); write(fds[index],blankspace,strlen(temp));
puts(temp);
break; break;
} }
position=ftell(fp); position=ftell(fp);
} }
printf("length %d",length);
sem_post(&mutex[index]); sem_post(&mutex[index]);
} }
...@@ -66,7 +70,9 @@ int file_get(char *key, char *value) ...@@ -66,7 +70,9 @@ int file_get(char *key, char *value)
/* Gets the value stored at offset */ /* Gets the value stored at offset */
/* Does not depend on key argument */ /* Does not depend on key argument */
int found =0; int found =0;
int index=modulus(key,256,setSize); int index=modulus(key,256,setSize);
lseek(fds[index],0,SEEK_SET);
sem_wait(&readerLocks[index]); sem_wait(&readerLocks[index]);
readCounters[index]+=1; readCounters[index]+=1;
if(readCounters[index]==1) if(readCounters[index]==1)
...@@ -103,6 +109,7 @@ off_t file_put(char *key,char *value) ...@@ -103,6 +109,7 @@ off_t file_put(char *key,char *value)
if not present then search for empty line and insert there! if not present then search for empty line and insert there!
*/ */
unsigned int index=modulus(key,256,setSize); unsigned int index=modulus(key,256,setSize);
lseek(fds[index],0,SEEK_SET);
off_t position; off_t position;
//sem_wait(&mutex[index]); //sem_wait(&mutex[index]);
printf("[Write to File: %d]\n",index); printf("[Write to File: %d]\n",index);
...@@ -128,7 +135,7 @@ off_t file_put(char *key,char *value) ...@@ -128,7 +135,7 @@ off_t file_put(char *key,char *value)
printf("value:(%s)(%s)\n",fvalue,value); printf("value:(%s)(%s)\n",fvalue,value);
fflush(stdout); fflush(stdout);
fseek(fp,position,SEEK_SET); fseek(fp,position,SEEK_SET);
snprintf(lin, sizeof(lin),"%s:%s\n",key,value); snprintf(lin, strlen(key)+strlen(value)+2,"%s:%s\n",key,value);
if(fputs(lin,fp)<0) if(fputs(lin,fp)<0)
printf("\n[unable to perform file_put]\n"); printf("\n[unable to perform file_put]\n");
return 0; return 0;
...@@ -183,6 +190,10 @@ int main() ...@@ -183,6 +190,10 @@ int main()
//offset = file_put("40", "value28"); //offset = file_put("40", "value28");
//file_get(prevkey, value); // Doesnot depend on key arg, returns key and value at offset 0 //file_get(prevkey, value); // Doesnot depend on key arg, returns key and value at offset 0
//printf("(%s)", value); //printf("(%s)", value);
file_del("29"); //file_del("29");
//file_get("24",value);
// printf("(%s)\n", value);
file_del("21");
//printf("(%s)\n", value);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment