void asyncRead (char* buf, int nbytes, int blockno, void (*handler) (char*, int, int)) { // call disk_scheduleRead to schedule a read TODO struct PendingRead* PR = malloc(sizeof *PR); PR->buf = buf; PR->nbytes = nbytes; PR->blockno = blockno; PR->handler = handler; queue_enqueue (&prq, PR); disk_scheduleRead (buf, nbytes, blockno); disk_waitForReads (); }
void* readAndHandleBlock (void* args_voidstar) { // TODO // Synchronously: // (1) call disk_scheduleRead to request the block // (2) wait read for it to complete // (3) call handleRead struct readAndHandleBlockArgs* obj = args_voidstar; disk_scheduleRead(obj->buf,obj->nbytes,obj->blockno); //call disk_scheduleRead to request the block blockUntilComplete(); handleRead(obj->buf,obj->nbytes,obj->blockno); free(obj->buf); free(obj); //how do we get the information after the reading return NULL; // read first, because it takes time to read so we block it first. And then // when it finishes reading, we unblock it and put it into a queue. We call interrupt service // routine to handle the data }
void syncRead (char* buf, int nBytes, int blockNo) { disk_scheduleRead (buf, 4096, blockNo); disk_waitForReads (); assert (*((int*) buf) == blockNo); }