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

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

diff -u --recursive --new-file v2.3.8/linux/include/linux/file.h linux/include/linux/file.h
@@ -26,18 +26,27 @@
 extern inline struct file * fcheck(unsigned int fd)
 {
 	struct file * file = NULL;
+	struct files_struct *files = current->files;
 
-	if (fd < current->files->max_fds)
-		file = current->files->fd[fd];
+	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 * fget(unsigned int fd)
 {
-	struct file * file = fcheck(fd);
+	struct file * file = NULL;
+	struct files_struct *files = current->files;
 
-	if (file)
-		file->f_count++;
+	read_lock(&files->file_lock);
+	if (fd < files->max_fds) {
+		file = files->fd[fd];
+		if (file)
+			atomic_inc(&file->f_count);
+	}
+	read_unlock(&files->file_lock);
 	return file;
 }
 
@@ -46,7 +55,11 @@
  */
 extern inline void fd_install(unsigned int fd, struct file * file)
 {
-	current->files->fd[fd] = file;
+	struct files_struct *files = current->files;
+
+	write_lock(&files->file_lock);
+	files->fd[fd] = file;
+	write_unlock(&files->file_lock);
 }
 
 /*

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