Fix: introduce LTTNG_SIZE_MAX for older kernels
[deliverable/lttng-modules.git] / wrapper / fdtable.c
1 /*
2 * wrapper/fdtable.c
3 *
4 * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; only
9 * version 2.1 of the License.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <linux/version.h>
22 #include <linux/spinlock.h>
23 #include <wrapper/fdtable.h>
24
25 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
26
27 /*
28 * Reimplementation of iterate_fd() for kernels between 2.6.32 and 3.6
29 * (inclusive).
30 */
31 int lttng_iterate_fd(struct files_struct *files,
32 unsigned int first,
33 int (*cb)(const void *, struct file *, unsigned int),
34 const void *ctx)
35 {
36 struct fdtable *fdt;
37 struct file *filp;
38 unsigned int i;
39 int res = 0;
40
41 if (!files)
42 return 0;
43 spin_lock(&files->file_lock);
44 fdt = files_fdtable(files);
45 for (i = 0; i < fdt->max_fds; i++) {
46 filp = fcheck_files(files, i);
47 if (!filp)
48 continue;
49 res = cb(ctx, filp, i);
50 if (res)
51 break;
52 }
53 spin_unlock(&files->file_lock);
54 return res;
55 }
56
57 #endif
This page took 0.051704 seconds and 5 git commands to generate.