| 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
| 2 | * wrapper/fdtable.c |
| 3 | * |
| 4 | * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/version.h> |
| 8 | #include <linux/spinlock.h> |
| 9 | #include <wrapper/fdtable.h> |
| 10 | |
| 11 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)) |
| 12 | |
| 13 | /* |
| 14 | * Reimplementation of iterate_fd() for kernels between 2.6.32 and 3.6 |
| 15 | * (inclusive). |
| 16 | */ |
| 17 | int lttng_iterate_fd(struct files_struct *files, |
| 18 | unsigned int first, |
| 19 | int (*cb)(const void *, struct file *, unsigned int), |
| 20 | const void *ctx) |
| 21 | { |
| 22 | struct fdtable *fdt; |
| 23 | struct file *filp; |
| 24 | unsigned int i; |
| 25 | int res = 0; |
| 26 | |
| 27 | if (!files) |
| 28 | return 0; |
| 29 | spin_lock(&files->file_lock); |
| 30 | fdt = files_fdtable(files); |
| 31 | for (i = 0; i < fdt->max_fds; i++) { |
| 32 | filp = fcheck_files(files, i); |
| 33 | if (!filp) |
| 34 | continue; |
| 35 | res = cb(ctx, filp, i); |
| 36 | if (res) |
| 37 | break; |
| 38 | } |
| 39 | spin_unlock(&files->file_lock); |
| 40 | return res; |
| 41 | } |
| 42 | |
| 43 | #endif |