// This function is called when a /dev/osprdX file is finally closed. // (If the file descriptor was dup2ed, this function is called only when the // last copy is closed.) static int osprd_close_last(struct inode *inode, struct file *filp) { int ret = 0; if (filp) { osprd_info_t *d = file2osprd(filp); int filp_writable = filp->f_mode & FMODE_WRITE; // EXERCISE: If the user closes a ramdisk file that holds // a lock, release the lock. Also wake up blocked processes // as appropriate. // Your code here. if( d->read_lock_count || d->write_lock_count){ /* User closed ramdisk file that holds a lock, release it */ ret = osprd_ioctl(inode, filp, OSPRDIOCRELEASE, 0); } else { /* Also wake up blocked processes as appropriate */ if(waitqueue_active(&d->blockq)) wake_up_all(&d->blockq); d->num_ramdisks_open = 0; } // This line avoids compiler warnings; you may remove it. (void) filp_writable, (void) d; } return 0; }
// This function is called when a /dev/osprdX file is finally closed. // (If the file descriptor was dup2ed, this function is called only when the // last copy is closed.) static int osprd_close_last(struct inode *inode, struct file *filp) { if (filp) { osprd_info_t *d = file2osprd(filp); //int filp_writable = filp->f_mode & FMODE_WRITE; // EXERCISE: If the user closes a ramdisk file that holds // a lock, release the lock. Also wake up blocked processes // as appropriate. // Your code here. osprd_ioctl(inode, filp, OSPRDIOCRELEASE, 0); } return 0; }