예제 #1
0
파일: osprd.c 프로젝트: smanikar/ramdisk
// 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;
}
예제 #2
0
파일: osprd.c 프로젝트: m1c0l/ramdisk
// 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;
}