Commit ef7f340a authored by Bandana's avatar Bandana

Update persistentStorage.c

parent 116d4cbd
......@@ -40,13 +40,6 @@ struct n2
struct n1 *h1=NULL;
struct n2 *h2=NULL;
unsigned int nooffiles=0;
void initializeStorageVariables()
{
pthread_mutex_init(&m, NULL);
sem_init(&w, 0,1);
}
struct n2 * check(struct n2 *h2){
while (1)
{
......@@ -568,7 +561,7 @@ struct n1* del(struct n1*r,char *key){
}
string GETT(char * key){
struct n1* GETT(char * key){
pthread_mutex_lock(&m);
readercout+=1;
if(readercout==1){
......@@ -601,24 +594,20 @@ string GETT(char * key){
pthread_mutex_unlock(&m);
return result;
return dh;
}
else
{
// printf("%s = %s \n",key ,dh->key);
printf("%s = %s \n",key ,dh->key);
if((tt=strcmp(key,dh->key))==0)
{
char filename2[10];
strcpy(filename2,dh->filename);
int fd1=open(strcat(filename2,".txt"),O_RDWR);
FILE *f=fopen(strcat(filename2,".txt"),"r");
char record[257];
lseek(fd1,dh->lineno*257,SEEK_SET);
// fgets(record,256,f);
read(fd1,record, 256);
// fclose(f);
write(STDOUT_FILENO, record, 256);
write(STDOUT_FILENO, "\n", 1);
close(fd1);
fseek(f,dh->lineno*257,SEEK_SET);
fgets(record,256,f);
fclose(f);
int sp=0;
while (record[sp]!='#')
{
......@@ -637,7 +626,7 @@ string GETT(char * key){
pthread_mutex_unlock(&m);
return result;
return dh;
}
else if(tt>0)
......@@ -653,7 +642,7 @@ string GETT(char * key){
void PUTT(char *key,char *value){
sem_wait(&w);
// printf("key = %s\nvalue=%s",key, value);
printf("key = %s\nvalue=%s",key, value);
h1=insert(h1,key);
char filename2[10];
strcpy(filename2,add->filename);
......@@ -707,7 +696,7 @@ void PUTT(char *key,char *value){
write(n,ts,257);
close(n);
}
// printf("PUTT completed\n");
printf("PUTT completed\n");
sem_post(&w);
}
......@@ -794,7 +783,7 @@ void pp(struct n1*r){
}
pp(r->p1);
// printf("%s\n",r->key);
printf("%s\n",r->key);
pp(r->p2);
}
......@@ -802,7 +791,7 @@ void pp2(struct n1*r){
if(r==NULL){
return;
}
// printf("%s\n",r->key);
printf("%s\n",r->key);
pp2(r->p1);
......@@ -813,7 +802,8 @@ void pp2(struct n1*r){
// int main()
// {
// printf("Saikumar\n");
// PUTT("1",);
// return 0;
// }
......
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