n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminata con errore\n",fd_c,flags,filepath);
errno=EINVAL;
serror(MESY,fd_c,taglia,tmp_buf);
return;
}
intfound=searchFile(q,filepath);// cerco il file nella queue
intcreate=flags&0x1;// also %2
intlock=flags>>1&0x1;// also >>1%2
fileT*removed=NULL;// file che è stato rimosso
if(found&&create){// si vuole creare il file ma esiste già
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminata con errore\n",fd_c,flags,filepath);
errno=EEXIST;
serror(MENT,fd_c,taglia,tmp_buf);
return;
}
if(!found&&!create){// si vuole aprire e non creare un file inesistente
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore\n",fd_c,flags,filepath);
errno=ENOENT;
serror(MENT,fd_c,taglia,tmp_buf);
return;
}
if(found&&!create){
if(openFileInQueue(q,file,lock,fd_c)==-1){
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore\n",fd_c,flags,filepath);
perror("openFileInQueue");
serror(MESE,fd_c,taglia,tmp_buf);
return;
}
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminata con successo\n",fd_c,flags,filepath);
sendMessage(MEOK,fd_c,taglia,tmp_buf);
return;
}
if(!found&&create){// not found and creating new file
if(getLen(q)==queue->maxLen){// capacity miss
removed=dequeue(q);
if(!removed){
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore\n",fd_c,flags,filepath);
perror("dequeue");
serror(MESE,fd_c,taglia,tmp_buf);
return;
}
fileT*f=createFileT(filepath,lock,fd_c,1);// create new file
if(!f){
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore del server\n",fd_c,flags,filepath);
perror("createFileT");
serror(MESE,fd_c,taglia);
return;
}
if(enqueue(q,f)!=0){
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore del server\n",fd_c,flags,filepath);
perror("enqueue");
serror(MESE,fd_c,taglia);
return;
}
taglia_update(taglia,q,1);// removed only one file
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" ha causato una capacity miss. File espulso \"%s\"\n",fd_c,flags,filepath,removed->filepath);
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore del server\n",fd_c,flags,filepath);
perror("createFileT");
serror(MESE,fd_c,taglia);
return;
}
if(enqueue(q,f)!=0){
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore del server\n",fd_c,flags,filepath);
perror("enqueue");
serror(MESE,fd_c,taglia);
return;
}
// abbiamo aggiunto un file quindi il numero di file è cambiato
// quindi bisogna fare un update del log
taglia_update(taglia,q,0);
n+=snprintf(tmp_buf+n,m-n,"Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con successo\n",fd_c,flags,filepath);