patch-2.4.0-test5 linux/fs/file_table.c
Next file: linux/fs/hpfs/buffer.c
Previous file: linux/fs/fcntl.c
Back to the patch index
Back to the overall index
- Lines: 75
- Date:
Thu Jul 27 16:47:16 2000
- Orig file:
v2.4.0-test4/linux/fs/file_table.c
- Orig date:
Fri Jul 14 12:12:14 2000
diff -u --recursive --new-file v2.4.0-test4/linux/fs/file_table.c linux/fs/file_table.c
@@ -12,9 +12,6 @@
#include <linux/module.h>
#include <linux/smp_lock.h>
-/* SLAB cache for filp's. */
-static kmem_cache_t *filp_cache;
-
/* sysctl tunables... */
struct files_stat_struct files_stat = {0, 0, NR_FILE};
@@ -25,20 +22,6 @@
/* public *and* exported. Not pretty! */
spinlock_t files_lock = SPIN_LOCK_UNLOCKED;
-void __init file_table_init(void)
-{
- filp_cache = kmem_cache_create("filp", sizeof(struct file),
- 0,
- SLAB_HWCACHE_ALIGN, NULL, NULL);
- if(!filp_cache)
- panic("VFS: Cannot alloc filp SLAB cache.");
- /*
- * We could allocate the reserved files here, but really
- * shouldn't need to: the normal boot process will create
- * plenty of free files.
- */
-}
-
/* Find an unused file structure and return a pointer to it.
* Returns NULL, if there are no more free file structures or
* we run out of memory.
@@ -78,7 +61,7 @@
*/
if (files_stat.nr_files < files_stat.max_files) {
file_list_unlock();
- f = kmem_cache_alloc(filp_cache, SLAB_KERNEL);
+ f = kmem_cache_alloc(filp_cachep, SLAB_KERNEL);
file_list_lock();
if (f) {
files_stat.nr_files++;
@@ -136,7 +119,7 @@
mntput(mnt);
}
-void _fput(struct file *file)
+static void _fput(struct file *file)
{
locks_remove_flock(file);
__fput(file);
@@ -146,6 +129,25 @@
list_add(&file->f_list, &free_list);
files_stat.nr_free_files++;
file_list_unlock();
+}
+
+void fput(struct file * file)
+{
+ if (atomic_dec_and_test(&file->f_count))
+ _fput(file);
+}
+
+struct file * fget(unsigned int fd)
+{
+ struct file * file = NULL;
+ struct files_struct *files = current->files;
+
+ read_lock(&files->file_lock);
+ file = fcheck(fd);
+ if (file)
+ get_file(file);
+ read_unlock(&files->file_lock);
+ return file;
}
/* Here. put_filp() is SMP-safe now. */
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)