patch-2.3.10 linux/include/linux/file.h

Next file: linux/include/linux/fs.h
Previous file: linux/include/linux/cyclades.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.9/linux/include/linux/file.h linux/include/linux/file.h
@@ -5,7 +5,8 @@
 #ifndef __LINUX_FILE_H
 #define __LINUX_FILE_H
 
-extern void __fput(struct file *);
+extern void __fput(struct file *);	/* goner? */
+extern void _fput(struct file *);
 
 /*
  * Check whether the specified task has the fd open. Since the task
@@ -15,7 +16,7 @@
 {
 	struct file * file = NULL;
 
-	if (p->files && fd < p->files->max_fds)
+	if (fd < p->files->max_fds)
 		file = p->files->fd[fd];
 	return file;
 }
@@ -28,10 +29,17 @@
 	struct file * file = NULL;
 	struct files_struct *files = current->files;
 
-	read_lock(&files->file_lock);
 	if (fd < files->max_fds)
 		file = files->fd[fd];
-	read_unlock(&files->file_lock);
+	return file;
+}
+
+extern inline struct file * frip(unsigned int fd)
+{
+	struct file * file = NULL;
+
+	if (fd < current->files->max_fds)
+		file = xchg(&current->files->fd[fd], NULL);
 	return file;
 }
 
@@ -41,11 +49,9 @@
 	struct files_struct *files = current->files;
 
 	read_lock(&files->file_lock);
-	if (fd < files->max_fds) {
-		file = files->fd[fd];
-		if (file)
-			atomic_inc(&file->f_count);
-	}
+	file = fcheck(fd);
+	if (file)
+		get_file(file);
 	read_unlock(&files->file_lock);
 	return file;
 }
@@ -78,7 +84,11 @@
  * I suspect there are many other similar "optimizations" across the
  * kernel...
  */
-extern void fput(struct file *); 
+extern inline void fput(struct file * file)
+{
+	if (atomic_dec_and_test(&file->f_count))
+		_fput(file);
+}
 extern void put_filp(struct file *);
 
 #endif /* __LINUX_FILE_H */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)