]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - fs/file.c
new helper: iterate_fd()
[karo-tx-linux.git] / fs / file.c
index 967bd0dadbe57281df679265274b732b79fb60b8..e6e418122587f04ed62080b7164f98a59719a1ba 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -979,3 +979,24 @@ int f_dupfd(unsigned int from, struct file *file, unsigned flags)
        }
        return err;
 }
+
+int iterate_fd(struct files_struct *files, unsigned n,
+               int (*f)(const void *, struct file *, unsigned),
+               const void *p)
+{
+       struct fdtable *fdt;
+       struct file *file;
+       int res = 0;
+       if (!files)
+               return 0;
+       spin_lock(&files->file_lock);
+       fdt = files_fdtable(files);
+       while (!res && n < fdt->max_fds) {
+               file = rcu_dereference_check_fdtable(files, fdt->fd[n++]);
+               if (file)
+                       res = f(p, file, n);
+       }
+       spin_unlock(&files->file_lock);
+       return res;
+}
+EXPORT_SYMBOL(iterate_fd);