Cleanup: Move all source files to src/
[lttng-modules.git] / src / wrapper / fdtable.c
diff --git a/src/wrapper/fdtable.c b/src/wrapper/fdtable.c
new file mode 100644 (file)
index 0000000..26a8367
--- /dev/null
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ * wrapper/fdtable.c
+ *
+ * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#include <linux/version.h>
+#include <linux/spinlock.h>
+#include <wrapper/fdtable.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
+
+/*
+ * Reimplementation of iterate_fd() for kernels between 2.6.32 and 3.6
+ * (inclusive).
+ */
+int lttng_iterate_fd(struct files_struct *files,
+               unsigned int first,
+               int (*cb)(const void *, struct file *, unsigned int),
+               const void *ctx)
+{
+       struct fdtable *fdt;
+       struct file *filp;
+       unsigned int i;
+       int res = 0;
+
+       if (!files)
+               return 0;
+       spin_lock(&files->file_lock);
+       fdt = files_fdtable(files);
+       for (i = 0; i < fdt->max_fds; i++) {
+               filp = fcheck_files(files, i);
+               if (!filp)
+                       continue;
+               res = cb(ctx, filp, i);
+               if (res)
+                       break;
+       }
+       spin_unlock(&files->file_lock);
+       return res;
+}
+
+#endif
This page took 0.024699 seconds and 4 git commands to generate.